speed up loading of messages by not notify on every new message

pull/1528/head
Audric Ackermann 5 years ago
parent f6e3b354d0
commit 05e9c936ff

@ -566,24 +566,9 @@ export async function getConversationById(
} }
export async function updateConversation( export async function updateConversation(
id: string,
data: ConversationType data: ConversationType
): Promise<void> { ): Promise<void> {
const existing = await getConversationById(id); await channels.updateConversation(data);
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);
} }
export async function removeConversation(id: string): Promise<void> { export async function removeConversation(id: string): Promise<void> {

@ -135,6 +135,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public updateLastMessage: () => any; public updateLastMessage: () => any;
public messageCollection: MessageCollection; public messageCollection: MessageCollection;
public throttledBumpTyping: any; public throttledBumpTyping: any;
public throttledNotify: any;
public initialPromise: any; public initialPromise: any;
private typingRefreshTimer?: NodeJS.Timeout | null; private typingRefreshTimer?: NodeJS.Timeout | null;
@ -163,6 +164,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
this.bouncyUpdateLastMessage.bind(this), this.bouncyUpdateLastMessage.bind(this),
1000 1000
); );
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 });
// Listening for out-of-band data updates // Listening for out-of-band data updates
this.on('expired', this.onExpired); this.on('expired', this.onExpired);
@ -982,7 +984,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
public async commit() { public async commit() {
await updateConversation(this.id, this.attributes); await updateConversation(this.attributes);
this.trigger('change', this); this.trigger('change', this);
} }
@ -1587,7 +1589,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}); });
} }
public async notify(message: any) { public async notify(message: MessageModel) {
if (!message.isIncoming()) { if (!message.isIncoming()) {
return; return;
} }
@ -1620,6 +1622,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
title: convo.getTitle(), title: convo.getTitle(),
}); });
} }
public async notifyTyping({ isTyping, sender }: any) { public async notifyTyping({ isTyping, sender }: any) {
// We don't do anything with typing messages from our other devices // We don't do anything with typing messages from our other devices
if (UserUtils.isUsFromCache(sender)) { if (UserUtils.isUsFromCache(sender)) {

@ -525,7 +525,9 @@ export async function handleMessageJob(
ourNumber ourNumber
); );
} }
const id = await message.commit(); const id = await message.commit();
message.set({ id }); message.set({ id });
window.Whisper.events.trigger('messageAdded', { window.Whisper.events.trigger('messageAdded', {
conversationKey: conversation.id, conversationKey: conversation.id,
@ -575,7 +577,7 @@ export async function handleMessageJob(
} }
if (message.get('unread')) { if (message.get('unread')) {
await conversation.notify(message); await conversation.throttledNotify(message);
} }
if (confirm) { if (confirm) {
@ -589,6 +591,7 @@ export async function handleMessageJob(
'error:', 'error:',
errorForLog errorForLog
); );
throw error; throw error;
} }
} }

@ -122,7 +122,6 @@ export class OpenGroup {
// Return OpenGroup if we're already connected // Return OpenGroup if we're already connected
conversation = OpenGroup.getConversation(prefixedServer); conversation = OpenGroup.getConversation(prefixedServer);
console.warn(`Convo for ${prefixedServer}: ${conversation}`);
if (conversation) { if (conversation) {
conversationId = conversation?.cid; conversationId = conversation?.cid;
@ -132,11 +131,6 @@ export class OpenGroup {
channel: 1, channel: 1,
conversationId, conversationId,
}); });
} else {
console.warn(
'NO conversationId = conversation?.cid',
conversation?.cid
);
} }
} }

Loading…
Cancel
Save