lint, cleanup
This commit is contained in:
parent
0b7bbd7427
commit
9f9a83a56a
4 changed files with 46 additions and 3 deletions
|
|
@ -37,6 +37,7 @@ import { useInterfaceStore } from 'src/stores/interface.js'
|
|||
import { useLocalConfigStore } from 'src/stores/local_config.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
import { useStatusesStore } from 'src/stores/statuses.js'
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
|
@ -590,6 +591,10 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
|
|||
|
||||
useI18nStore().setI18n(i18n)
|
||||
|
||||
// Global WS handlers
|
||||
useInterfaceStore().attachSocket()
|
||||
useStatusesStore().attachSocket()
|
||||
|
||||
app.use(router)
|
||||
app.use(store)
|
||||
app.use(i18n)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js'
|
|||
import { promiseInterval } from '../services/promise_interval/promise_interval.js'
|
||||
|
||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
import { useStreamingStore } from 'src/stores/streaming.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
||||
import { chats } from 'src/api/chats.js'
|
||||
|
|
@ -34,6 +35,14 @@ export const useChatsStore = defineStore('chats', {
|
|||
},
|
||||
},
|
||||
actions: {
|
||||
attachSocket() {
|
||||
const et = new EventTarget()
|
||||
const socket = { et }
|
||||
|
||||
et.addEventListener('pleroma:chat_update', this.updateChat)
|
||||
|
||||
useStreamingStore().addSubscriber(socket)
|
||||
},
|
||||
startFetchingChats() {
|
||||
const fetcher = () => this.fetchChats()
|
||||
this.setChatListFetcher(() => promiseInterval(fetcher, 5000))
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import { deserialize } from '../services/theme_data/iss_deserializer.js'
|
|||
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
import { useStreamingStore } from 'src/stores/streaming.js'
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
||||
import { WSConnectionStatus } from 'src/api/websocket.js'
|
||||
import {
|
||||
CURRENT_VERSION,
|
||||
generatePreset,
|
||||
|
|
@ -74,6 +76,34 @@ export const useInterfaceStore = defineStore('interface', {
|
|||
foreignProfileBackground: null,
|
||||
}),
|
||||
actions: {
|
||||
attachSocket() {
|
||||
const et = new EventTarget()
|
||||
const socket = { et }
|
||||
|
||||
et.addEventListener('open', this.onStreamConnect)
|
||||
et.addEventListener('close', this.onStreamDisconnect)
|
||||
|
||||
useStreamingStore().addSubscriber(socket)
|
||||
},
|
||||
onStreamConnect() {
|
||||
if (useStreamingStore().state !== WSConnectionStatus.STARTING_INITIAL) {
|
||||
this.pushGlobalNotice({
|
||||
level: 'success',
|
||||
messageKey: 'timeline.socket_reconnected',
|
||||
timeout: 5000,
|
||||
})
|
||||
}
|
||||
},
|
||||
onStreamDisconnect(closeEvent) {
|
||||
// TODO better explanation/localization
|
||||
const { code } = closeEvent
|
||||
this.pushGlobalNotice({
|
||||
level: 'error',
|
||||
messageKey: 'timeline.socket_broke',
|
||||
messageArgs: [code],
|
||||
timeout: 5000,
|
||||
})
|
||||
},
|
||||
setTemporaryChanges({ confirm, revert }) {
|
||||
this.temporaryChangesCountdown = 10
|
||||
this.temporaryChangesConfirm = confirm
|
||||
|
|
|
|||
|
|
@ -725,7 +725,6 @@ export const useUsersStore = defineStore('users', {
|
|||
}
|
||||
|
||||
// DMs and Home
|
||||
useStatusesStore().attachSocket()
|
||||
useNotificationsStore().activate()
|
||||
useTimelinesStore().activatePersistents()
|
||||
|
||||
|
|
@ -741,9 +740,9 @@ export const useUsersStore = defineStore('users', {
|
|||
dispatch('startFetchingFollowRequests')
|
||||
}
|
||||
|
||||
useStreamingStore().initSocket()
|
||||
useStreamingStore().initSocket(true)
|
||||
if (useMergedConfigStore().mergedConfig.useStreamingApi) {
|
||||
useStreamingStore().initSocket()
|
||||
useStreamingStore().initSocket(true)
|
||||
}
|
||||
|
||||
// Start fetching things that don't need to block the UI
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue