Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3358683
D5811.id19350.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.id19350.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,48 @@
? sortMessageInfoList([...threadMessageInfos, ...additionalMessages])
: threadMessageInfos;
+ const targetMessageReactionsMap = new Map<string, Map<string, Set<string>>>();
+
+ 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>>();
+
+ const usersSet = new Set<string>();
+ usersSet.add(messageInfo.creator.id);
+
+ reactsMap.set(messageInfo.reaction, usersSet);
+ targetMessageReactionsMap.set(messageInfo.targetMessageID, reactsMap);
+ continue;
+ }
+
+ const messageReactsMap = targetMessageReactionsMap.get(
+ messageInfo.targetMessageID,
+ );
+ invariant(messageReactsMap, 'messageReactsInfo should be set');
+
+ if (!messageReactsMap.has(messageInfo.reaction)) {
+ const usersSet = new Set<string>();
+ usersSet.add(messageInfo.creator.id);
+
+ messageReactsMap.set(messageInfo.reaction, usersSet);
+ continue;
+ }
+
+ 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 +396,41 @@
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) {
+ 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
@@ -358,6 +443,7 @@
);
const localMessageInfo =
messageStore.local[messageKey(originalMessageInfo)];
+
chatMessageItems.push({
itemType: 'message',
messageInfo: originalMessageInfo,
@@ -366,6 +452,7 @@
startsCluster,
endsCluster: false,
threadCreatedFromMessage,
+ reactions: renderedReactions,
});
} else {
invariant(
@@ -386,6 +473,7 @@
endsCluster: false,
threadCreatedFromMessage,
robotext,
+ reactions: renderedReactions,
});
}
lastMessageInfo = originalMessageInfo;
@@ -412,13 +500,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 +519,7 @@
threadInfos,
threadInfoFromSourceMessageID,
additionalMessages,
+ viewerID,
);
},
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 5:46 AM (21 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578567
Default Alt Text
D5811.id19350.diff (5 KB)
Attached To
Mode
D5811: [lib] introduced reactions field to chatMessageItems
Attached
Detach File
Event Timeline
Log In to Comment