Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3387452
D9325.id32252.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
19 KB
Referenced Files
None
Subscribers
None
D9325.id32252.diff
View Options
diff --git a/lib/shared/message-utils.test.js b/lib/shared/message-utils.test.js
--- a/lib/shared/message-utils.test.js
+++ b/lib/shared/message-utils.test.js
@@ -1,6 +1,7 @@
// @flow
import { isInvalidSidebarSource } from './message-utils.js';
+import { messageSpecs } from '../shared/messages/message-specs.js';
import { messageTypes } from '../types/message-types-enum.js';
import type { RawSidebarSourceMessageInfo } from '../types/message-types.js';
import type { RawAddMembersMessageInfo } from '../types/messages/add-members.js';
@@ -25,7 +26,7 @@
import type { RawUpdateRelationshipMessageInfo } from '../types/messages/update-relationship.js';
import { threadTypes } from '../types/thread-types-enum.js';
-describe('isInvalidSidebarSource', () => {
+describe('isInvalidSidebarSource & canBeSidebarSource', () => {
it('should return false for RawTextMessageInfo', () => {
const textMessageInfo: RawTextMessageInfo = {
type: messageTypes.TEXT,
@@ -36,10 +37,14 @@
text: 'This is a text message',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.TEXT];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(textMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawCreateThreadMessageInfo', () => {
@@ -57,11 +62,15 @@
},
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CREATE_THREAD];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
createThreadMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawAddMembersMessageInfo', () => {
@@ -73,11 +82,15 @@
addedUserIDs: ['4', '5'],
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.ADD_MEMBERS];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
addMembersMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawCreateSubthreadMessageInfo', () => {
@@ -89,11 +102,15 @@
childThreadID: '10002',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CREATE_SUB_THREAD];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
createSubthreadMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawChangeSettingsMessageInfo', () => {
@@ -106,11 +123,15 @@
value: '#FFFFFF',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CHANGE_SETTINGS];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
changeSettingsMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawRemoveMembersMessageInfo', () => {
@@ -122,11 +143,15 @@
removedUserIDs: ['1', '2', '3'],
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.REMOVE_MEMBERS];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
removeMembersMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawChangeRoleMessageInfo', () => {
@@ -140,11 +165,15 @@
roleName: 'Moderators',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CHANGE_ROLE];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
changeRoleMessageinfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawLeaveThreadMessageInfo', () => {
@@ -155,11 +184,15 @@
time: 10000,
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.LEAVE_THREAD];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
leaveThreadMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawJoinThreadMessageInfo', () => {
@@ -170,11 +203,15 @@
time: 10000,
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.JOIN_THREAD];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
joinThreadMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawCreateEntryMessageInfo', () => {
@@ -188,11 +225,15 @@
text: 'This is a calendar entry',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CREATE_ENTRY];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
createEntryMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawEditEntryMessageInfo', () => {
@@ -206,10 +247,14 @@
text: 'This is an edited calendar entry',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.EDIT_ENTRY];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(editEntryMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawDeleteEntryMessageInfo', () => {
@@ -223,11 +268,15 @@
text: 'This is a deleted calendar entry',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.DELETE_ENTRY];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
deleteEntryMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawRestoreEntryMessageInfo', () => {
@@ -241,11 +290,15 @@
text: 'This is a restored calendar entry',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.RESTORE_ENTRY];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
restoreEntryMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawUpdateRelationshipMessageInfo', () => {
@@ -258,11 +311,15 @@
operation: 'request_sent',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.UPDATE_RELATIONSHIP];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
updateRelationshipMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawImagesMessageInfo', () => {
@@ -286,10 +343,14 @@
],
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.IMAGES];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(imageMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return false for RawMediaMessageInfo', () => {
@@ -313,10 +374,14 @@
],
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.MULTIMEDIA];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(mediaMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return true for RawSidebarSourceMessageInfo', () => {
@@ -336,11 +401,15 @@
},
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.SIDEBAR_SOURCE];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
sidebarSourceMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(true);
+ expect(canBeSidebarSource).toBe(false);
});
it('should return false for RawCreateSidebarMessageInfo', () => {
@@ -358,11 +427,15 @@
},
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.CREATE_SIDEBAR];
const shouldBeInvalidSidebarSource = isInvalidSidebarSource(
createSidebarMessageInfo,
);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(false);
+ expect(canBeSidebarSource).toBe(true);
});
it('should return true for RawReactionMessageInfo', () => {
@@ -377,10 +450,14 @@
action: 'add_reaction',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.REACTION];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(reactionMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(true);
+ expect(canBeSidebarSource).toBe(false);
});
it('should return true for RawEditMessageInfo', () => {
@@ -393,10 +470,14 @@
text: 'This is an edited message',
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.EDIT_MESSAGE];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(editMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(true);
+ expect(canBeSidebarSource).toBe(false);
});
it('should return true for RawTogglePinMessageInfo', () => {
@@ -410,9 +491,13 @@
time: 10000,
id: '1',
};
+ const messageSpec = messageSpecs[messageTypes.TOGGLE_PIN];
const shouldBeInvalidSidebarSource =
isInvalidSidebarSource(togglePinMessageInfo);
+ const canBeSidebarSource = messageSpec.canBeSidebarSource;
+
expect(shouldBeInvalidSidebarSource).toBe(true);
+ expect(canBeSidebarSource).toBe(false);
});
});
diff --git a/lib/shared/messages/add-members-message-spec.js b/lib/shared/messages/add-members-message-spec.js
--- a/lib/shared/messages/add-members-message-spec.js
+++ b/lib/shared/messages/add-members-message-spec.js
@@ -166,5 +166,7 @@
return rawMessageInfo.addedUserIDs;
},
+ canBeSidebarSource: true,
+
validator: rawAddMembersMessageInfoValidator,
});
diff --git a/lib/shared/messages/change-role-message-spec.js b/lib/shared/messages/change-role-message-spec.js
--- a/lib/shared/messages/change-role-message-spec.js
+++ b/lib/shared/messages/change-role-message-spec.js
@@ -236,5 +236,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawChangeRoleMessageInfoValidator,
});
diff --git a/lib/shared/messages/change-settings-message-spec.js b/lib/shared/messages/change-settings-message-spec.js
--- a/lib/shared/messages/change-settings-message-spec.js
+++ b/lib/shared/messages/change-settings-message-spec.js
@@ -182,5 +182,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawChangeSettingsMessageInfoValidator,
});
diff --git a/lib/shared/messages/create-entry-message-spec.js b/lib/shared/messages/create-entry-message-spec.js
--- a/lib/shared/messages/create-entry-message-spec.js
+++ b/lib/shared/messages/create-entry-message-spec.js
@@ -121,5 +121,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawCreateEntryMessageInfoValidator,
});
diff --git a/lib/shared/messages/create-sidebar-message-spec.js b/lib/shared/messages/create-sidebar-message-spec.js
--- a/lib/shared/messages/create-sidebar-message-spec.js
+++ b/lib/shared/messages/create-sidebar-message-spec.js
@@ -206,5 +206,7 @@
return [parentThreadID];
},
+ canBeSidebarSource: true,
+
validator: rawCreateSidebarMessageInfoValidator,
});
diff --git a/lib/shared/messages/create-sub-thread-message-spec.js b/lib/shared/messages/create-sub-thread-message-spec.js
--- a/lib/shared/messages/create-sub-thread-message-spec.js
+++ b/lib/shared/messages/create-sub-thread-message-spec.js
@@ -163,5 +163,7 @@
return [rawMessageInfo.childThreadID];
},
+ canBeSidebarSource: true,
+
validator: rawCreateSubthreadMessageInfoValidator,
});
diff --git a/lib/shared/messages/create-thread-message-spec.js b/lib/shared/messages/create-thread-message-spec.js
--- a/lib/shared/messages/create-thread-message-spec.js
+++ b/lib/shared/messages/create-thread-message-spec.js
@@ -202,5 +202,7 @@
return parentThreadID ? [parentThreadID] : [];
},
+ canBeSidebarSource: true,
+
validator: rawCreateThreadMessageInfoValidator,
});
diff --git a/lib/shared/messages/delete-entry-message-spec.js b/lib/shared/messages/delete-entry-message-spec.js
--- a/lib/shared/messages/delete-entry-message-spec.js
+++ b/lib/shared/messages/delete-entry-message-spec.js
@@ -136,5 +136,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawDeleteEntryMessageInfoValidator,
});
diff --git a/lib/shared/messages/edit-entry-message-spec.js b/lib/shared/messages/edit-entry-message-spec.js
--- a/lib/shared/messages/edit-entry-message-spec.js
+++ b/lib/shared/messages/edit-entry-message-spec.js
@@ -121,5 +121,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawEditEntryMessageInfoValidator,
});
diff --git a/lib/shared/messages/edit-message-spec.js b/lib/shared/messages/edit-message-spec.js
--- a/lib/shared/messages/edit-message-spec.js
+++ b/lib/shared/messages/edit-message-spec.js
@@ -8,7 +8,7 @@
assertMessageType,
messageTypes,
} from '../../types/message-types-enum.js';
-import { type ClientDBMessageInfo } from '../../types/message-types.js';
+import type { ClientDBMessageInfo } from '../../types/message-types.js';
import {
type EditMessageData,
type RawEditMessageInfo,
@@ -140,5 +140,7 @@
return unwrapped;
},
+ canBeSidebarSource: false,
+
validator: rawEditMessageInfoValidator,
});
diff --git a/lib/shared/messages/join-thread-message-spec.js b/lib/shared/messages/join-thread-message-spec.js
--- a/lib/shared/messages/join-thread-message-spec.js
+++ b/lib/shared/messages/join-thread-message-spec.js
@@ -119,5 +119,7 @@
return joinResult(rawMessageInfo.type, rawMessageInfo.threadID);
},
+ canBeSidebarSource: true,
+
validator: rawJoinThreadMessageInfoValidator,
});
diff --git a/lib/shared/messages/leave-thread-message-spec.js b/lib/shared/messages/leave-thread-message-spec.js
--- a/lib/shared/messages/leave-thread-message-spec.js
+++ b/lib/shared/messages/leave-thread-message-spec.js
@@ -119,5 +119,7 @@
return joinResult(rawMessageInfo.type, rawMessageInfo.threadID);
},
+ canBeSidebarSource: true,
+
validator: rawLeaveThreadMessageInfoValidator,
});
diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js
--- a/lib/shared/messages/message-spec.js
+++ b/lib/shared/messages/message-spec.js
@@ -113,6 +113,7 @@
+startsThread?: boolean,
+threadIDs?: (rawMessageInfo: RawInfo) => $ReadOnlyArray<string>,
+includedInRepliesCount?: boolean,
+ +canBeSidebarSource: boolean,
+useCreationSideEffectsFunc?: () => CreationSideEffectsFunc<RawInfo>,
+validator: TType<RawInfo>,
};
diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js
--- a/lib/shared/messages/multimedia-message-spec.js
+++ b/lib/shared/messages/multimedia-message-spec.js
@@ -351,6 +351,8 @@
includedInRepliesCount: true,
+ canBeSidebarSource: true,
+
validator: rawMultimediaMessageInfoValidator,
});
diff --git a/lib/shared/messages/reaction-message-spec.js b/lib/shared/messages/reaction-message-spec.js
--- a/lib/shared/messages/reaction-message-spec.js
+++ b/lib/shared/messages/reaction-message-spec.js
@@ -14,9 +14,9 @@
assertMessageType,
messageTypes,
} from '../../types/message-types-enum.js';
-import {
- type MessageInfo,
- type ClientDBMessageInfo,
+import type {
+ MessageInfo,
+ ClientDBMessageInfo,
} from '../../types/message-types.js';
import {
type ReactionMessageData,
@@ -218,5 +218,7 @@
return action === 'add_reaction' ? pushTypes.NOTIF : pushTypes.RESCIND;
},
+ canBeSidebarSource: false,
+
validator: rawReactionMessageInfoValidator,
});
diff --git a/lib/shared/messages/remove-members-message-spec.js b/lib/shared/messages/remove-members-message-spec.js
--- a/lib/shared/messages/remove-members-message-spec.js
+++ b/lib/shared/messages/remove-members-message-spec.js
@@ -166,5 +166,7 @@
return rawMessageInfo.removedUserIDs;
},
+ canBeSidebarSource: true,
+
validator: rawRemoveMembersMessageInfoValidator,
});
diff --git a/lib/shared/messages/restore-entry-message-spec.js b/lib/shared/messages/restore-entry-message-spec.js
--- a/lib/shared/messages/restore-entry-message-spec.js
+++ b/lib/shared/messages/restore-entry-message-spec.js
@@ -136,5 +136,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawRestoreEntryMessageInfoValidator,
});
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
@@ -172,5 +172,7 @@
startsThread: true,
+ canBeSidebarSource: false,
+
validator: rawSidebarSourceMessageInfoValidator,
});
diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js
--- a/lib/shared/messages/text-message-spec.js
+++ b/lib/shared/messages/text-message-spec.js
@@ -317,5 +317,7 @@
};
},
+ canBeSidebarSource: true,
+
validator: rawTextMessageInfoValidator,
});
diff --git a/lib/shared/messages/toggle-pin-message-spec.js b/lib/shared/messages/toggle-pin-message-spec.js
--- a/lib/shared/messages/toggle-pin-message-spec.js
+++ b/lib/shared/messages/toggle-pin-message-spec.js
@@ -155,5 +155,7 @@
return unwrapped;
},
+ canBeSidebarSource: false,
+
validator: rawTogglePinMessageInfoValidator,
});
diff --git a/lib/shared/messages/unsupported-message-spec.js b/lib/shared/messages/unsupported-message-spec.js
--- a/lib/shared/messages/unsupported-message-spec.js
+++ b/lib/shared/messages/unsupported-message-spec.js
@@ -4,7 +4,7 @@
import { pushTypes, type MessageSpec } from './message-spec.js';
import { messageTypes } from '../../types/message-types-enum.js';
-import { type ClientDBMessageInfo } from '../../types/message-types.js';
+import type { ClientDBMessageInfo } from '../../types/message-types.js';
import {
type RawUnsupportedMessageInfo,
type UnsupportedMessageInfo,
@@ -74,5 +74,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawUnsupportedMessageInfoValidator,
});
diff --git a/lib/shared/messages/update-relationship-message-spec.js b/lib/shared/messages/update-relationship-message-spec.js
--- a/lib/shared/messages/update-relationship-message-spec.js
+++ b/lib/shared/messages/update-relationship-message-spec.js
@@ -154,5 +154,7 @@
generatesNotifs: async () => pushTypes.NOTIF,
+ canBeSidebarSource: true,
+
validator: rawUpdateRelationshipMessageInfoValidator,
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 9:34 AM (21 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2600428
Default Alt Text
D9325.id32252.diff (19 KB)
Attached To
Mode
D9325: [lib] Introduce a canBeSidebarSource function in each message spec
Attached
Detach File
Event Timeline
Log In to Comment