Early preparations for PNP Contact Merging

This commit is contained in:
Scott Nonnenberg 2022-08-09 14:39:00 -07:00 committed by GitHub
parent 2f5dd73e58
commit faf6c41332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1572 additions and 447 deletions

View file

@ -103,12 +103,10 @@ export class MessageRequests extends Collection<MessageRequestModel> {
conversation = window.ConversationController.get(groupId);
}
if (!conversation && (threadE164 || threadUuid)) {
conversation = window.ConversationController.get(
window.ConversationController.ensureContactIds({
e164: threadE164,
uuid: threadUuid,
})
);
conversation = window.ConversationController.lookupOrCreate({
e164: threadE164,
uuid: threadUuid,
});
}
if (!conversation) {

View file

@ -44,11 +44,11 @@ export class Reactions extends Collection<ReactionModel> {
const senderId = getContactId(message.attributes);
const sentAt = message.get('sent_at');
const reactionsBySource = this.filter(re => {
const targetSenderId = window.ConversationController.ensureContactIds({
const targetSender = window.ConversationController.lookupOrCreate({
uuid: re.get('targetAuthorUuid'),
});
const targetTimestamp = re.get('targetTimestamp');
return targetSenderId === senderId && targetTimestamp === sentAt;
return targetSender?.id === senderId && targetTimestamp === sentAt;
});
if (reactionsBySource.length > 0) {
@ -87,13 +87,14 @@ export class Reactions extends Collection<ReactionModel> {
try {
// The conversation the target message was in; we have to find it in the database
// to to figure that out.
const targetConversationId =
window.ConversationController.ensureContactIds({
const targetAuthorConversation =
window.ConversationController.lookupOrCreate({
uuid: reaction.get('targetAuthorUuid'),
});
const targetConversationId = targetAuthorConversation?.id;
if (!targetConversationId) {
throw new Error(
'onReaction: No conversationId returned from ensureContactIds!'
'onReaction: No conversationId returned from lookupOrCreate!'
);
}

View file

@ -58,13 +58,13 @@ export class ReadSyncs extends Collection {
}
forMessage(message: MessageModel): ReadSyncModel | null {
const senderId = window.ConversationController.ensureContactIds({
const sender = window.ConversationController.lookupOrCreate({
e164: message.get('source'),
uuid: message.get('sourceUuid'),
});
const sync = this.find(item => {
return (
item.get('senderId') === senderId &&
item.get('senderId') === sender?.id &&
item.get('timestamp') === message.get('sent_at')
);
});
@ -84,12 +84,12 @@ export class ReadSyncs extends Collection {
);
const found = messages.find(item => {
const senderId = window.ConversationController.ensureContactIds({
const sender = window.ConversationController.lookupOrCreate({
e164: item.source,
uuid: item.sourceUuid,
});
return isIncoming(item) && senderId === sync.get('senderId');
return isIncoming(item) && sender?.id === sync.get('senderId');
});
if (!found) {

View file

@ -35,13 +35,13 @@ export class ViewSyncs extends Collection {
}
forMessage(message: MessageModel): Array<ViewSyncModel> {
const senderId = window.ConversationController.ensureContactIds({
const sender = window.ConversationController.lookupOrCreate({
e164: message.get('source'),
uuid: message.get('sourceUuid'),
});
const syncs = this.filter(item => {
return (
item.get('senderId') === senderId &&
item.get('senderId') === sender?.id &&
item.get('timestamp') === message.get('sent_at')
);
});
@ -63,12 +63,12 @@ export class ViewSyncs extends Collection {
);
const found = messages.find(item => {
const senderId = window.ConversationController.ensureContactIds({
const sender = window.ConversationController.lookupOrCreate({
e164: item.source,
uuid: item.sourceUuid,
});
return senderId === sync.get('senderId');
return sender?.id === sync.get('senderId');
});
if (!found) {