This commit is contained in:
Henry Jameson 2026-09-03 16:55:41 +03:00
commit 9fe60eb860
9 changed files with 56 additions and 31 deletions

View file

@ -15,7 +15,7 @@ import { useUsersStore } from 'src/stores/users.js'
export default (data) => { export default (data) => {
const emojiCurry = suggestEmoji(data.emoji) const emojiCurry = suggestEmoji(data.emoji)
const usersCurry = data.store && suggestUsers(data.store) const usersCurry = suggestUsers()
return (input, nameKeywordLocalizer) => { return (input, nameKeywordLocalizer) => {
const firstChar = input[0] const firstChar = input[0]
if (firstChar === ':' && data.emoji) { if (firstChar === ':' && data.emoji) {

View file

@ -165,7 +165,9 @@ const Notification = {
id: this.user.id, id: this.user.id,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}).then(() => { }).then(() => {
useNotificationsStore().dismissNotificationLocal(this.notification.id) useNotificationsStore().markSingleNotificationAsSeen(
this.notification.id,
)
useFollowRequestsStore().remove(this.user.id) useFollowRequestsStore().remove(this.user.id)
}) })
this.hideDenyConfirmDialog() this.hideDenyConfirmDialog()

View file

@ -110,7 +110,7 @@ const SideDrawer = {
hideSitename: (store) => store.instanceIdentity.hideSitename, hideSitename: (store) => store.instanceIdentity.hideSitename,
}), }),
...mapState(useChatsStore, ['unreadChatsCount']), ...mapState(useChatsStore, ['unreadChatsCount']),
...mapState(useDraftsStore, ['draftCount']), ...mapState(useDraftsStore, ['draftsCount']),
}, },
methods: { methods: {
toggleDrawer() { toggleDrawer() {

View file

@ -269,10 +269,10 @@
icon="file-pen" icon="file-pen"
/> {{ $t('nav.drafts') }} /> {{ $t('nav.drafts') }}
<span <span
v-if="draftCount" v-if="draftsCount"
class="badge -neutral" class="badge -neutral"
> >
{{ draftCount }} {{ draftsCount }}
</span> </span>
</router-link> </router-link>
</li> </li>

View file

@ -57,7 +57,7 @@ export const useDraftsStore = defineStore('drafts', {
await deleteDraftFromStorage([id]) await deleteDraftFromStorage([id])
}, },
async loadDrafts() { async loadDrafts() {
const currentData = await getStorageData() const currentData = (await getStorageData()) ?? {}
this.drafts = new Map(Object.entries(currentData)) this.drafts = new Map(Object.entries(currentData))
}, },
async addOrSaveDraft(draft) { async addOrSaveDraft(draft) {
@ -67,9 +67,9 @@ export const useDraftsStore = defineStore('drafts', {
await saveDraftToStorage(draftWithId) await saveDraftToStorage(draftWithId)
return id return id
}, },
async abandonAllDrafts(store) { async abandonAllDrafts() {
const ids = [...this.drafts.keys()] const ids = [...this.drafts.keys()]
ids.forEach((id) => this.abandonDraft(id)) ids.forEach((id) => this.drafts.delete(id))
await deleteDraftFromStorage(ids) await deleteDraftFromStorage(ids)
}, },
}, },

View file

@ -15,7 +15,7 @@ export const useFollowRequestsStore = defineStore('followRequests', {
}, },
actions: { actions: {
startFetching() { startFetching() {
if (this.fetcher) throw 'Fetcher already exists!' if (this.fetcher) throw new Error('Fetcher already exists!')
this.fetcher = followRequestFetcher({ this.fetcher = followRequestFetcher({
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
@ -24,8 +24,9 @@ export const useFollowRequestsStore = defineStore('followRequests', {
this.fetcher.startFetching() this.fetcher.startFetching()
}, },
stopFetching() { stopFetching() {
if (!this.fetcher) throw "Fetcher doesn't exists!" if (!this.fetcher) throw new Error("Fetcher doesn't exists!")
this.fetcher.stopFetching(), (this.fetcher = null) this.fetcher.stopFetching()
this.fetcher = null
}, },
setFollowRequests(requests) { setFollowRequests(requests) {
this.requests = new Map(requests.map((user) => [user.id, user])) this.requests = new Map(requests.map((user) => [user.id, user]))

View file

@ -1,5 +1,8 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useShoutStore } from 'src/stores/shout.js'
import { useUsersStore } from 'src/stores/users.js'
const defaultState = { const defaultState = {
postFormats: [], postFormats: [],
mailerEnabled: false, mailerEnabled: false,
@ -38,6 +41,13 @@ export const useInstanceCapabilitiesStore = defineStore(
} }
this[capability] = value this[capability] = value
if (
capability === 'shoutAvailable' &&
useUsersStore().currentUser?.token
) {
useShoutStore().initializeSocket()
}
}, },
}, },
}, },

View file

@ -10,7 +10,6 @@ export const useShoutStore = defineStore('shout', {
messages: [], messages: [],
channel: { state: '' }, channel: { state: '' },
joined: false, joined: false,
token: null,
socket: null, socket: null,
}), }),
getters: { getters: {
@ -20,7 +19,7 @@ export const useShoutStore = defineStore('shout', {
initializeSocket() { initializeSocket() {
if (this.token === null) return if (this.token === null) return
if (!useInstanceCapabilitiesStore().shoutAvailable) return if (!useInstanceCapabilitiesStore().shoutAvailable) return
if (this.socket !== null) throw new Error('Shout socket already exist!') if (this.socket !== null) return
this.socket = new Socket('/socket', { params: { token: this.token } }) this.socket = new Socket('/socket', { params: { token: this.token } })
this.socket.connect() this.socket.connect()

View file

@ -5,7 +5,9 @@ import { setActivePinia } from 'pinia'
import { useAnnouncementsStore } from 'src/stores/announcements.js' import { useAnnouncementsStore } from 'src/stores/announcements.js'
import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js' import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js'
import { useChatsStore } from 'src/stores/chats.js' import { useChatsStore } from 'src/stores/chats.js'
import { useDraftsStore } from 'src/stores/drafts.js'
import { useEmojiStore } from 'src/stores/emoji.js' import { useEmojiStore } from 'src/stores/emoji.js'
import { useFollowRequestsStore } from 'src/stores/follow_requests.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { useListsStore } from 'src/stores/lists.js' import { useListsStore } from 'src/stores/lists.js'
@ -53,12 +55,14 @@ const mockMastoAPIUser = ({
name = userName, name = userName,
url = userUrl, url = userUrl,
id = userId, id = userId,
locked = true,
} = {}) => ({ } = {}) => ({
id, id,
acct: screen_name, acct: screen_name,
display_name: name, display_name: name,
fields: [], fields: [],
avatar: '', avatar: '',
locked,
url, url,
}) })
@ -67,17 +71,20 @@ const mockUser = ({
id = userId, id = userId,
name = userName, name = userName,
url = userUrl, url = userUrl,
locked = true,
} = {}) => ({ } = {}) => ({
_original: mockMastoAPIUser({ _original: mockMastoAPIUser({
screen_name, screen_name,
id, id,
name, name,
url, url,
locked,
}), }),
id, id,
name, name,
screen_name, screen_name,
url, url,
locked,
relationship: undefined, relationship: undefined,
}) })
@ -631,22 +638,24 @@ describe('Users store', () => {
const spies = [ const spies = [
// Misc initialization // Misc initialization
vi.spyOn(useSyncConfigStore(), 'initSyncConfig'), /* 0 */ vi.spyOn(useSyncConfigStore(), 'initSyncConfig'),
vi.spyOn(useUserHighlightStore(), 'initUserHighlight'), /* 1 */ vi.spyOn(useUserHighlightStore(), 'initUserHighlight'),
vi.spyOn(useInterfaceStore(), 'applyTheme'), /* 2 */ vi.spyOn(useInterfaceStore(), 'applyTheme'),
vi.spyOn(useInterfaceStore(), 'onLogin'), /* 3 */ vi.spyOn(useInterfaceStore(), 'onLogin'),
vi.spyOn(useEmojiStore(), 'fetchEmoji'), /* 4 */ vi.spyOn(useEmojiStore(), 'fetchEmoji'),
/* 5 */ vi.spyOn(useDraftsStore(), 'loadDrafts'),
// Timeline / Notifications // Timeline / Notifications
vi.spyOn(useNotificationsStore(), 'activate'), /* 6 */ vi.spyOn(useNotificationsStore(), 'activate'),
vi.spyOn(useTimelinesStore(), 'activatePersistents'), /* 7 */ vi.spyOn(useTimelinesStore(), 'activatePersistents'),
// Fetchers // Fetchers
vi.spyOn(useChatsStore(), 'startFetching'), /* 8 */ vi.spyOn(useChatsStore(), 'startFetching'),
vi.spyOn(useListsStore(), 'startFetching'), /* 9 */ vi.spyOn(useListsStore(), 'startFetching'),
vi.spyOn(useAnnouncementsStore(), 'startFetching'), /* 10 */ vi.spyOn(useAnnouncementsStore(), 'startFetching'),
vi.spyOn(useBookmarkFoldersStore(), 'startFetching'), /* 11 */ vi.spyOn(useBookmarkFoldersStore(), 'startFetching'),
vi.spyOn(useStreamingStore(), 'initSocket'), /* 12 */ vi.spyOn(useFollowRequestsStore(), 'startFetching'),
/* 13 */ vi.spyOn(useStreamingStore(), 'initSocket'),
] ]
spies.forEach((spy) => { spies.forEach((spy) => {
@ -758,6 +767,7 @@ describe('Users store', () => {
/* 11 */ vi.spyOn(useAnnouncementsStore(), 'stopFetching'), /* 11 */ vi.spyOn(useAnnouncementsStore(), 'stopFetching'),
/* 12 */ vi.spyOn(useBookmarkFoldersStore(), 'stopFetching'), /* 12 */ vi.spyOn(useBookmarkFoldersStore(), 'stopFetching'),
/* 13 */ vi.spyOn(useStreamingStore(), 'stopSocket'), /* 13 */ vi.spyOn(useStreamingStore(), 'stopSocket'),
/* 14 */ vi.spyOn(useFollowRequestsStore(), 'stopFetching'),
] ]
spies.forEach((spy) => { spies.forEach((spy) => {
@ -771,6 +781,7 @@ describe('Users store', () => {
const store = useUsersStore() const store = useUsersStore()
store.currentUser = mockUser() store.currentUser = mockUser()
store.currentUser.locked = true
// Adding some users to verify they are getting cleaned afterwards // Adding some users to verify they are getting cleaned afterwards
store.addNewUsers({ store.addNewUsers({
@ -832,17 +843,19 @@ describe('Users store', () => {
/* 3 */ vi.spyOn(useChatsStore(), 'stopFetching'), /* 3 */ vi.spyOn(useChatsStore(), 'stopFetching'),
/* 4 */ vi.spyOn(useAnnouncementsStore(), 'stopFetching'), /* 4 */ vi.spyOn(useAnnouncementsStore(), 'stopFetching'),
/* 5 */ vi.spyOn(useBookmarkFoldersStore(), 'stopFetching'), /* 5 */ vi.spyOn(useBookmarkFoldersStore(), 'stopFetching'),
/* 6 */ vi.spyOn(useFollowRequestsStore(), 'stopFetching'),
// ## RESUME ## // ## RESUME ##
// Timeline / Notifications // Timeline / Notifications
/* 6 */ vi.spyOn(useNotificationsStore(), 'resume'), /* 7 */ vi.spyOn(useNotificationsStore(), 'resume'),
/* 7 */ vi.spyOn(useTimelinesStore(), 'resumeAll'), /* 8 */ vi.spyOn(useTimelinesStore(), 'resumeAll'),
// Fetchers (Pauseless) // Fetchers (Pauseless)
/* 8 */ vi.spyOn(useListsStore(), 'startFetching'), /* 9 */ vi.spyOn(useListsStore(), 'startFetching'),
/* 9 */ vi.spyOn(useChatsStore(), 'startFetching'), /* 10 */ vi.spyOn(useChatsStore(), 'startFetching'),
/* 10 */ vi.spyOn(useAnnouncementsStore(), 'startFetching'), /* 11 */ vi.spyOn(useAnnouncementsStore(), 'startFetching'),
/* 11 */ vi.spyOn(useBookmarkFoldersStore(), 'startFetching'), /* 12 */ vi.spyOn(useBookmarkFoldersStore(), 'startFetching'),
/* 13 */ vi.spyOn(useFollowRequestsStore(), 'startFetching'),
] ]
spies.forEach((spy) => { spies.forEach((spy) => {