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 @@ -423,8 +423,7 @@ sourceMessage.type !== messageTypes.REACTION && sourceMessage.type !== messageTypes.EDIT_MESSAGE && sourceMessage.type !== messageTypes.SIDEBAR_SOURCE && - sourceMessage.type !== messageTypes.TOGGLE_PIN && - sourceMessage.type !== messageTypes.CHANGE_ROLE, + sourceMessage.type !== messageTypes.TOGGLE_PIN, 'Invalid sidebar source type', ); 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 @@ -21,6 +21,7 @@ createMessageInfo, getMostRecentNonLocalMessageID, sortMessageInfoList, + parseSourceMessageIDFromPendingThreadID, } from '../shared/message-utils.js'; import { threadIsPending, @@ -529,9 +530,15 @@ originalMessageInfo.type !== messageTypes.MULTIMEDIA, "Flow doesn't understand isComposableMessageType above", ); + const parentMessageID = parseSourceMessageIDFromPendingThreadID(threadID); + const parentThreadID = parentMessageID + ? messageStore.messages[parentMessageID]?.threadID + : ''; + const robotext = robotextForMessageInfo( originalMessageInfo, threadInfos[threadID], + threadInfos[parentThreadID], ); chatMessageItems.push({ itemType: 'message', 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 @@ -74,13 +74,14 @@ function robotextForMessageInfo( messageInfo: RobotextMessageInfo, threadInfo: ?ThreadInfo, + parentThreadInfo: ?ThreadInfo, ): EntityText { const messageSpec = messageSpecs[messageInfo.type]; invariant( messageSpec.robotext, `we're not aware of messageType ${messageInfo.type}`, ); - return messageSpec.robotext(messageInfo, { threadInfo }); + return messageSpec.robotext(messageInfo, { threadInfo, parentThreadInfo }); } function createMessageInfo( @@ -423,7 +424,7 @@ messageInfo.type !== messageTypes.EDIT_MESSAGE, 'messageTitle can only be auto-generated for RobotextMessageInfo', ); - return robotextForMessageInfo(messageInfo, threadInfo); + return robotextForMessageInfo(messageInfo, threadInfo, null); } function mergeThreadMessageInfos( @@ -647,11 +648,16 @@ messageType === messageTypes.REACTION || messageType === messageTypes.EDIT_MESSAGE || messageType === messageTypes.SIDEBAR_SOURCE || - messageType === messageTypes.TOGGLE_PIN || - messageType === messageTypes.CHANGE_ROLE + messageType === messageTypes.TOGGLE_PIN ); } +function parseSourceMessageIDFromPendingThreadID(id: string): ?string { + const regex: RegExp = /(\d+\|\d+)/; + const match = regex.exec(id); + return match?.[1]; +} + export { localIDPrefix, messageKey, @@ -682,4 +688,5 @@ constructChangeRoleEntityText, useNextLocalID, isInvalidSidebarSource, + parseSourceMessageIDFromPendingThreadID, }; 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 @@ -12,8 +12,7 @@ messageType === messageTypes.REACTION || messageType === messageTypes.EDIT_MESSAGE || messageType === messageTypes.SIDEBAR_SOURCE || - messageType === messageTypes.TOGGLE_PIN || - messageType === messageTypes.CHANGE_ROLE + messageType === messageTypes.TOGGLE_PIN ) { expect(shouldBeInvalidSidebarSource).toBe(true); } else { 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 @@ -129,10 +129,11 @@ users.map(user => ET`${ET.user({ userInfo: user })}`), ); - const { threadInfo } = params; - invariant(threadInfo, 'ThreadInfo should be set for CHANGE_ROLE message'); + const { threadInfo, parentThreadInfo } = params; + const thread = threadInfo ?? parentThreadInfo; + invariant(thread, 'ThreadInfo should be set for CHANGE_ROLE message'); - const threadRoleName = threadInfo.roles[messageInfo.newRole]?.name; + const threadRoleName = thread.roles[messageInfo.newRole]?.name; const messageInfoRoleName = messageInfo.roleName; const roleName = threadRoleName ?? messageInfoRoleName; 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 @@ -43,6 +43,7 @@ export type RobotextParams = { +threadInfo: ?ThreadInfo, + +parentThreadInfo: ?ThreadInfo, }; export type NotificationTextsParams = { diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js --- a/lib/shared/notif-utils.js +++ b/lib/shared/notif-utils.js @@ -271,7 +271,7 @@ messageInfo: RobotextMessageInfo, threadInfo: ThreadInfo, ): EntityText { - const robotext = robotextForMessageInfo(messageInfo, threadInfo); + const robotext = robotextForMessageInfo(messageInfo, threadInfo, null); return robotext.map(entity => { if ( typeof entity !== 'string' &&