Page MenuHomePhabricator

D13319.diff
No OneTemporary

D13319.diff

diff --git a/lib/shared/dm-ops/dm-op-specs.js b/lib/shared/dm-ops/dm-op-specs.js
--- a/lib/shared/dm-ops/dm-op-specs.js
+++ b/lib/shared/dm-ops/dm-op-specs.js
@@ -12,6 +12,7 @@
import { leaveThreadSpec } from './leave-thread-spec.js';
import { removeMembersSpec } from './remove-members-spec.js';
import { sendEditMessageSpec } from './send-edit-message-spec.js';
+import { sendMultimediaMessageSpec } from './send-multimedia-message-spec.js';
import { sendReactionMessageSpec } from './send-reaction-message-spec.js';
import { sendTextMessageSpec } from './send-text-message-spec.js';
import { type DMOperationType, dmOperationTypes } from '../../types/dm-ops.js';
@@ -22,6 +23,7 @@
[dmOperationTypes.CREATE_THREAD]: createThreadSpec,
[dmOperationTypes.CREATE_SIDEBAR]: createSidebarSpec,
[dmOperationTypes.SEND_TEXT_MESSAGE]: sendTextMessageSpec,
+ [dmOperationTypes.SEND_MULTIMEDIA_MESSAGE]: sendMultimediaMessageSpec,
[dmOperationTypes.SEND_REACTION_MESSAGE]: sendReactionMessageSpec,
[dmOperationTypes.SEND_EDIT_MESSAGE]: sendEditMessageSpec,
[dmOperationTypes.ADD_MEMBERS]: addMembersSpec,
diff --git a/lib/shared/dm-ops/send-multimedia-message-spec.js b/lib/shared/dm-ops/send-multimedia-message-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/send-multimedia-message-spec.js
@@ -0,0 +1,67 @@
+// @flow
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMSendMultimediaMessageOperation } from '../../types/dm-ops.js';
+import { messageTypes } from '../../types/message-types-enum.js';
+import type { MediaMessageData } from '../../types/messages/media.js';
+import type { ClientUpdateInfo } from '../../types/update-types.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+function createMessageDataFromDMOperation(
+ dmOperation: DMSendMultimediaMessageOperation,
+): MediaMessageData {
+ const { threadID, creatorID, time, media } = dmOperation;
+ return {
+ type: messageTypes.MULTIMEDIA,
+ threadID,
+ creatorID,
+ time,
+ media,
+ };
+}
+
+const sendMultimediaMessageSpec: DMOperationSpec<DMSendMultimediaMessageOperation> =
+ Object.freeze({
+ notificationsCreationData: async (
+ dmOperation: DMSendMultimediaMessageOperation,
+ ) => {
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (
+ dmOperation: DMSendMultimediaMessageOperation,
+ ) => {
+ const { messageID } = dmOperation;
+ const messageData = createMessageDataFromDMOperation(dmOperation);
+ const rawMessageInfos = [
+ rawMessageInfoFromMessageData(messageData, messageID),
+ ];
+ const updateInfos: Array<ClientUpdateInfo> = [];
+ return {
+ rawMessageInfos,
+ updateInfos,
+ };
+ },
+ canBeProcessed(
+ dmOperation: DMSendMultimediaMessageOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) {
+ if (utilities.threadInfos[dmOperation.threadID]) {
+ return { isProcessingPossible: true };
+ }
+ return {
+ isProcessingPossible: false,
+ reason: {
+ type: 'missing_thread',
+ threadID: dmOperation.threadID,
+ },
+ };
+ },
+ supportsAutoRetry: false,
+ });
+
+export { sendMultimediaMessageSpec };
diff --git a/lib/types/dm-ops.js b/lib/types/dm-ops.js
--- a/lib/types/dm-ops.js
+++ b/lib/types/dm-ops.js
@@ -3,6 +3,7 @@
import t, { type TInterface, type TUnion } from 'tcomb';
import { clientAvatarValidator, type ClientAvatar } from './avatar-types.js';
+import { type Media, mediaValidator } from './media-types.js';
import type { RawMessageInfo } from './message-types.js';
import type { NotificationsCreationData } from './notif-types.js';
import type { OutboundP2PMessage } from './sqlite-types.js';
@@ -28,6 +29,7 @@
CREATE_THREAD: 'create_thread',
CREATE_SIDEBAR: 'create_sidebar',
SEND_TEXT_MESSAGE: 'send_text_message',
+ SEND_MULTIMEDIA_MESSAGE: 'send_multimedia_message',
SEND_REACTION_MESSAGE: 'send_reaction_message',
SEND_EDIT_MESSAGE: 'send_edit_message',
ADD_MEMBERS: 'add_members',
@@ -155,6 +157,24 @@
text: t.String,
});
+export type DMSendMultimediaMessageOperation = {
+ +type: 'send_multimedia_message',
+ +threadID: string,
+ +creatorID: string,
+ +time: number,
+ +messageID: string,
+ +media: $ReadOnlyArray<Media>,
+};
+export const dmSendMultimediaMessageOperationValidator: TInterface<DMSendMultimediaMessageOperation> =
+ tShape<DMSendMultimediaMessageOperation>({
+ type: tString(dmOperationTypes.SEND_MULTIMEDIA_MESSAGE),
+ threadID: t.String,
+ creatorID: tUserID,
+ time: t.Number,
+ messageID: t.String,
+ media: t.list(mediaValidator),
+ });
+
export type DMSendReactionMessageOperation = {
+type: 'send_reaction_message',
+threadID: string,
@@ -352,6 +372,7 @@
| DMCreateThreadOperation
| DMCreateSidebarOperation
| DMSendTextMessageOperation
+ | DMSendMultimediaMessageOperation
| DMSendReactionMessageOperation
| DMSendEditMessageOperation
| DMAddMembersOperation
@@ -366,6 +387,7 @@
dmCreateThreadOperationValidator,
dmCreateSidebarOperationValidator,
dmSendTextMessageOperationValidator,
+ dmSendMultimediaMessageOperationValidator,
dmSendReactionMessageOperationValidator,
dmSendEditMessageOperationValidator,
dmAddMembersOperationValidator,

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 10, 4:57 AM (14 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2845257
Default Alt Text
D13319.diff (5 KB)

Event Timeline