Page MenuHomePhabricator

D7632.id25830.diff
No OneTemporary

D7632.id25830.diff

diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js
--- a/keyserver/src/fetchers/message-fetchers.js
+++ b/keyserver/src/fetchers/message-fetchers.js
@@ -24,6 +24,7 @@
defaultMaxMessageAge,
type FetchPinnedMessagesRequest,
type FetchPinnedMessagesResult,
+ isMessageSidebarSourceReactionOrEdit,
} from 'lib/types/message-types.js';
import { threadPermissions } from 'lib/types/thread-types.js';
import { ServerError } from 'lib/utils/errors.js';
@@ -742,13 +743,12 @@
for (const message of messages) {
let { rawMessageInfo } = message;
+ invariant(
+ !isMessageSidebarSourceReactionOrEdit(rawMessageInfo),
+ 'SIDEBAR_SOURCE or TOGGLE_PIN should not point to a ' +
+ 'SIDEBAR_SOURCE, REACTION or EDIT_MESSAGE',
+ );
if (rawMessageInfo.id) {
- invariant(
- rawMessageInfo.type !== messageTypes.SIDEBAR_SOURCE &&
- rawMessageInfo.type !== messageTypes.REACTION &&
- rawMessageInfo.type !== messageTypes.EDIT_MESSAGE,
- 'SIDEBAR_SOURCE should not point to a SIDEBAR_SOURCE, REACTION or EDIT_MESSAGE',
- );
const editedContent = edits.get(rawMessageInfo.id);
if (editedContent && rawMessageInfo.type === messageTypes.TEXT) {
rawMessageInfo = {
diff --git a/lib/shared/messages/sidebar-source-message-spec.js b/lib/shared/messages/sidebar-source-message-spec.js
--- a/lib/shared/messages/sidebar-source-message-spec.js
+++ b/lib/shared/messages/sidebar-source-message-spec.js
@@ -10,13 +10,14 @@
} from './message-spec.js';
import { joinResult } from './utils.js';
import type { PlatformDetails } from '../../types/device-types.js';
-import type {
- RawSidebarSourceMessageInfo,
- SidebarSourceMessageData,
- SidebarSourceMessageInfo,
- ClientDBMessageInfo,
+import {
+ type RawSidebarSourceMessageInfo,
+ type SidebarSourceMessageData,
+ type SidebarSourceMessageInfo,
+ type ClientDBMessageInfo,
+ messageTypes,
+ isMessageSidebarSourceReactionOrEdit,
} from '../../types/message-types.js';
-import { messageTypes } from '../../types/message-types.js';
import type { RawUnsupportedMessageInfo } from '../../types/messages/unsupported.js';
import type { NotifTexts } from '../../types/notif-types.js';
import type { RelativeUserInfo } from '../../types/user-types.js';
@@ -106,10 +107,7 @@
rawMessageInfo.sourceMessage,
);
invariant(
- sourceMessage &&
- sourceMessage.type !== messageTypes.SIDEBAR_SOURCE &&
- sourceMessage.type !== messageTypes.REACTION &&
- sourceMessage.type !== messageTypes.EDIT_MESSAGE,
+ sourceMessage && !isMessageSidebarSourceReactionOrEdit(sourceMessage),
'Sidebars can not be created from SIDEBAR SOURCE, REACTION or EDIT MESSAGE',
);
diff --git a/lib/types/message-types.js b/lib/types/message-types.js
--- a/lib/types/message-types.js
+++ b/lib/types/message-types.js
@@ -214,6 +214,16 @@
return messageData.localID;
}
+export function isMessageSidebarSourceReactionOrEdit(
+ message: RawMessageInfo | MessageInfo,
+): boolean %checks {
+ return (
+ message.type === messageTypes.SIDEBAR_SOURCE ||
+ message.type === messageTypes.REACTION ||
+ message.type === messageTypes.EDIT_MESSAGE
+ );
+}
+
const mediaMessageTypes = new Set([
messageTypes.IMAGES,
messageTypes.MULTIMEDIA,

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 6:29 PM (7 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700766
Default Alt Text
D7632.id25830.diff (3 KB)

Event Timeline