|
@@ -12,11 +12,6 @@ import {
|
|
isArray,
|
|
isArray,
|
|
omitBy
|
|
omitBy
|
|
} from 'lodash'
|
|
} from 'lodash'
|
|
-import {
|
|
|
|
- isStatusNotification,
|
|
|
|
- isValidNotification,
|
|
|
|
- maybeShowNotification
|
|
|
|
-} from '../services/notification_utils/notification_utils.js'
|
|
|
|
import apiService from '../services/api/api.service.js'
|
|
import apiService from '../services/api/api.service.js'
|
|
|
|
|
|
const emptyTl = (userId = 0) => ({
|
|
const emptyTl = (userId = 0) => ({
|
|
@@ -36,22 +31,12 @@ const emptyTl = (userId = 0) => ({
|
|
flushMarker: 0
|
|
flushMarker: 0
|
|
})
|
|
})
|
|
|
|
|
|
-const emptyNotifications = () => ({
|
|
|
|
- desktopNotificationSilence: true,
|
|
|
|
- maxId: 0,
|
|
|
|
- minId: Number.POSITIVE_INFINITY,
|
|
|
|
- data: [],
|
|
|
|
- idStore: {},
|
|
|
|
- loading: false
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
export const defaultState = () => ({
|
|
export const defaultState = () => ({
|
|
allStatuses: [],
|
|
allStatuses: [],
|
|
scrobblesNextFetch: {},
|
|
scrobblesNextFetch: {},
|
|
allStatusesObject: {},
|
|
allStatusesObject: {},
|
|
conversationsObject: {},
|
|
conversationsObject: {},
|
|
maxId: 0,
|
|
maxId: 0,
|
|
- notifications: emptyNotifications(),
|
|
|
|
favorites: new Set(),
|
|
favorites: new Set(),
|
|
timelines: {
|
|
timelines: {
|
|
mentions: emptyTl(),
|
|
mentions: emptyTl(),
|
|
@@ -154,22 +139,6 @@ const addStatusToGlobalStorage = (state, data) => {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-// Remove status from the global storages (arrays and objects maintaining statuses) except timelines
|
|
|
|
-const removeStatusFromGlobalStorage = (state, status) => {
|
|
|
|
- remove(state.allStatuses, { id: status.id })
|
|
|
|
-
|
|
|
|
- // TODO: Need to remove from allStatusesObject?
|
|
|
|
-
|
|
|
|
- // Remove possible notification
|
|
|
|
- remove(state.notifications.data, ({ action: { id } }) => id === status.id)
|
|
|
|
-
|
|
|
|
- // Remove from conversation
|
|
|
|
- const conversationId = status.statusnet_conversation_id
|
|
|
|
- if (state.conversationsObject[conversationId]) {
|
|
|
|
- remove(state.conversationsObject[conversationId], { id: status.id })
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false, userId, pagination = {} }) => {
|
|
const addNewStatuses = (state, { statuses, showImmediately = false, timeline, user = {}, noIdUpdate = false, userId, pagination = {} }) => {
|
|
// Sanity check
|
|
// Sanity check
|
|
if (!isArray(statuses)) {
|
|
if (!isArray(statuses)) {
|
|
@@ -303,20 +272,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|
favoriteStatus(favorite)
|
|
favoriteStatus(favorite)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- deletion: (deletion) => {
|
|
|
|
- const uri = deletion.uri
|
|
|
|
- const status = find(allStatuses, { uri })
|
|
|
|
- if (!status) {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- removeStatusFromGlobalStorage(state, status)
|
|
|
|
-
|
|
|
|
- if (timeline) {
|
|
|
|
- remove(timelineObject.statuses, { uri })
|
|
|
|
- remove(timelineObject.visibleStatuses, { uri })
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
follow: (follow) => {
|
|
follow: (follow) => {
|
|
// NOOP, it is known status but we don't do anything about it for now
|
|
// NOOP, it is known status but we don't do anything about it for now
|
|
},
|
|
},
|
|
@@ -338,52 +293,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const updateNotificationsMinMaxId = (state, notification) => {
|
|
|
|
- state.notifications.maxId = notification.id > state.notifications.maxId
|
|
|
|
- ? notification.id
|
|
|
|
- : state.notifications.maxId
|
|
|
|
- state.notifications.minId = notification.id < state.notifications.minId
|
|
|
|
- ? notification.id
|
|
|
|
- : state.notifications.minId
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters, newNotificationSideEffects }) => {
|
|
|
|
- each(notifications, (notification) => {
|
|
|
|
- // If invalid notification, update ids but don't add it to store
|
|
|
|
- if (!isValidNotification(notification)) {
|
|
|
|
- console.error('Invalid notification:', notification)
|
|
|
|
- updateNotificationsMinMaxId(state, notification)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (isStatusNotification(notification.type)) {
|
|
|
|
- notification.action = addStatusToGlobalStorage(state, notification.action).item
|
|
|
|
- notification.status = notification.status && addStatusToGlobalStorage(state, notification.status).item
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (notification.type === 'pleroma:report') {
|
|
|
|
- dispatch('addReport', notification.report)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (notification.type === 'pleroma:emoji_reaction') {
|
|
|
|
- dispatch('fetchEmojiReactionsBy', notification.status.id)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Only add a new notification if we don't have one for the same action
|
|
|
|
- // eslint-disable-next-line no-prototype-builtins
|
|
|
|
- if (!state.notifications.idStore.hasOwnProperty(notification.id)) {
|
|
|
|
- updateNotificationsMinMaxId(state, notification)
|
|
|
|
-
|
|
|
|
- state.notifications.data.push(notification)
|
|
|
|
- state.notifications.idStore[notification.id] = notification
|
|
|
|
-
|
|
|
|
- newNotificationSideEffects(notification)
|
|
|
|
- } else if (notification.seen) {
|
|
|
|
- state.notifications.idStore[notification.id].seen = true
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
const removeStatus = (state, { timeline, userId }) => {
|
|
const removeStatus = (state, { timeline, userId }) => {
|
|
const timelineObject = state.timelines[timeline]
|
|
const timelineObject = state.timelines[timeline]
|
|
if (userId) {
|
|
if (userId) {
|
|
@@ -396,7 +305,6 @@ const removeStatus = (state, { timeline, userId }) => {
|
|
|
|
|
|
export const mutations = {
|
|
export const mutations = {
|
|
addNewStatuses,
|
|
addNewStatuses,
|
|
- addNewNotifications,
|
|
|
|
removeStatus,
|
|
removeStatus,
|
|
showNewStatuses (state, { timeline }) {
|
|
showNewStatuses (state, { timeline }) {
|
|
const oldTimeline = (state.timelines[timeline])
|
|
const oldTimeline = (state.timelines[timeline])
|
|
@@ -418,9 +326,6 @@ export const mutations = {
|
|
const userId = excludeUserId ? state.timelines[timeline].userId : undefined
|
|
const userId = excludeUserId ? state.timelines[timeline].userId : undefined
|
|
state.timelines[timeline] = emptyTl(userId)
|
|
state.timelines[timeline] = emptyTl(userId)
|
|
},
|
|
},
|
|
- clearNotifications (state) {
|
|
|
|
- state.notifications = emptyNotifications()
|
|
|
|
- },
|
|
|
|
setFavorited (state, { status, value }) {
|
|
setFavorited (state, { status, value }) {
|
|
const newStatus = state.allStatusesObject[status.id]
|
|
const newStatus = state.allStatusesObject[status.id]
|
|
|
|
|
|
@@ -503,31 +408,6 @@ export const mutations = {
|
|
const newStatus = state.allStatusesObject[id]
|
|
const newStatus = state.allStatusesObject[id]
|
|
newStatus.nsfw = nsfw
|
|
newStatus.nsfw = nsfw
|
|
},
|
|
},
|
|
- setNotificationsLoading (state, { value }) {
|
|
|
|
- state.notifications.loading = value
|
|
|
|
- },
|
|
|
|
- setNotificationsSilence (state, { value }) {
|
|
|
|
- state.notifications.desktopNotificationSilence = value
|
|
|
|
- },
|
|
|
|
- markNotificationsAsSeen (state) {
|
|
|
|
- each(state.notifications.data, (notification) => {
|
|
|
|
- notification.seen = true
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- markSingleNotificationAsSeen (state, { id }) {
|
|
|
|
- const notification = find(state.notifications.data, n => n.id === id)
|
|
|
|
- if (notification) notification.seen = true
|
|
|
|
- },
|
|
|
|
- dismissNotification (state, { id }) {
|
|
|
|
- state.notifications.data = state.notifications.data.filter(n => n.id !== id)
|
|
|
|
- },
|
|
|
|
- dismissNotifications (state, { finder }) {
|
|
|
|
- state.notifications.data = state.notifications.data.filter(n => finder)
|
|
|
|
- },
|
|
|
|
- updateNotification (state, { id, updater }) {
|
|
|
|
- const notification = find(state.notifications.data, n => n.id === id)
|
|
|
|
- notification && updater(notification)
|
|
|
|
- },
|
|
|
|
queueFlush (state, { timeline, id }) {
|
|
queueFlush (state, { timeline, id }) {
|
|
state.timelines[timeline].flushMarker = id
|
|
state.timelines[timeline].flushMarker = id
|
|
},
|
|
},
|
|
@@ -609,23 +489,9 @@ export const mutations = {
|
|
const statuses = {
|
|
const statuses = {
|
|
state: defaultState(),
|
|
state: defaultState(),
|
|
actions: {
|
|
actions: {
|
|
- addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId, pagination }) {
|
|
|
|
|
|
+ addNewStatuses ({ rootState, commit, dispatch, state }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId, pagination }) {
|
|
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId, pagination })
|
|
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId, pagination })
|
|
},
|
|
},
|
|
- addNewNotifications (store, { notifications, older }) {
|
|
|
|
- const { commit, dispatch, rootGetters } = store
|
|
|
|
-
|
|
|
|
- const newNotificationSideEffects = (notification) => {
|
|
|
|
- maybeShowNotification(store, notification)
|
|
|
|
- }
|
|
|
|
- commit('addNewNotifications', { dispatch, notifications, older, rootGetters, newNotificationSideEffects })
|
|
|
|
- },
|
|
|
|
- setNotificationsLoading ({ rootState, commit }, { value }) {
|
|
|
|
- commit('setNotificationsLoading', { value })
|
|
|
|
- },
|
|
|
|
- setNotificationsSilence ({ rootState, commit }, { value }) {
|
|
|
|
- commit('setNotificationsSilence', { value })
|
|
|
|
- },
|
|
|
|
fetchStatus ({ rootState, dispatch }, id) {
|
|
fetchStatus ({ rootState, dispatch }, id) {
|
|
return rootState.api.backendInteractor.fetchStatus({ id })
|
|
return rootState.api.backendInteractor.fetchStatus({ id })
|
|
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
|
|
.then((status) => dispatch('addNewStatuses', { statuses: [status] }))
|
|
@@ -721,31 +587,6 @@ const statuses = {
|
|
queueFlushAll ({ rootState, commit }) {
|
|
queueFlushAll ({ rootState, commit }) {
|
|
commit('queueFlushAll')
|
|
commit('queueFlushAll')
|
|
},
|
|
},
|
|
- markNotificationsAsSeen ({ rootState, commit }) {
|
|
|
|
- commit('markNotificationsAsSeen')
|
|
|
|
- apiService.markNotificationsAsSeen({
|
|
|
|
- id: rootState.statuses.notifications.maxId,
|
|
|
|
- credentials: rootState.users.currentUser.credentials
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- markSingleNotificationAsSeen ({ rootState, commit }, { id }) {
|
|
|
|
- commit('markSingleNotificationAsSeen', { id })
|
|
|
|
- apiService.markNotificationsAsSeen({
|
|
|
|
- single: true,
|
|
|
|
- id,
|
|
|
|
- credentials: rootState.users.currentUser.credentials
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- dismissNotificationLocal ({ rootState, commit }, { id }) {
|
|
|
|
- commit('dismissNotification', { id })
|
|
|
|
- },
|
|
|
|
- dismissNotification ({ rootState, commit }, { id }) {
|
|
|
|
- commit('dismissNotification', { id })
|
|
|
|
- rootState.api.backendInteractor.dismissNotification({ id })
|
|
|
|
- },
|
|
|
|
- updateNotification ({ rootState, commit }, { id, updater }) {
|
|
|
|
- commit('updateNotification', { id, updater })
|
|
|
|
- },
|
|
|
|
fetchFavsAndRepeats ({ rootState, commit }, id) {
|
|
fetchFavsAndRepeats ({ rootState, commit }, id) {
|
|
Promise.all([
|
|
Promise.all([
|
|
rootState.api.backendInteractor.fetchFavoritedByUsers({ id }),
|
|
rootState.api.backendInteractor.fetchFavoritedByUsers({ id }),
|