Only re-save and re-sort conversation if draft has changed

This commit is contained in:
Scott Nonnenberg 2019-09-13 17:10:00 -07:00
parent bd13a2087f
commit 92235678b5

View file

@ -764,17 +764,23 @@
conversationUnloaded(this.model.id); conversationUnloaded(this.model.id);
} }
if (this.model.get('draftChanged')) {
if (this.model.hasDraft()) { if (this.model.hasDraft()) {
this.model.set({ this.model.set({
draftChanged: false,
draftTimestamp: Date.now(), draftTimestamp: Date.now(),
timestamp: Date.now(), timestamp: Date.now(),
}); });
} else {
this.model.updateLastMessage(); this.model.set({
draftChanged: false,
draftTimestamp: null,
});
}
// We don't wait here; we need to take down the view // We don't wait here; we need to take down the view
this.saveModel(); this.saveModel();
} else {
this.model.updateLastMessage(); this.model.updateLastMessage();
} }
@ -955,6 +961,7 @@
const draftAttachments = this.model.get('draftAttachments') || []; const draftAttachments = this.model.get('draftAttachments') || [];
this.model.set({ this.model.set({
draftAttachments: [...draftAttachments, onDisk], draftAttachments: [...draftAttachments, onDisk],
draftChanged: true,
}); });
await this.saveModel(); await this.saveModel();
@ -969,6 +976,7 @@
draftAttachments, draftAttachments,
item => item.path === attachment.path item => item.path === attachment.path
), ),
draftChanged: true,
}); });
this.updateAttachmentsView(); this.updateAttachmentsView();
@ -983,6 +991,7 @@
const draftAttachments = this.model.get('draftAttachments') || []; const draftAttachments = this.model.get('draftAttachments') || [];
this.model.set({ this.model.set({
draftAttachments: [], draftAttachments: [],
draftChanged: true,
}); });
this.updateAttachmentsView(); this.updateAttachmentsView();
@ -2262,6 +2271,7 @@
if (existing !== messageId) { if (existing !== messageId) {
this.model.set({ this.model.set({
quotedMessageId: messageId, quotedMessageId: messageId,
draftChanged: true,
}); });
await this.saveModel(); await this.saveModel();
@ -2427,16 +2437,20 @@
if (this.model.get('draft') && (!messageText || trimmed.length === 0)) { if (this.model.get('draft') && (!messageText || trimmed.length === 0)) {
this.model.set({ this.model.set({
draft: null, draft: null,
draftChanged: true,
}); });
await this.saveModel(); await this.saveModel();
return; return;
} }
if (messageText !== this.model.get('draft')) {
this.model.set({ this.model.set({
draft: messageText, draft: messageText,
draftChanged: true,
}); });
await this.saveModel(); await this.saveModel();
}
}, },
maybeGrabLinkPreview(message, caretLocation) { maybeGrabLinkPreview(message, caretLocation) {