Merge branch 'notifications-thru-sw' into shigusegubu-vue3

This commit is contained in:
Henry Jameson 2023-11-13 17:29:43 +02:00
commit e9bc8f020a
32 changed files with 1076 additions and 68 deletions

View file

@ -40,6 +40,7 @@ export const defaultState = {
padEmoji: true,
hideAttachments: false,
hideAttachmentsInConv: false,
hideScrobbles: false,
maxThumbnails: 16,
hideNsfw: true,
preloadImage: true,
@ -65,6 +66,9 @@ export const defaultState = {
chatMention: true,
polls: true
},
notificationSettings: {
nativeNotifications: ['follows', 'mentions', 'followRequest', 'reports', 'chatMention', 'polls']
},
webPushNotifications: false,
muteWords: [],
highlight: {},

View file

@ -17,6 +17,10 @@ import {
isValidNotification,
maybeShowNotification
} from '../services/notification_utils/notification_utils.js'
import {
closeDesktopNotification,
closeAllDesktopNotifications
} from '../services/desktop_notification_utils/desktop_notification_utils.js'
import apiService from '../services/api/api.service.js'
const emptyTl = (userId = 0) => ({
@ -47,6 +51,7 @@ const emptyNotifications = () => ({
export const defaultState = () => ({
allStatuses: [],
scrobblesNextFetch: {},
allStatusesObject: {},
conversationsObject: {},
maxId: 0,
@ -120,8 +125,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
@ -709,6 +730,8 @@ const statuses = {
apiService.markNotificationsAsSeen({
id: rootState.statuses.notifications.maxId,
credentials: rootState.users.currentUser.credentials
}).then(() => {
closeAllDesktopNotifications(rootState)
})
},
markSingleNotificationAsSeen ({ rootState, commit }, { id }) {
@ -717,6 +740,8 @@ const statuses = {
single: true,
id,
credentials: rootState.users.currentUser.credentials
}).then(() => {
closeDesktopNotification(rootState, id)
})
},
dismissNotificationLocal ({ rootState, commit }, { id }) {