Make notifications work
Unsure if marking single notifications as seen is possible with masto
This commit is contained in:
parent
cd6de14f3e
commit
7230883077
5 changed files with 22 additions and 8 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,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 => {
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -447,7 +447,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue