Merge branch 'ss-read' into 'develop'

Server-side read marking

See merge request pleroma/pleroma-fe!386
This commit is contained in:
lambda 2018-12-03 14:47:27 +00:00
commit ea28aa62f0
4 changed files with 26 additions and 10 deletions

View file

@ -52,7 +52,7 @@ const Notifications = {
}, },
methods: { methods: {
markAsSeen () { markAsSeen () {
this.$store.commit('markNotificationsAsSeen', this.visibleNotifications) this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications)
}, },
fetchOlderNotifications () { fetchOlderNotifications () {
const store = this.$store const store = this.$store

View file

@ -47,7 +47,6 @@ const persistedStateOptions = {
paths: [ paths: [
'config', 'config',
'users.lastLoginName', 'users.lastLoginName',
'statuses.notifications.maxSavedId',
'oauth' 'oauth'
] ]
} }

View file

@ -1,5 +1,4 @@
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash' import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
import { set } from 'vue'
import apiService from '../services/api/api.service.js' import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js' // import parse from '../services/status_parser/status_parser.js'
@ -27,7 +26,6 @@ export const defaultState = {
notifications: { notifications: {
desktopNotificationSilence: true, desktopNotificationSilence: true,
maxId: 0, maxId: 0,
maxSavedId: 0,
minId: Number.POSITIVE_INFINITY, minId: Number.POSITIVE_INFINITY,
data: [], data: [],
error: false, error: false,
@ -305,7 +303,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
state.notifications.maxId = Math.max(notification.id, state.notifications.maxId) state.notifications.maxId = Math.max(notification.id, state.notifications.maxId)
state.notifications.minId = Math.min(notification.id, state.notifications.minId) state.notifications.minId = Math.min(notification.id, state.notifications.minId)
const fresh = !older && !notification.is_seen && notification.id > state.notifications.maxSavedId const fresh = !notification.is_seen
const status = notification.ntype === 'like' const status = notification.ntype === 'like'
? find(allStatuses, { id: action.in_reply_to_status_id }) ? find(allStatuses, { id: action.in_reply_to_status_id })
: action : action
@ -314,7 +312,6 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
type: notification.ntype, type: notification.ntype,
status, status,
action, action,
// Always assume older notifications as seen
seen: !fresh seen: !fresh
} }
@ -412,9 +409,8 @@ export const mutations = {
addFollowers (state, { followers }) { addFollowers (state, { followers }) {
state.timelines['user'].followers = followers state.timelines['user'].followers = followers
}, },
markNotificationsAsSeen (state, notifications) { markNotificationsAsSeen (state) {
set(state.notifications, 'maxSavedId', state.notifications.maxId) each(state.notifications.data, (notification) => {
each(notifications, (notification) => {
notification.seen = true notification.seen = true
}) })
}, },
@ -492,6 +488,13 @@ const statuses = {
}, },
queueFlush ({ rootState, commit }, { timeline, id }) { queueFlush ({ rootState, commit }, { timeline, id }) {
commit('queueFlush', { timeline, id }) commit('queueFlush', { timeline, id })
},
markNotificationsAsSeen ({ rootState, commit }) {
commit('markNotificationsAsSeen')
apiService.markNotificationsAsSeen({
id: rootState.statuses.notifications.maxId,
credentials: rootState.users.currentUser.credentials
})
} }
}, },
mutations mutations

View file

@ -29,6 +29,7 @@ const PROFILE_UPDATE_URL = '/api/account/update_profile.json'
const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json'
const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json'
const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json' const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json'
const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json'
const BLOCKING_URL = '/api/blocks/create.json' const BLOCKING_URL = '/api/blocks/create.json'
const UNBLOCKING_URL = '/api/blocks/destroy.json' const UNBLOCKING_URL = '/api/blocks/destroy.json'
const USER_URL = '/api/users/show.json' const USER_URL = '/api/users/show.json'
@ -460,6 +461,18 @@ const suggestions = ({credentials}) => {
}).then((data) => data.json()) }).then((data) => data.json())
} }
const markNotificationsAsSeen = ({id, credentials}) => {
const body = new FormData()
body.append('latest_id', id)
return fetch(QVITTER_USER_NOTIFICATIONS_READ_URL, {
body,
headers: authHeaders(credentials),
method: 'POST'
}).then((data) => data.json())
}
const apiService = { const apiService = {
verifyCredentials, verifyCredentials,
fetchTimeline, fetchTimeline,
@ -494,7 +507,8 @@ const apiService = {
fetchFollowRequests, fetchFollowRequests,
approveUser, approveUser,
denyUser, denyUser,
suggestions suggestions,
markNotificationsAsSeen
} }
export default apiService export default apiService