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) => {
const emojiCurry = suggestEmoji(data.emoji)
const usersCurry = data.store && suggestUsers(data.store)
const usersCurry = suggestUsers()
return (input, nameKeywordLocalizer) => {
const firstChar = input[0]
if (firstChar === ':' && data.emoji) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,6 @@ export const useShoutStore = defineStore('shout', {
messages: [],
channel: { state: '' },
joined: false,
token: null,
socket: null,
}),
getters: {
@ -20,7 +19,7 @@ export const useShoutStore = defineStore('shout', {
initializeSocket() {
if (this.token === null) 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.connect()

View file

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