forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Add getSingleMessage binding for GET messages/{message_id}
We'll use this for zulip#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.
- Loading branch information
1 parent
04d2c95
commit c35b883
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* @flow strict-local */ | ||
|
||
import type { Auth, ApiResponseSuccess } from '../transportTypes'; | ||
import type { Message } from '../apiTypes'; | ||
import { transformFetchedMessage, type FetchedMessage } from '../rawModelTypes'; | ||
import { apiGet } from '../apiFetch'; | ||
import { identityOfAuth } from '../../account/accountMisc'; | ||
|
||
// The actual response from the server. We convert the message to a proper | ||
// Message before returning it to application code. | ||
type ServerApiResponseSingleMessage = {| | ||
...$Exact<ApiResponseSuccess>, | ||
-raw_content: string, // deprecated | ||
|
||
// Until we narrow FetchedMessage into its FL 120+ form, FetchedMessage | ||
// will be a bit less precise than we could be here. That's because we | ||
// only get this field from servers FL 120+. | ||
// TODO(server-5.0): Make this field required, and remove FL-120 comment. | ||
+message?: FetchedMessage, | ||
|}; | ||
|
||
/** | ||
* See https://zulip.com/api/get-message | ||
* | ||
* Gives undefined if the `message` field is missing, which it will be for | ||
* FL <120. | ||
*/ | ||
// TODO(server-5.0): Simplify FL-120 condition in jsdoc and implementation. | ||
export default async ( | ||
auth: Auth, | ||
args: {| | ||
+message_id: number, | ||
|}, | ||
|
||
// TODO(#4659): Don't get this from callers. | ||
zulipFeatureLevel: number, | ||
|
||
// TODO(#4659): Don't get this from callers? | ||
allowEditHistory: boolean, | ||
): Promise<Message | void> => { | ||
const { message_id } = args; | ||
const response: ServerApiResponseSingleMessage = await apiGet(auth, `messages/${message_id}`, { | ||
apply_markdown: true, | ||
}); | ||
|
||
return ( | ||
response.message | ||
&& transformFetchedMessage<Message>( | ||
response.message, | ||
identityOfAuth(auth), | ||
zulipFeatureLevel, | ||
allowEditHistory, | ||
) | ||
); | ||
}; |