more work on notifications + status edits

This commit is contained in:
Henry Jameson 2026-08-13 17:14:29 +03:00
commit 6783236351
6 changed files with 68 additions and 44 deletions

View file

@ -18,6 +18,7 @@ import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useUserHighlightStore } from 'src/stores/user_highlight.js' import { useUserHighlightStore } from 'src/stores/user_highlight.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { useStatusesStore } from 'src/stores/statuses.js'
import { approveUser, denyUser } from 'src/api/user.js' import { approveUser, denyUser } from 'src/api/user.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
@ -182,6 +183,11 @@ const Notification = {
}, },
}, },
computed: { computed: {
status() {
if (this.notification.status) {
return useStatusesStore().allStatuses.get(this.notification.status.id)
}
},
userClass() { userClass() {
return highlightClass(this.notification.from_profile) return highlightClass(this.notification.from_profile)
}, },

View file

@ -6,7 +6,7 @@
<Status <Status
class="Notification panel-body" class="Notification panel-body"
:compact="true" :compact="true"
:statusoid="notification.status" :statusoid="status"
@click="interacted" @click="interacted"
/> />
</article> </article>
@ -261,7 +261,7 @@
<StatusContent <StatusContent
class="status-content" class="status-content"
:compact="!statusExpanded" :compact="!statusExpanded"
:status="notification.status" :status="status"
:collapse="!statusExpanded" :collapse="!statusExpanded"
@click="onContentClick" @click="onContentClick"
/> />

View file

@ -22,10 +22,7 @@ const mastoApiNotificationTypes = new Set([
'pleroma:report', 'pleroma:report',
]) ])
const fetchAndUpdate = ( const fetchAndUpdate = ({ credentials }, { older = false, sinceId }) => {
{ credentials },
{ older = false, sinceId }
) => {
useNotificationsStore().setLoading(true) useNotificationsStore().setLoading(true)
const args = { credentials } const args = { credentials }
const timelineData = useNotificationsStore() const timelineData = useNotificationsStore()
@ -115,7 +112,6 @@ const fetchNotifications = ({ args, older }) => {
}) })
} }
const notificationsFetcher = (credentials) => { const notificationsFetcher = (credentials) => {
const state = { const state = {
interval: null, interval: null,

View file

@ -1,5 +1,15 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useI18nStore } from 'src/stores/i18n.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useReportsStore } from 'src/stores/reports.js'
import { useStatusesStore } from 'src/stores/statuses.js'
import { useStreamingStore } from 'src/stores/streaming.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useUsersStore } from 'src/stores/users.js'
import { dismissNotification, markNotificationsAsSeen } from 'src/api/user.js'
import { import {
closeAllDesktopNotifications, closeAllDesktopNotifications,
closeDesktopNotification, closeDesktopNotification,
@ -11,17 +21,6 @@ import {
import { isStatusNotification } from 'src/services/notification_utils/notification_utils_sw.js' import { isStatusNotification } from 'src/services/notification_utils/notification_utils_sw.js'
import notificationsFetcher from 'src/services/notifications_fetcher/notifications_fetcher.service.js' import notificationsFetcher from 'src/services/notifications_fetcher/notifications_fetcher.service.js'
import { useI18nStore } from 'src/stores/i18n.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useReportsStore } from 'src/stores/reports.js'
import { useStatusesStore } from 'src/stores/statuses.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useStreamingStore } from 'src/stores/streaming.js'
import { useUsersStore } from 'src/stores/users.js'
import { dismissNotification, markNotificationsAsSeen } from 'src/api/user.js'
export const defaultState = () => ({ export const defaultState = () => ({
desktopNotificationSilence: true, desktopNotificationSilence: true,
maxId: '', maxId: '',
@ -42,8 +41,7 @@ export const useNotificationsStore = defineStore('notifications', {
attachSocket() { attachSocket() {
const et = new EventTarget() const et = new EventTarget()
const handleNotificationMessage = ({ data, timestamp }) => { const handleNotificationMessage = ({ data, timestamp }) => {
console.log(data) this.addNewNotifications({ data: [data.notification], timestamp })
this.addNewNotifications({ statuses: [data.notification], timestamp })
} }
const notificationHandler = ({ detail: message }) => { const notificationHandler = ({ detail: message }) => {
handleNotificationMessage(message) handleNotificationMessage(message)
@ -56,7 +54,7 @@ export const useNotificationsStore = defineStore('notifications', {
openHandler, openHandler,
closeHandler, closeHandler,
notificationHandler, notificationHandler,
} },
} }
et.addEventListener('notification', notificationHandler) et.addEventListener('notification', notificationHandler)
@ -72,10 +70,7 @@ export const useNotificationsStore = defineStore('notifications', {
// Initially there's set flag to silence all desktop notifications so // Initially there's set flag to silence all desktop notifications so
// that there won't spam of them when user just opened up the FE we // that there won't spam of them when user just opened up the FE we
// reset that flag after a while to show new notifications once again. // reset that flag after a while to show new notifications once again.
setTimeout( setTimeout(() => (this.desktopNotificationSilence = false), 10000)
() => this.desktopNotificationSilence = false,
10000,
)
if (this.fetcher) throw new Error('Fetcher already exists!') if (this.fetcher) throw new Error('Fetcher already exists!')
this.fetcher = notificationsFetcher(useOAuthStore().token) this.fetcher = notificationsFetcher(useOAuthStore().token)
@ -87,7 +82,8 @@ export const useNotificationsStore = defineStore('notifications', {
} }
useStreamingStore().removeSubscriber(this.socket) useStreamingStore().removeSubscriber(this.socket)
const { openHandler, closeHandler, notificationHandler } = timeline.socket.handlers const { openHandler, closeHandler, notificationHandler } =
this.socket.handlers
this.socket.et.removeEventListener('notification', openHandler) this.socket.et.removeEventListener('notification', openHandler)
this.socket.et.removeEventListener('notification', closeHandler) this.socket.et.removeEventListener('notification', closeHandler)
@ -111,11 +107,19 @@ export const useNotificationsStore = defineStore('notifications', {
this.startFetching('Socket disconnected') this.startFetching('Socket disconnected')
}, },
startFetching(reason) { startFetching(reason) {
console.debug('[Notifications] Starting fetching notifications', 'Reason:', reason) console.debug(
'[Notifications] Starting fetching notifications',
'Reason:',
reason,
)
this.fetcher.startFetching() this.fetcher.startFetching()
}, },
stopFetching(reason) { stopFetching(reason) {
console.debug('[Notifications] Stopped fetching notifications', 'Reason:', reason) console.debug(
'[Notifications] Stopped fetching notifications',
'Reason:',
reason,
)
this.fetcher.stopFetching() this.fetcher.stopFetching()
}, },

View file

@ -93,8 +93,9 @@ export const useStatusesStore = defineStore('statuses', {
const socket = { const socket = {
et, et,
handlers: { handlers: {
handleUpdate, handleDelete handleUpdate,
} handleDelete,
},
} }
et.addEventListener('update', handleUpdate) et.addEventListener('update', handleUpdate)
@ -106,7 +107,10 @@ export const useStatusesStore = defineStore('statuses', {
}, },
resetStatuses() { resetStatuses() {
this.socket.et.removeEventListener('update', this.socket.handleUpdate) this.socket.et.removeEventListener('update', this.socket.handleUpdate)
this.socket.et.removeEventListener('status.update', this.socket.handleUpdate) this.socket.et.removeEventListener(
'status.update',
this.socket.handleUpdate,
)
this.socket.et.removeEventListener('delete', this.socket.handleDelete) this.socket.et.removeEventListener('delete', this.socket.handleDelete)
const emptyState = defaultState() const emptyState = defaultState()

View file

@ -100,9 +100,12 @@ export const useTimelinesStore = defineStore('timelines', {
if (streamName) { if (streamName) {
const et = new EventTarget() const et = new EventTarget()
const openHandler = () => this.onStreamConnect(timelineName, argument) const openHandler = () => this.onStreamConnect(timelineName, argument)
const closeHandler = () => this.onStreamDisconnect(timelineName, argument) const closeHandler = () =>
const messageHandler = () => ({ detail: message }) => this.onStreamDisconnect(timelineName, argument)
this.onStreamMessage(timelineName, argument, message) const messageHandler =
() =>
({ detail: message }) =>
this.onStreamMessage(timelineName, argument, message)
et.addEventListener('open', openHandler) et.addEventListener('open', openHandler)
et.addEventListener('close', closeHandler) et.addEventListener('close', closeHandler)
@ -118,7 +121,7 @@ export const useTimelinesStore = defineStore('timelines', {
openHandler, openHandler,
closeHandler, closeHandler,
messageHandler, messageHandler,
} },
} }
useStreamingStore().addSubscriber(timeline.socket) useStreamingStore().addSubscriber(timeline.socket)
@ -131,12 +134,14 @@ export const useTimelinesStore = defineStore('timelines', {
this.stopFetchingTimeline(timelineName, 'Timeline deactivation') this.stopFetchingTimeline(timelineName, 'Timeline deactivation')
} }
if (data.socket) { if (timeline.socket) {
useStreamingStore().removeSubscriber(timeline.socket) useStreamingStore().removeSubscriber(timeline.socket)
const { openHandler, closeHandler, messageHandler } = timeline.socket.handlers
et.removeEventListener('open', openHandler) const { openHandler, closeHandler, messageHandler } =
et.removeEventListener('close', closeHandler) timeline.socket.handlers
et.removeEventListener('message', messageHandler) timeline.socket.et.removeEventListener('open', openHandler)
timeline.socket.et.removeEventListener('close', closeHandler)
timeline.socket.et.removeEventListener('message', messageHandler)
} }
this[timelineName] = emptyTl(timelineName) this[timelineName] = emptyTl(timelineName)
@ -247,12 +252,23 @@ export const useTimelinesStore = defineStore('timelines', {
this.startFetchingTimeline(timeline, argument, 'Socket disconnected') this.startFetchingTimeline(timeline, argument, 'Socket disconnected')
}, },
startFetchingTimeline(timelineName, argument, reason) { startFetchingTimeline(timelineName, argument, reason) {
console.debug('[Timelines] Starting fetching timeline', timelineName, argument, 'Reason:', reason) console.debug(
'[Timelines] Starting fetching timeline',
timelineName,
argument,
'Reason:',
reason,
)
const timeline = this[timelineName] const timeline = this[timelineName]
timeline.fetcher.startFetching() timeline.fetcher.startFetching()
}, },
stopFetchingTimeline(timelineName, reason) { stopFetchingTimeline(timelineName, reason) {
console.debug('[Timelines] Stopped fetching timeline', timelineName, 'Reason:', reason) console.debug(
'[Timelines] Stopped fetching timeline',
timelineName,
'Reason:',
reason,
)
const timeline = this[timelineName] const timeline = this[timelineName]
timeline.fetcher.stopFetching() timeline.fetcher.stopFetching()
}, },
@ -287,8 +303,6 @@ export const useTimelinesStore = defineStore('timelines', {
this.updateTimelineExtremes(timeline, [...timeline.statuses.keys()]) this.updateTimelineExtremes(timeline, [...timeline.statuses.keys()])
}, },
clearTimeline(timeline) {
},
queueFlush(timeline, id) { queueFlush(timeline, id) {
this[timeline].flushMarker = id this[timeline].flushMarker = id
}, },