diff options
| author | Henry Jameson <me@hjkos.com> | 2023-11-13 17:26:53 +0200 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2023-11-13 17:26:53 +0200 |
| commit | c059f4a7ee16c0128c348c43c9d468e7cfdb5ef7 (patch) | |
| tree | 12e816bd639f1ef6fa531c0df602e115b2a99ca7 /src/modules/statuses.js | |
| parent | e0b8ad9f141f418ab3d8ebc7a9e68bcb755c820a (diff) | |
| parent | 18c0cf1845a95db2d0e894d2455cdd4dc545aaf7 (diff) | |
Merge remote-tracking branch 'origin/develop' into notifications-thru-sw
Diffstat (limited to 'src/modules/statuses.js')
| -rw-r--r-- | src/modules/statuses.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 186bba3c..9b4cd175 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -47,6 +47,7 @@ const emptyNotifications = () => ({ export const defaultState = () => ({ allStatuses: [], + scrobblesNextFetch: {}, allStatusesObject: {}, conversationsObject: {}, maxId: 0, @@ -120,8 +121,24 @@ const sortTimeline = (timeline) => { return timeline } +const getLatestScrobble = (state, user) => { + if (state.scrobblesNextFetch[user.id] && state.scrobblesNextFetch[user.id] > Date.now()) { + return + } + + state.scrobblesNextFetch[user.id] = Date.now() + 24 * 60 * 60 * 1000 + apiService.fetchScrobbles({ accountId: user.id }).then((scrobbles) => { + if (scrobbles.length > 0) { + user.latestScrobble = scrobbles[0] + + state.scrobblesNextFetch[user.id] = Date.now() + 60 * 1000 + } + }) +} + // Add status to the global storages (arrays and objects maintaining statuses) except timelines const addStatusToGlobalStorage = (state, data) => { + getLatestScrobble(state, data.user) const result = mergeOrAdd(state.allStatuses, state.allStatusesObject, data) if (result.new) { // Add to conversation |
