Skip to content

Commit c35b883

Browse files
committed
api: Add getSingleMessage binding for GET messages/{message_id}
We'll use this for #5306; see the plan in discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M5306.20Follow.20.2Fnear.2F.20links.20through.20topic.20moves.2Frenames/near/1407930 In particular, we want the stream and topic for a stream message that might not be in our data structures. We'll use this endpoint to fetch that information.
1 parent 04d2c95 commit c35b883

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import deleteMessage from './messages/deleteMessage';
3030
import deleteTopic from './messages/deleteTopic';
3131
import getRawMessageContent from './messages/getRawMessageContent';
3232
import getMessages from './messages/getMessages';
33+
import getSingleMessage from './messages/getSingleMessage';
3334
import getMessageHistory from './messages/getMessageHistory';
3435
import messagesFlags from './messages/messagesFlags';
3536
import sendMessage from './messages/sendMessage';
@@ -78,6 +79,7 @@ export {
7879
deleteTopic,
7980
getRawMessageContent,
8081
getMessages,
82+
getSingleMessage,
8183
getMessageHistory,
8284
messagesFlags,
8385
sendMessage,

src/api/messages/getSingleMessage.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* @flow strict-local */
2+
3+
import type { Auth, ApiResponseSuccess } from '../transportTypes';
4+
import type { Message } from '../apiTypes';
5+
import { transformFetchedMessage, type FetchedMessage } from '../rawModelTypes';
6+
import { apiGet } from '../apiFetch';
7+
import { identityOfAuth } from '../../account/accountMisc';
8+
9+
// The actual response from the server. We convert the message to a proper
10+
// Message before returning it to application code.
11+
type ServerApiResponseSingleMessage = {|
12+
...$Exact<ApiResponseSuccess>,
13+
-raw_content: string, // deprecated
14+
15+
// Until we narrow FetchedMessage into its FL 120+ form, FetchedMessage
16+
// will be a bit less precise than we could be here. That's because we
17+
// only get this field from servers FL 120+.
18+
// TODO(server-5.0): Make this field required, and remove FL-120 comment.
19+
+message?: FetchedMessage,
20+
|};
21+
22+
/**
23+
* See https://zulip.com/api/get-message
24+
*
25+
* Gives undefined if the `message` field is missing, which it will be for
26+
* FL <120.
27+
*/
28+
// TODO(server-5.0): Simplify FL-120 condition in jsdoc and implementation.
29+
export default async (
30+
auth: Auth,
31+
args: {|
32+
+message_id: number,
33+
|},
34+
35+
// TODO(#4659): Don't get this from callers.
36+
zulipFeatureLevel: number,
37+
38+
// TODO(#4659): Don't get this from callers?
39+
allowEditHistory: boolean,
40+
): Promise<Message | void> => {
41+
const { message_id } = args;
42+
const response: ServerApiResponseSingleMessage = await apiGet(auth, `messages/${message_id}`, {
43+
apply_markdown: true,
44+
});
45+
46+
return (
47+
response.message
48+
&& transformFetchedMessage<Message>(
49+
response.message,
50+
identityOfAuth(auth),
51+
zulipFeatureLevel,
52+
allowEditHistory,
53+
)
54+
);
55+
};

0 commit comments

Comments
 (0)