Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3345423
D5127.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D5127.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
@@ -24,9 +24,15 @@
fetchMessageInfoForLocalID,
} from '../fetchers/message-fetchers';
import { checkThreadPermission } from '../fetchers/thread-permission-fetchers';
-import { fetchMedia } from '../fetchers/upload-fetchers';
+import {
+ fetchMedia,
+ fetchMediaFromMediaMessageContent,
+} from '../fetchers/upload-fetchers';
import type { Viewer } from '../session/viewer';
-import { assignMedia } from '../updaters/upload-updaters';
+import {
+ assignMedia,
+ assignMessageContainerToMedia,
+} from '../updaters/upload-updaters';
import { validateInput } from '../utils/validation-utils';
const sendTextMessageRequestInputValidator = tShape({
@@ -111,7 +117,49 @@
sendMultimediaMessageRequestInputValidator,
request,
);
- return legacyMultimediaMessageCreationResponder(viewer, request);
+
+ if (request.mediaIDs) {
+ return legacyMultimediaMessageCreationResponder(viewer, request);
+ }
+
+ const { threadID, localID, mediaMessageContents } = request;
+ if (mediaMessageContents.length === 0) {
+ throw new ServerError('invalid_parameters');
+ }
+
+ const hasPermission = await checkThreadPermission(
+ viewer,
+ threadID,
+ threadPermissions.VOICED,
+ );
+ if (!hasPermission) {
+ 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(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 6:00 AM (18 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569330
Default Alt Text
D5127.diff (2 KB)
Attached To
Mode
D5127: [keyserver] Introduce updated `multimediaMessageCreationResponder(...)` to handle updated payload
Attached
Detach File
Event Timeline
Log In to Comment