Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32556443
D15065.1767224255.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D15065.1767224255.diff
View Options
diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js
--- a/keyserver/src/creators/thread-creator.js
+++ b/keyserver/src/creators/thread-creator.js
@@ -8,7 +8,7 @@
generatePendingThreadColor,
generateRandomColor,
} from 'lib/shared/color-utils.js';
-import { isInvalidSidebarSource } from 'lib/shared/message-utils.js';
+import { isValidRawSidebarSourceMessageInfo } from 'lib/shared/message-utils.js';
import { getThreadTypeParentRequirement } from 'lib/shared/thread-utils.js';
import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js';
import { messageTypes } from 'lib/types/message-types-enum.js';
@@ -203,7 +203,7 @@
confirmParentPermission: confirmParentPermissionPromise,
});
- if (sourceMessage && isInvalidSidebarSource(sourceMessage)) {
+ if (sourceMessage && !isValidRawSidebarSourceMessageInfo(sourceMessage)) {
throw new ServerError('invalid_parameters');
}
@@ -438,13 +438,6 @@
if (!sourceMessage) {
throw new ServerError('invalid_parameters');
}
- invariant(
- sourceMessage.type !== messageTypes.REACTION &&
- sourceMessage.type !== messageTypes.EDIT_MESSAGE &&
- sourceMessage.type !== messageTypes.SIDEBAR_SOURCE &&
- sourceMessage.type !== messageTypes.TOGGLE_PIN,
- 'Invalid sidebar source type',
- );
let editedSourceMessage = sourceMessage;
if (sourceMessageID && sourceMessage.type === messageTypes.TEXT) {
diff --git a/lib/shared/dm-ops/create-sidebar-spec.js b/lib/shared/dm-ops/create-sidebar-spec.js
--- a/lib/shared/dm-ops/create-sidebar-spec.js
+++ b/lib/shared/dm-ops/create-sidebar-spec.js
@@ -21,7 +21,7 @@
import { updateTypes } from '../../types/update-types-enum.js';
import { generatePendingThreadColor } from '../color-utils.js';
import {
- isInvalidSidebarSource,
+ isValidRawSidebarSourceMessageInfo,
rawMessageInfoFromMessageData,
} from '../message-utils.js';
import { createThreadTimestamps } from '../thread-utils.js';
@@ -52,7 +52,7 @@
'joined thick thread ${parentThreadID} after its creation',
);
}
- if (isInvalidSidebarSource(sourceMessage)) {
+ if (!isValidRawSidebarSourceMessageInfo(sourceMessage)) {
throw new Error(
`sourceMessage ${sourceMessageID} is an invalid sidebar source`,
);
diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js
--- a/lib/shared/message-utils.js
+++ b/lib/shared/message-utils.js
@@ -39,6 +39,8 @@
type RawMultimediaMessageInfo,
type RobotextMessageInfo,
type ThreadMessageInfo,
+ type ValidRawSidebarSourceMessageInfo,
+ type ValidSidebarSourceMessageInfo,
} from '../types/message-types.js';
import type { DeleteMessageInfo } from '../types/messages/delete.js';
import type { EditMessageInfo } from '../types/messages/edit.js';
@@ -518,6 +520,32 @@
);
}
+function isValidRawSidebarSourceMessageInfo(
+ message: RawMessageInfo,
+): implies message is ValidRawSidebarSourceMessageInfo {
+ return (
+ message.type !== messageTypes.REACTION &&
+ message.type !== messageTypes.EDIT_MESSAGE &&
+ message.type !== messageTypes.SIDEBAR_SOURCE &&
+ message.type !== messageTypes.TOGGLE_PIN &&
+ message.type !== messageTypes.DELETE_MESSAGE &&
+ messageSpecs[message.type].canBeSidebarSource
+ );
+}
+
+function isValidSidebarSourceMessageInfo(
+ message: MessageInfo,
+): implies message is ValidSidebarSourceMessageInfo {
+ return (
+ message.type !== messageTypes.REACTION &&
+ message.type !== messageTypes.EDIT_MESSAGE &&
+ message.type !== messageTypes.SIDEBAR_SOURCE &&
+ message.type !== messageTypes.TOGGLE_PIN &&
+ message.type !== messageTypes.DELETE_MESSAGE &&
+ messageSpecs[message.type].canBeSidebarSource
+ );
+}
+
// Prefer checking isInvalidPinSourceForThread below. This function doesn't
// check whether the user is attempting to pin a SIDEBAR_SOURCE in the context
// of its parent thread, so it's not suitable for permission checks. We only
@@ -665,6 +693,8 @@
modifyItemForResultScreen,
constructChangeRoleEntityText,
isInvalidSidebarSource,
+ isValidRawSidebarSourceMessageInfo,
+ isValidSidebarSourceMessageInfo,
isInvalidPinSource,
isInvalidPinSourceForThread,
isUnableToBeRenderedIndependently,
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
@@ -19,7 +19,10 @@
} from '../../types/message-types.js';
import type { NotifTexts } from '../../types/notif-types.js';
import type { RelativeUserInfo } from '../../types/user-types.js';
-import { isInvalidSidebarSource } from '../message-utils.js';
+import {
+ isValidSidebarSourceMessageInfo,
+ isValidRawSidebarSourceMessageInfo,
+} from '../message-utils.js';
export const sidebarSourceMessageSpec: MessageSpec<
SidebarSourceMessageData,
@@ -77,7 +80,7 @@
const content = JSON.parse(row.content);
let sourceMessage = derivedMessages.get(content.sourceMessageID);
- if (!sourceMessage || isInvalidSidebarSource(sourceMessage)) {
+ if (!sourceMessage || !isValidRawSidebarSourceMessageInfo(sourceMessage)) {
console.warn(
`Message with id ${row.id} has a derived message ` +
`${content.sourceMessageID} which is not present in the database`,
@@ -108,7 +111,7 @@
rawMessageInfo.sourceMessage,
);
invariant(
- sourceMessage && !isInvalidSidebarSource(sourceMessage),
+ sourceMessage && isValidSidebarSourceMessageInfo(sourceMessage),
'Sidebars can not be created from SIDEBAR SOURCE, REACTION, EDIT OR PIN MESSAGE',
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 31, 11:37 PM (16 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5874639
Default Alt Text
D15065.1767224255.diff (5 KB)
Attached To
Mode
D15065: [Flow262][skip-ci] Add isValidRawSidebarSourceMessageInfo()/isValidSidebarSourceMessageInfo()
Attached
Detach File
Event Timeline
Log In to Comment