Page MenuHomePhabricator

D5191.id16896.diff
No OneTemporary

D5191.id16896.diff

diff --git a/keyserver/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js
--- a/keyserver/src/responders/message-responders.js
+++ b/keyserver/src/responders/message-responders.js
@@ -118,15 +118,14 @@
request,
);
- if (request.mediaIDs) {
- return legacyMultimediaMessageCreationResponder(viewer, request);
- }
-
- const { threadID, localID, mediaMessageContents } = request;
- if (mediaMessageContents.length === 0) {
+ if (
+ (request.mediaIDs && request.mediaIDs.length === 0) ||
+ (request.mediaMessageContents && request.mediaMessageContents.length === 0)
+ ) {
throw new ServerError('invalid_parameters');
}
+ const { threadID, localID } = request;
const hasPermission = await checkThreadPermission(
viewer,
threadID,
@@ -136,59 +135,19 @@
throw new ServerError('invalid_parameters');
}
- const [media, existingMessageInfo] = await Promise.all([
- fetchMediaFromMediaMessageContent(viewer, mediaMessageContents),
- fetchMessageInfoForLocalID(viewer, localID),
- ]);
-
- if (media.length !== mediaMessageContents.length && !existingMessageInfo) {
- throw new ServerError('invalid_parameters');
- }
-
- const messageData = createMediaMessageData({
- localID,
- threadID,
- creatorID: viewer.id,
- media,
- });
- const [newMessageInfo] = await createMessages(viewer, [messageData]);
- const { id } = newMessageInfo;
- invariant(
- id !== null && id !== undefined,
- 'serverID should be set in createMessages result',
- );
-
- await assignMessageContainerToMedia(viewer, mediaMessageContents, id);
- return { newMessageInfo };
-}
-
-async function legacyMultimediaMessageCreationResponder(
- viewer: Viewer,
- request: SendMultimediaMessageRequest,
-): Promise<SendMessageResponse> {
- const { threadID, localID } = request;
- const mediaIDs = request.mediaIDs
- ? request.mediaIDs
- : request.mediaMessageContents.map(contents => contents.uploadID);
-
- if (mediaIDs.length === 0) {
- throw new ServerError('invalid_parameters');
+ const promises = [];
+ promises.push(fetchMessageInfoForLocalID(viewer, localID));
+ if (request.mediaIDs) {
+ promises.push(fetchMedia(viewer, request.mediaIDs));
+ } else {
+ promises.push(
+ fetchMediaFromMediaMessageContent(viewer, request.mediaMessageContents),
+ );
}
- const hasPermission = await checkThreadPermission(
- viewer,
- threadID,
- threadPermissions.VOICED,
- );
- if (!hasPermission) {
- throw new ServerError('invalid_parameters');
- }
+ const [existingMessageInfo, media] = await Promise.all(promises);
- const [media, existingMessageInfo] = await Promise.all([
- fetchMedia(viewer, mediaIDs),
- fetchMessageInfoForLocalID(viewer, localID),
- ]);
- if (media.length !== mediaIDs.length && !existingMessageInfo) {
+ if (media.length === 0 && !existingMessageInfo) {
throw new ServerError('invalid_parameters');
}
@@ -199,13 +158,21 @@
media,
});
const [newMessageInfo] = await createMessages(viewer, [messageData]);
-
const { id } = newMessageInfo;
invariant(
id !== null && id !== undefined,
'serverID should be set in createMessages result',
);
- await assignMedia(viewer, mediaIDs, id);
+
+ if (request.mediaIDs) {
+ await assignMedia(viewer, request.mediaIDs, id);
+ } else {
+ await assignMessageContainerToMedia(
+ viewer,
+ request.mediaMessageContents,
+ id,
+ );
+ }
return { newMessageInfo };
}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 28, 6:13 AM (7 h, 39 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2724183
Default Alt Text
D5191.id16896.diff (3 KB)

Event Timeline