diff options
| author | NEETzsche <neetzsche@tutanota.com> | 2023-11-09 15:03:21 -0700 |
|---|---|---|
| committer | NEETzsche <neetzsche@tutanota.com> | 2023-11-10 06:11:55 -0700 |
| commit | 2c9930bd5b5c1279e0890aeba673ad6b5ce2af18 (patch) | |
| tree | b8a99013fc921b7d760dad93b94ea9403fc67490 /src/modules | |
| parent | 954d03150f1dc097b9950cfef2fed2e4f55b6442 (diff) | |
Display the latest scrobble under a user's name
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/config.js | 1 | ||||
| -rw-r--r-- | src/modules/statuses.js | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/modules/config.js b/src/modules/config.js index dda3d221..49e9b2df 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -40,6 +40,7 @@ export const defaultState = { padEmoji: true, hideAttachments: false, hideAttachmentsInConv: false, + hideScrobbles: false, maxThumbnails: 16, hideNsfw: true, preloadImage: true, 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 |
