Skip to content

Commit a2fb8bf

Browse files
committed
Patch to not refetch the threads #389
1 parent d8d5593 commit a2fb8bf

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/scenes/mailboxes/src/stores/google/googleActions.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,11 @@ class GoogleActions {
330330
return acc
331331
}, {})
332332

333-
const allThreads = threads.map((thread) => {
334-
return changedIndexed[thread.id] ? changedIndexed[thread.id] : thread
335-
})
336-
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, allThreads)
337-
return allThreads
333+
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads, changedIndexed)
334+
return { threads: threads, changedIndex: changedIndexed }
338335
} else {
339-
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads)
340-
return threads
336+
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads, {})
337+
return { threads: threads, changedIndex: {} }
341338
}
342339
})
343340
})

src/scenes/mailboxes/src/stores/mailbox/mailboxActions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ class MailboxActions {
175175
/**
176176
* Sets the latest unread thread list
177177
* @param id: the id of the mailbox
178-
* @param threads: the threads to set
178+
* @param threadList: the list of threads as an array
179+
* @param fetchedThreads: the full threads that have been fetched sent as an object keyed by id
179180
*/
180-
setGoogleLatestUnreadThreads (id, threads) {
181-
return this.update(id, 'googleUnreadMessageInfo_v2.latestUnreadThreads', threads)
181+
setGoogleLatestUnreadThreads (id, threadList, fetchedThreads) {
182+
return { id: id, threadList: threadList, fetchedThreads: fetchedThreads }
182183
}
183184

184185
/**

src/scenes/mailboxes/src/stores/mailbox/mailboxStore.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class MailboxStore {
142142

143143
// Google
144144
handleUpdateGoogleConfig: actions.UPDATE_GOOGLE_CONFIG,
145+
handleSetGoogleLatestUnreadThreads: actions.SET_GOOGLE_LATEST_UNREAD_THREADS,
145146

146147
// Active & Ordering
147148
handleChangeActive: actions.CHANGE_ACTIVE,
@@ -325,6 +326,37 @@ class MailboxStore {
325326
this.mailboxes.set(id, new Mailbox(id, data))
326327
}
327328

329+
/**
330+
* Updates the google unread threads
331+
* @param id: the id of the mailbox
332+
* @param threadList: the complete thread list as an array
333+
* @param fetchedThreads: the threads that were fetched in an object by id
334+
*/
335+
handleSetGoogleLatestUnreadThreads ({ id, threadList, fetchedThreads }) {
336+
const prevThreads = this.mailboxes.get(id).google.latestUnreadThreads.reduce((acc, thread) => {
337+
acc[thread.id] = thread
338+
return acc
339+
}, {})
340+
341+
// Merge changes
342+
const nextThreads = threadList.map((threadHead) => {
343+
if (fetchedThreads[threadHead.id]) {
344+
return fetchedThreads[threadHead.id]
345+
} else if (prevThreads[threadHead.id]) {
346+
return prevThreads[threadHead.id]
347+
} else {
348+
return undefined
349+
}
350+
}).filter((thread) => !!thread)
351+
352+
// Write it
353+
const data = this.mailboxes.get(id).cloneData()
354+
data.googleUnreadMessageInfo_v2 = data.googleUnreadMessageInfo_v2 || {}
355+
data.googleUnreadMessageInfo_v2.latestUnreadThreads = nextThreads
356+
persistence.mailbox.setJSONItem(id, data)
357+
this.mailboxes.set(id, new Mailbox(id, data))
358+
}
359+
328360
/* **************************************************************************/
329361
// Handlers : Active & Ordering
330362
/* **************************************************************************/

0 commit comments

Comments
 (0)