Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Commit

Permalink
Patch to not refetch the threads #389
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas101 committed Oct 29, 2016
1 parent d8d5593 commit a2fb8bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/scenes/mailboxes/src/stores/google/googleActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,11 @@ class GoogleActions {
return acc
}, {})

const allThreads = threads.map((thread) => {
return changedIndexed[thread.id] ? changedIndexed[thread.id] : thread
})
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, allThreads)
return allThreads
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads, changedIndexed)
return { threads: threads, changedIndex: changedIndexed }
} else {
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads)
return threads
mailboxActions.setGoogleLatestUnreadThreads(mailboxId, threads, {})
return { threads: threads, changedIndex: {} }
}
})
})
Expand Down
7 changes: 4 additions & 3 deletions src/scenes/mailboxes/src/stores/mailbox/mailboxActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ class MailboxActions {
/**
* Sets the latest unread thread list
* @param id: the id of the mailbox
* @param threads: the threads to set
* @param threadList: the list of threads as an array
* @param fetchedThreads: the full threads that have been fetched sent as an object keyed by id
*/
setGoogleLatestUnreadThreads (id, threads) {
return this.update(id, 'googleUnreadMessageInfo_v2.latestUnreadThreads', threads)
setGoogleLatestUnreadThreads (id, threadList, fetchedThreads) {
return { id: id, threadList: threadList, fetchedThreads: fetchedThreads }
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/scenes/mailboxes/src/stores/mailbox/mailboxStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class MailboxStore {

// Google
handleUpdateGoogleConfig: actions.UPDATE_GOOGLE_CONFIG,
handleSetGoogleLatestUnreadThreads: actions.SET_GOOGLE_LATEST_UNREAD_THREADS,

// Active & Ordering
handleChangeActive: actions.CHANGE_ACTIVE,
Expand Down Expand Up @@ -325,6 +326,37 @@ class MailboxStore {
this.mailboxes.set(id, new Mailbox(id, data))
}

/**
* Updates the google unread threads
* @param id: the id of the mailbox
* @param threadList: the complete thread list as an array
* @param fetchedThreads: the threads that were fetched in an object by id
*/
handleSetGoogleLatestUnreadThreads ({ id, threadList, fetchedThreads }) {
const prevThreads = this.mailboxes.get(id).google.latestUnreadThreads.reduce((acc, thread) => {
acc[thread.id] = thread
return acc
}, {})

// Merge changes
const nextThreads = threadList.map((threadHead) => {
if (fetchedThreads[threadHead.id]) {
return fetchedThreads[threadHead.id]
} else if (prevThreads[threadHead.id]) {
return prevThreads[threadHead.id]
} else {
return undefined
}
}).filter((thread) => !!thread)

// Write it
const data = this.mailboxes.get(id).cloneData()
data.googleUnreadMessageInfo_v2 = data.googleUnreadMessageInfo_v2 || {}
data.googleUnreadMessageInfo_v2.latestUnreadThreads = nextThreads
persistence.mailbox.setJSONItem(id, data)
this.mailboxes.set(id, new Mailbox(id, data))
}

/* **************************************************************************/
// Handlers : Active & Ordering
/* **************************************************************************/
Expand Down

0 comments on commit a2fb8bf

Please sign in to comment.