Page MenuHomePhabricator

D13274.id44041.diff
No OneTemporary

D13274.id44041.diff

diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -111,7 +111,11 @@
import { userSurfacedPermissionsFromRolePermissions } from '../utils/role-utils.js';
import { usingOlmViaTunnelbrokerForDMs } from '../utils/services-utils.js';
import { firstLine } from '../utils/string-utils.js';
-import { pendingThreadIDRegex } from '../utils/validation-utils.js';
+import {
+ pendingThreadIDRegex,
+ pendingThickSidebarURLPrefix,
+ pendingSidebarURLPrefix,
+} from '../utils/validation-utils.js';
function threadHasPermission(
threadInfo: ?(ThreadInfo | LegacyRawThreadInfo | RawThreadInfo),
@@ -373,7 +377,10 @@
}
function threadIsPendingSidebar(threadID: ?string): boolean {
- return !!threadID?.startsWith('pending/sidebar/');
+ return (
+ !!threadID?.startsWith(`pending/${pendingSidebarURLPrefix}/`) ||
+ !!threadID?.startsWith(`pending/${pendingThickSidebarURLPrefix}`)
+ );
}
function getSingleOtherUser(
@@ -397,9 +404,9 @@
): string {
let pendingThreadKey;
if (sourceMessageID && threadTypeIsThick(threadType)) {
- pendingThreadKey = `dm_sidebar/${sourceMessageID}`;
+ pendingThreadKey = `${pendingThickSidebarURLPrefix}/${sourceMessageID}`;
} else if (sourceMessageID) {
- pendingThreadKey = `sidebar/${sourceMessageID}`;
+ pendingThreadKey = `${pendingSidebarURLPrefix}/${sourceMessageID}`;
} else {
pendingThreadKey = [...memberIDs].sort().join('+');
}
@@ -425,16 +432,17 @@
const [threadTypeString, threadKey] = pendingThreadIDMatches[1].split('/');
let threadType;
- if (threadTypeString === 'dm_sidebar') {
+ if (threadTypeString === pendingThickSidebarURLPrefix) {
threadType = threadTypes.THICK_SIDEBAR;
- } else if (threadTypeString === 'sidebar') {
+ } else if (threadTypeString === pendingSidebarURLPrefix) {
threadType = threadTypes.SIDEBAR;
} else {
threadType = assertThreadType(Number(threadTypeString.replace('type', '')));
}
const threadTypeStringIsSidebar =
- threadTypeString === 'sidebar' || threadTypeString === 'dm_sidebar';
+ threadTypeString === pendingSidebarURLPrefix ||
+ threadTypeString === pendingThickSidebarURLPrefix;
const memberIDs = threadTypeStringIsSidebar ? [] : threadKey.split('+');
const sourceMessageID = threadTypeStringIsSidebar ? threadKey : null;
return {
diff --git a/lib/shared/thread-utils.test.js b/lib/shared/thread-utils.test.js
--- a/lib/shared/thread-utils.test.js
+++ b/lib/shared/thread-utils.test.js
@@ -4,6 +4,7 @@
parsePendingThreadID,
threadInfoFromRawThreadInfo,
getPendingThreadID,
+ threadIsPendingSidebar,
} from './thread-utils.js';
import { threadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
@@ -213,3 +214,28 @@
).toStrictEqual('pending/dm_sidebar/12345');
});
});
+
+describe('threadIsPendingSidebar', () => {
+ it('should correctly check if sidebar is pending', () => {
+ const thinPendingSidebarID = getPendingThreadID(
+ threadTypes.SIDEBAR,
+ [],
+ '12345',
+ );
+ const thickPendingSidebarID = getPendingThreadID(
+ threadTypes.THICK_SIDEBAR,
+ [],
+ '12345',
+ );
+ const nonSidebarPendinThreadID = getPendingThreadID(
+ threadTypes.PERSONAL,
+ [],
+ );
+
+ expect(threadIsPendingSidebar(thinPendingSidebarID)).toStrictEqual(true);
+ expect(threadIsPendingSidebar(thickPendingSidebarID)).toStrictEqual(true);
+ expect(threadIsPendingSidebar(nonSidebarPendinThreadID)).toStrictEqual(
+ false,
+ );
+ });
+});
diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js
--- a/lib/utils/validation-utils.js
+++ b/lib/utils/validation-utils.js
@@ -112,7 +112,9 @@
'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}';
const idSchemaRegex = `(?:(?:[0-9]+|${uuidRegex})\\|)?(?:[0-9]+|${uuidRegex})`;
-const pendingThreadIDRegex = `pending/(type[0-9]+/[0-9]+(\\+[0-9]+)*|(sidebar|dm_sidebar)/${idSchemaRegex})`;
+const pendingSidebarURLPrefix = 'sidebar';
+const pendingThickSidebarURLPrefix = 'dm_sidebar';
+const pendingThreadIDRegex = `pending/(type[0-9]+/[0-9]+(\\+[0-9]+)*|(${pendingSidebarURLPrefix}|${pendingThickSidebarURLPrefix})/${idSchemaRegex})`;
const thickThreadIDRegex: RegExp = new RegExp(`^${uuidRegex}$`);
const chatNameMaxLength = 191;
@@ -146,6 +148,8 @@
assertWithValidator,
ashoatKeyserverID,
idSchemaRegex,
+ pendingSidebarURLPrefix,
+ pendingThickSidebarURLPrefix,
pendingThreadIDRegex,
thickThreadIDRegex,
validChatNameRegex,

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 12:57 PM (19 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2530722
Default Alt Text
D13274.id44041.diff (4 KB)

Event Timeline