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 @@ -88,6 +88,7 @@ UserInfos, AccountUserInfo, LoggedInUserInfo, + UserInfo, } from '../types/user-types.js'; import { useDispatchActionPromise, @@ -398,16 +399,42 @@ return threadInfoFromRawThreadInfo(rawThreadInfo, viewerID, userInfos); } -function createPendingThreadItem( +type PendingPersonalThread = { + +threadInfo: ThreadInfo, + +pendingPersonalThreadUserInfo: UserInfo, +}; + +function createPendingPersonalThread( loggedInUserInfo: LoggedInUserInfo, - user: UserIDAndUsername, -): ChatThreadItem { + userID: string, + username: string, +): PendingPersonalThread { + const pendingPersonalThreadUserInfo = { + id: userID, + username: username, + }; + + const pendingThreadMembers = [ + loggedInUserInfo, + pendingPersonalThreadUserInfo, + ]; + const threadInfo = createPendingThread({ viewerID: loggedInUserInfo.id, threadType: threadTypes.PERSONAL, - members: [loggedInUserInfo, user], + members: pendingThreadMembers, }); + return { threadInfo, pendingPersonalThreadUserInfo }; +} + +function createPendingThreadItem( + loggedInUserInfo: LoggedInUserInfo, + user: UserIDAndUsername, +): ChatThreadItem { + const { threadInfo, pendingPersonalThreadUserInfo } = + createPendingPersonalThread(loggedInUserInfo, user.id, user.username); + return { type: 'chatThreadItem', threadInfo, @@ -416,10 +443,7 @@ lastUpdatedTime: threadInfo.creationTime, lastUpdatedTimeIncludingSidebars: threadInfo.creationTime, sidebars: [], - pendingPersonalThreadUserInfo: { - id: user.id, - username: user.username, - }, + pendingPersonalThreadUserInfo, }; } @@ -1791,6 +1815,7 @@ getPendingThreadID, parsePendingThreadID, createPendingThread, + createPendingPersonalThread, createUnresolvedPendingSidebar, extractNewMentionedParentMembers, createPendingSidebar,