diff --git a/ts/data/data.ts b/ts/data/data.ts index 0234c68a5..48be92f28 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -566,24 +566,9 @@ export async function getConversationById( } export async function updateConversation( - id: string, data: ConversationType ): Promise { - const existing = await getConversationById(id); - if (!existing) { - throw new Error(`Conversation ${id} does not exist!`); - } - - const merged = _.merge({}, existing.attributes, data); - - // Merging is a really bad idea and not what we want here, e.g. - // it will take a union of old and new members and that's not - // what we want for member deletion, so: - merged.members = data.members; - - // Don't save the online status of the object - const cleaned = _.omit(merged, 'isOnline'); - await channels.updateConversation(cleaned); + await channels.updateConversation(data); } export async function removeConversation(id: string): Promise { diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index a4f6fb45e..c4393348a 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -135,6 +135,7 @@ export class ConversationModel extends Backbone.Model { public updateLastMessage: () => any; public messageCollection: MessageCollection; public throttledBumpTyping: any; + public throttledNotify: any; public initialPromise: any; private typingRefreshTimer?: NodeJS.Timeout | null; @@ -163,6 +164,7 @@ export class ConversationModel extends Backbone.Model { this.bouncyUpdateLastMessage.bind(this), 1000 ); + this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); // Listening for out-of-band data updates this.on('expired', this.onExpired); @@ -982,7 +984,7 @@ export class ConversationModel extends Backbone.Model { } public async commit() { - await updateConversation(this.id, this.attributes); + await updateConversation(this.attributes); this.trigger('change', this); } @@ -1587,7 +1589,7 @@ export class ConversationModel extends Backbone.Model { }); } - public async notify(message: any) { + public async notify(message: MessageModel) { if (!message.isIncoming()) { return; } @@ -1620,6 +1622,7 @@ export class ConversationModel extends Backbone.Model { title: convo.getTitle(), }); } + public async notifyTyping({ isTyping, sender }: any) { // We don't do anything with typing messages from our other devices if (UserUtils.isUsFromCache(sender)) { diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index d9505f115..900b600ab 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -525,7 +525,9 @@ export async function handleMessageJob( ourNumber ); } + const id = await message.commit(); + message.set({ id }); window.Whisper.events.trigger('messageAdded', { conversationKey: conversation.id, @@ -575,7 +577,7 @@ export async function handleMessageJob( } if (message.get('unread')) { - await conversation.notify(message); + await conversation.throttledNotify(message); } if (confirm) { @@ -589,6 +591,7 @@ export async function handleMessageJob( 'error:', errorForLog ); + throw error; } } diff --git a/ts/session/types/OpenGroup.ts b/ts/session/types/OpenGroup.ts index 7b51bcadd..e8b84e182 100644 --- a/ts/session/types/OpenGroup.ts +++ b/ts/session/types/OpenGroup.ts @@ -122,7 +122,6 @@ export class OpenGroup { // Return OpenGroup if we're already connected conversation = OpenGroup.getConversation(prefixedServer); - console.warn(`Convo for ${prefixedServer}: ${conversation}`); if (conversation) { conversationId = conversation?.cid; @@ -132,11 +131,6 @@ export class OpenGroup { channel: 1, conversationId, }); - } else { - console.warn( - 'NO conversationId = conversation?.cid', - conversation?.cid - ); } }