diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -908,31 +908,41 @@ }; } - const messageData = { - type: messageTypes.TOGGLE_PIN, - threadID, - targetMessageID: messageID, - action, - pinnedContent: getPinnedContentFromMessage(targetMessage), - creatorID: viewer.userID, - time: Date.now(), + const createMessagesAsync = async () => { + const messageData = { + type: messageTypes.TOGGLE_PIN, + threadID, + targetMessageID: messageID, + action, + pinnedContent: getPinnedContentFromMessage(targetMessage), + creatorID: viewer.userID, + time: Date.now(), + }; + const newMessageInfos = await createMessages(viewer, [messageData]); + return newMessageInfos; }; - const newMessageInfos = await createMessages(viewer, [messageData]); - const { threadInfos: serverThreadInfos } = await fetchServerThreadInfos({ - threadID, - }); - const time = Date.now(); - const updates = []; - for (const member of serverThreadInfos[threadID].members) { - updates.push({ - userID: member.id, - time, + const createUpdatesAsync = async () => { + const { threadInfos: serverThreadInfos } = await fetchServerThreadInfos({ threadID, - type: updateTypes.UPDATE_THREAD, }); - } - await createUpdates(updates); + const time = Date.now(); + const updates = []; + for (const member of serverThreadInfos[threadID].members) { + updates.push({ + userID: member.id, + time, + threadID, + type: updateTypes.UPDATE_THREAD, + }); + } + await createUpdates(updates); + }; + + const [newMessageInfos] = await Promise.all([ + createMessagesAsync(), + createUpdatesAsync(), + ]); return { newMessageInfos,