Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3559452
D5191.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D5191.id.diff
View Options
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
@@ -4,6 +4,7 @@
import t from 'tcomb';
import { createMediaMessageData, trimMessage } from 'lib/shared/message-utils';
+import type { Media } from 'lib/types/media-types.js';
import {
messageTypes,
type SendTextMessageRequest,
@@ -118,15 +119,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 +136,20 @@
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 hasPermission = await checkThreadPermission(
+ const existingMessageInfoPromise = fetchMessageInfoForLocalID(
viewer,
- threadID,
- threadPermissions.VOICED,
+ localID,
);
- if (!hasPermission) {
- throw new ServerError('invalid_parameters');
- }
+ const mediaPromise: Promise<$ReadOnlyArray<Media>> = request.mediaIDs
+ ? fetchMedia(viewer, request.mediaIDs)
+ : fetchMediaFromMediaMessageContent(viewer, request.mediaMessageContents);
- const [media, existingMessageInfo] = await Promise.all([
- fetchMedia(viewer, mediaIDs),
- fetchMessageInfoForLocalID(viewer, localID),
+ const [existingMessageInfo, media] = await Promise.all([
+ existingMessageInfoPromise,
+ mediaPromise,
]);
- if (media.length !== mediaIDs.length && !existingMessageInfo) {
+
+ if (media.length === 0 && !existingMessageInfo) {
throw new ServerError('invalid_parameters');
}
@@ -199,13 +160,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
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 6:12 AM (6 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2724146
Default Alt Text
D5191.id.diff (3 KB)
Attached To
Mode
D5191: [keyserver] Merge updated and legacy `multimediaMessageCreationResponder(...)`
Attached
Detach File
Event Timeline
Log In to Comment