Read Pinned Chats
Co-authored-by: Sidney Keese <sidney@carbonfive.com>
This commit is contained in:
parent
3ca547f3dd
commit
63b2644cb4
15 changed files with 444 additions and 46 deletions
|
@ -14,6 +14,7 @@ import {
|
|||
} from '../textsecure.d';
|
||||
import { deriveGroupFields, waitThenMaybeUpdateGroup } from '../groups';
|
||||
import { ConversationModel } from '../models/conversations';
|
||||
import { ConversationAttributesTypeType } from '../model-types.d';
|
||||
|
||||
const { updateConversation } = dataInterface;
|
||||
|
||||
|
@ -496,6 +497,7 @@ export async function mergeAccountRecord(
|
|||
avatarUrl,
|
||||
linkPreviews,
|
||||
noteToSelfArchived,
|
||||
pinnedConversations: remotelyPinnedConversationClasses,
|
||||
profileKey,
|
||||
readReceipts,
|
||||
sealedSenderIndicators,
|
||||
|
@ -520,6 +522,104 @@ export async function mergeAccountRecord(
|
|||
window.storage.put('profileKey', profileKey.toArrayBuffer());
|
||||
}
|
||||
|
||||
if (remotelyPinnedConversationClasses) {
|
||||
const locallyPinnedConversations = window.ConversationController._conversations.filter(
|
||||
conversation => Boolean(conversation.get('isPinned'))
|
||||
);
|
||||
|
||||
const remotelyPinnedConversationPromises = remotelyPinnedConversationClasses.map(
|
||||
async pinnedConversation => {
|
||||
let conversationId;
|
||||
let conversationType: ConversationAttributesTypeType = 'private';
|
||||
|
||||
switch (pinnedConversation.identifier) {
|
||||
case 'contact': {
|
||||
if (!pinnedConversation.contact) {
|
||||
throw new Error('mergeAccountRecord: no contact found');
|
||||
}
|
||||
conversationId = window.ConversationController.ensureContactIds(
|
||||
pinnedConversation.contact
|
||||
);
|
||||
conversationType = 'private';
|
||||
break;
|
||||
}
|
||||
case 'legacyGroupId': {
|
||||
if (!pinnedConversation.legacyGroupId) {
|
||||
throw new Error('mergeAccountRecord: no legacyGroupId found');
|
||||
}
|
||||
conversationId = pinnedConversation.legacyGroupId.toBinary();
|
||||
conversationType = 'group';
|
||||
break;
|
||||
}
|
||||
case 'groupMasterKey': {
|
||||
if (!pinnedConversation.groupMasterKey) {
|
||||
throw new Error('mergeAccountRecord: no groupMasterKey found');
|
||||
}
|
||||
const masterKeyBuffer = pinnedConversation.groupMasterKey.toArrayBuffer();
|
||||
const groupFields = deriveGroupFields(masterKeyBuffer);
|
||||
const groupId = arrayBufferToBase64(groupFields.id);
|
||||
|
||||
conversationId = groupId;
|
||||
conversationType = 'group';
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
window.log.error('mergeAccountRecord: Invalid identifier received');
|
||||
}
|
||||
}
|
||||
|
||||
if (!conversationId) {
|
||||
window.log.error(
|
||||
`mergeAccountRecord: missing conversation id. looking based on ${pinnedConversation.identifier}`
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (conversationType === 'private') {
|
||||
return window.ConversationController.getOrCreateAndWait(
|
||||
conversationId,
|
||||
conversationType
|
||||
);
|
||||
}
|
||||
|
||||
return window.ConversationController.get(conversationId);
|
||||
}
|
||||
);
|
||||
|
||||
const remotelyPinnedConversations = (
|
||||
await Promise.all(remotelyPinnedConversationPromises)
|
||||
).filter(
|
||||
(conversation): conversation is ConversationModel =>
|
||||
conversation !== undefined
|
||||
);
|
||||
|
||||
const remotelyPinnedConversationIds = remotelyPinnedConversations.map(
|
||||
({ id }) => id
|
||||
);
|
||||
|
||||
const conversationsToUnpin = locallyPinnedConversations.filter(
|
||||
({ id }) => !remotelyPinnedConversationIds.includes(id)
|
||||
);
|
||||
|
||||
window.log.info(
|
||||
`mergeAccountRecord: unpinning ${conversationsToUnpin.length} conversations`
|
||||
);
|
||||
|
||||
window.log.info(
|
||||
`mergeAccountRecord: pinning ${conversationsToUnpin.length} conversations`
|
||||
);
|
||||
|
||||
conversationsToUnpin.forEach(conversation => {
|
||||
conversation.set({ isPinned: false, pinIndex: undefined });
|
||||
updateConversation(conversation.attributes);
|
||||
});
|
||||
|
||||
remotelyPinnedConversations.forEach((conversation, index) => {
|
||||
conversation.set({ isPinned: true, pinIndex: index });
|
||||
updateConversation(conversation.attributes);
|
||||
});
|
||||
}
|
||||
|
||||
const ourID = window.ConversationController.getOurConversationId();
|
||||
|
||||
if (!ourID) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue