Display the latest scrobble under a user's name

This commit is contained in:
NEETzsche 2023-11-09 15:03:21 -07:00
commit 2c9930bd5b
8 changed files with 73 additions and 3 deletions

View file

@ -40,6 +40,7 @@ export const defaultState = {
padEmoji: true,
hideAttachments: false,
hideAttachmentsInConv: false,
hideScrobbles: false,
maxThumbnails: 16,
hideNsfw: true,
preloadImage: true,

View file

@ -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