Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3358491
D5811.id19437.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D5811.id19437.diff
View Options
diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js
--- a/lib/selectors/chat-selectors.js
+++ b/lib/selectors/chat-selectors.js
@@ -272,6 +272,7 @@
endsCluster: boolean,
+robotext: string,
+threadCreatedFromMessage: ?ThreadInfo,
+ +reactions: $ReadOnlyMap<string, MessageReactionInfo>,
};
export type ChatMessageInfoItem =
| RobotextChatMessageInfoItem
@@ -283,8 +284,14 @@
+startsCluster: boolean,
endsCluster: boolean,
+threadCreatedFromMessage: ?ThreadInfo,
+ +reactions: $ReadOnlyMap<string, MessageReactionInfo>,
};
export type ChatMessageItem = { itemType: 'loader' } | ChatMessageInfoItem;
+export type MessageReactionInfo = {
+ +viewerReacted: boolean,
+ +users: $ReadOnlySet<string>,
+};
+
const msInFiveMinutes = 5 * 60 * 1000;
function createChatMessageItems(
threadID: string,
@@ -293,6 +300,7 @@
threadInfos: { +[id: string]: ThreadInfo },
threadInfoFromSourceMessageID: { +[id: string]: ThreadInfo },
additionalMessages: $ReadOnlyArray<MessageInfo>,
+ viewerID: string,
): ChatMessageItem[] {
const thread = messageStore.threads[threadID];
@@ -304,6 +312,44 @@
? sortMessageInfoList([...threadMessageInfos, ...additionalMessages])
: threadMessageInfos;
+ const targetMessageReactionsMap = new Map<string, Map<string, Set<string>>>();
+
+ // We need to iterate backwards to make the order of the messages go from
+ // oldest to most recent, and we could run into the case where the most
+ // recent reaction message has remove_reaction as its action. The code
+ // would then try to remove a user that hasn't been put into the usersSet
+ // already, and essentially it would just skip that unlike
+ for (let i = messages.length - 1; i >= 0; i--) {
+ const messageInfo = messages[i];
+ if (messageInfo.type !== messageTypes.REACTION) {
+ continue;
+ }
+
+ if (!targetMessageReactionsMap.has(messageInfo.targetMessageID)) {
+ const reactsMap = new Map<string, Set<string>>();
+ targetMessageReactionsMap.set(messageInfo.targetMessageID, reactsMap);
+ }
+
+ const messageReactsMap = targetMessageReactionsMap.get(
+ messageInfo.targetMessageID,
+ );
+ invariant(messageReactsMap, 'messageReactsInfo should be set');
+
+ if (!messageReactsMap.has(messageInfo.reaction)) {
+ const usersSet = new Set<string>();
+ messageReactsMap.set(messageInfo.reaction, usersSet);
+ }
+
+ const messageReactionUsersSet = messageReactsMap.get(messageInfo.reaction);
+ invariant(messageReactionUsersSet, 'messageReactionUsersSet should be set');
+
+ if (messageInfo.action === 'add_reaction') {
+ messageReactionUsersSet.add(messageInfo.creator.id);
+ } else {
+ messageReactionUsersSet.delete(messageInfo.creator.id);
+ }
+ }
+
const chatMessageItems = [];
let lastMessageInfo = null;
for (let i = messages.length - 1; i >= 0; i--) {
@@ -346,6 +392,43 @@
messageInfo.id && threadInfos[threadID]?.type !== threadTypes.SIDEBAR
? threadInfoFromSourceMessageID[messageInfo.id]
: undefined;
+
+ const renderedReactions: $ReadOnlyMap<
+ string,
+ MessageReactionInfo,
+ > = (() => {
+ const result = new Map<string, MessageReactionInfo>();
+
+ let messageReactsMap;
+ if (originalMessageInfo.id) {
+ messageReactsMap = targetMessageReactionsMap.get(
+ originalMessageInfo.id,
+ );
+ }
+
+ if (!messageReactsMap) {
+ return result;
+ }
+
+ for (const reaction of messageReactsMap.keys()) {
+ const reactionUsersSet = messageReactsMap.get(reaction);
+ invariant(reactionUsersSet, 'reactionUsersSet should be set');
+
+ if (reactionUsersSet.size === 0) {
+ continue;
+ }
+
+ const messageReactionInfo = {
+ users: reactionUsersSet,
+ viewerReacted: reactionUsersSet.has(viewerID),
+ };
+
+ result.set(reaction, messageReactionInfo);
+ }
+
+ return result;
+ })();
+
if (isComposableMessageType(originalMessageInfo.type)) {
// We use these invariants instead of just checking the messageInfo.type
// directly in the conditional above so that isComposableMessageType can
@@ -366,6 +449,7 @@
startsCluster,
endsCluster: false,
threadCreatedFromMessage,
+ reactions: renderedReactions,
});
} else {
invariant(
@@ -386,6 +470,7 @@
endsCluster: false,
threadCreatedFromMessage,
robotext,
+ reactions: renderedReactions,
});
}
lastMessageInfo = originalMessageInfo;
@@ -412,13 +497,16 @@
messageInfoSelector,
threadInfoSelector,
threadInfoFromSourceMessageIDSelector,
+ (state: BaseAppState<*>) =>
+ state.currentUserInfo && state.currentUserInfo.id,
(
messageStore: MessageStore,
messageInfos: { +[id: string]: ?MessageInfo },
threadInfos: { +[id: string]: ThreadInfo },
threadInfoFromSourceMessageID: { +[id: string]: ThreadInfo },
+ viewerID: ?string,
): ?(ChatMessageItem[]) => {
- if (!threadID) {
+ if (!threadID || !viewerID) {
return null;
}
return createChatMessageItems(
@@ -428,6 +516,7 @@
threadInfos,
threadInfoFromSourceMessageID,
additionalMessages,
+ viewerID,
);
},
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 5:05 AM (20 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578429
Default Alt Text
D5811.id19437.diff (5 KB)
Attached To
Mode
D5811: [lib] introduced reactions field to chatMessageItems
Attached
Detach File
Event Timeline
Log In to Comment