diff --git a/src/components/follow_request_card/follow_request_card.js b/src/components/follow_request_card/follow_request_card.js index 47c86e15..bbe569f6 100644 --- a/src/components/follow_request_card/follow_request_card.js +++ b/src/components/follow_request_card/follow_request_card.js @@ -46,7 +46,7 @@ const FollowRequestCard = { this.$store.dispatch('decrementFollowRequestsCount') const notifId = this.findFollowRequestNotificationId() - this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId }) + //this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId }) this.$store.dispatch('updateNotification', { id: notifId, updater: notification => { diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index af612ccb..5b5c60b2 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -87,7 +87,7 @@ const Notification = { doApprove () { this.$store.state.api.backendInteractor.approveUser({ id: this.user.id }) this.$store.dispatch('removeFollowRequest', this.user) - this.$store.dispatch('markSingleNotificationAsSeen', { id: this.notification.id }) + //this.$store.dispatch('markSingleNotificationAsSeen', { id: this.notification.id }) this.$store.dispatch('updateNotification', { id: this.notification.id, updater: notification => { diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 1f4de887..29a0ff41 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -704,11 +704,11 @@ const statuses = { }, markSingleNotificationAsSeen ({ rootState, commit }, { id }) { commit('markSingleNotificationAsSeen', { id }) - apiService.markNotificationsAsSeen({ + /*apiService.markNotificationsAsSeen({ single: true, id, credentials: rootState.users.currentUser.credentials - }) + })*/ }, dismissNotificationLocal ({ rootState, commit }, { id }) { commit('dismissNotification', { id }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 84316196..18ebc2e6 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -113,6 +113,7 @@ const MASTODON_TAG_URL = (name) => `/api/v1/tags/${name}` const MASTODON_FOLLOW_TAG_URL = (name) => `/api/v1/tags/${name}/follow` const MASTODON_UNFOLLOW_TAG_URL = (name) => `/api/v1/tags/${name}/unfollow` const MASTODON_FOLLOWED_TAGS_URL = '/api/v1/followed_tags' +const MASTODON_MARKERS_URL = '/api/v1/markers' const oldfetch = window.fetch @@ -715,6 +716,16 @@ const fetchTimeline = ({ const isNotifications = timeline === 'notifications' const params = [] + let markers = {} + let markerPromise = Promise.resolve() + if (isNotifications) { + markerPromise = fetch(`${MASTODON_MARKERS_URL}?timeline=notifications`, { headers: authHeaders(credentials) }) + .then((data) => data.json()) + .then((data) => { + markers = data.notifications + }) + } + let url = timelineUrls[timeline] if (timeline === 'user' || timeline === 'media' || timeline === 'replies') { @@ -781,6 +792,7 @@ const fetchTimeline = ({ throw new Error(data.error) } if (!data.errors) { + if (isNotifications) data.map((val) => val.last_read = markers.last_read_id) return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination } } else { data.status = status @@ -1277,13 +1289,15 @@ const suggestions = ({ credentials }) => { const markNotificationsAsSeen = ({ id, credentials, single = false }) => { const body = new FormData() - if (single) { + /*if (single) { body.append('id', id) } else { body.append('max_id', id) - } + }*/ - return fetch(NOTIFICATION_READ_URL, { + body.append('notifications[last_read_id]', id) + + return fetch(MASTODON_MARKERS_URL, { body, headers: authHeaders(credentials), method: 'POST' diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 925e281b..e8e308f3 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -446,7 +446,7 @@ export const parseNotification = (data) => { if (masto) { output.type = mastoDict[data.type] || data.type // todo: figure out how to tell if a notification has been seen or not - output.seen = true + output.seen = data.last_read && data.id <= data.last_read if (data.status) { output.status = isStatusNotification(output.type) ? parseStatus(data.status) : null output.action = output.status // TODO: Refactor, this is unneeded