users store unit tests

This commit is contained in:
Henry Jameson 2026-08-18 03:20:09 +03:00
commit 975b338586
16 changed files with 1804 additions and 727 deletions

View file

@ -3,6 +3,7 @@ import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useStatusesStore } from 'src/stores/statuses.js'
import { useUsersStore } from 'src/stores/users.js'
import {
addNewEmojiFile,
@ -399,12 +400,10 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
return {
items: await Promise.all(
users.map(
async (userAdminData) =>
await window.vuex.dispatch('updateUserAdminData', {
userAdminData,
}),
),
users.map((user) => {
useUsersStore().updateUserAdminData(user.id, user)
return useUsersStore().findUser(user.id)
}),
),
count,
}
@ -418,7 +417,8 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
screen_name,
})
window.vuex.commit('updateUserAdminData', { user: result.data })
const { data } = result
useUsersStore().updateUserAdminData(data.id, data)
},
async deleteUsers({ users }) {
const screen_names = users.map((u) => u.screen_name)
@ -491,7 +491,7 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
})
users.forEach((user) => {
window.vuex.commit('updateRight', { user, right, value })
useUsersStore().updateRight(user.id, right, value)
})
},
async setUsersActivationStatus({ users, value }) {
@ -505,7 +505,7 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
})
resultUsers.data.forEach((user) => {
window.vuex.commit('updateUserAdminData', { user })
useUsersStore().updateUserAdminData(user.id, user)
})
},
async setUsersSuggestionStatus({ users, value }) {
@ -519,7 +519,7 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
})
resultUsers.data.forEach((user) => {
window.vuex.commit('updateUserAdminData', { user })
useUsersStore().updateUserAdminData(user.id, user)
})
},
async setUsersConfirmationStatus({ users }) {
@ -545,7 +545,7 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
})
resultUsers.data.forEach((user) => {
window.vuex.commit('updateUserAdminData', { user })
useUsersStore().updateUserAdminData(user.id, user)
})
},
reloadEmoji() {

View file

@ -96,7 +96,7 @@ export const useAnnouncementsStore = defineStore('announcements', {
this.announcements[index].read = true
})
},
startFetchingAnnouncements() {
startFetching() {
if (this.fetchAnnouncementsTimer) {
return
}
@ -109,7 +109,7 @@ export const useAnnouncementsStore = defineStore('announcements', {
return this.fetchAnnouncements()
},
stopFetchingAnnouncements() {
stopFetching() {
const interval = this.fetchAnnouncementsTimer
this.fetchAnnouncementsTimer = undefined
clearInterval(interval)

View file

@ -43,11 +43,11 @@ export const useChatsStore = defineStore('chats', {
useStreamingStore().addSubscriber(socket)
},
startFetchingChats() {
startFetching() {
const fetcher = () => this.fetchChats()
this.setChatListFetcher(() => promiseInterval(fetcher, 5000))
},
stopFetchingChats() {
stopFetching() {
this.setChatListFetcher(null)
},
async fetchChats() {

View file

@ -6,20 +6,38 @@ import {
tryLoadCache,
} from '../services/style_setter/style_setter.js'
import { deserialize } from '../services/theme_data/iss_deserializer.js'
import {
windowHeight,
windowWidth,
} from '../services/window_utils/window_utils'
import { useInstanceStore } from 'src/stores/instance.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.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 {
registerPushNotifications,
unregisterPushNotifications,
} from 'src/services/sw/sw.js'
import {
CURRENT_VERSION,
generatePreset,
} from 'src/services/theme_data/theme_data.service.js'
import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
const getNotificationPermission = async () => {
const Notification = window.Notification
if (!Notification) return null
if (Notification.permission === 'default')
return Notification.requestPermission()
return Notification.permission
}
const GENERIC_FONT_NAMES = new Set([
'serif',
'sans-serif',
@ -85,6 +103,19 @@ export const useInterfaceStore = defineStore('interface', {
useStreamingStore().addSubscriber(socket)
},
onLogin() {
getNotificationPermission().then((permission) =>
useInterfaceStore().setNotificationPermission(permission),
)
this.setLayoutWidth(windowWidth())
this.setLayoutHeight(windowHeight())
},
onLogout() {
this.setLastTimeline('public-timeline')
this.setLayoutWidth(windowWidth())
this.setLayoutHeight(windowHeight())
},
onStreamConnect() {
if (useStreamingStore().state !== WSConnectionStatus.STARTING_INITIAL) {
this.pushGlobalNotice({
@ -805,6 +836,28 @@ export const useInterfaceStore = defineStore('interface', {
window.splashError(e)
}
},
// Push notifications
registerPushNotifications() {
const token = useOAuthStore().token
const vapidPublicKey = useInstanceStore().vapidPublicKey
const isEnabled = useMergedConfigStore().mergedConfig.webPushNotifications
const notificationVisibility =
useMergedConfigStore().mergedConfig.notificationVisibility
registerPushNotifications(
isEnabled,
vapidPublicKey,
token,
notificationVisibility,
)
},
unregisterPushNotifications() {
const token = this.currentUser.credentials
unregisterPushNotifications(token)
},
},
})

View file

@ -592,6 +592,15 @@ export const useStatusesStore = defineStore('statuses', {
})
},
// For when blocking a user
wipeUserStatuses(userId) {
this.allStatuses.values().forEach((status) => {
if (status.user.id === userId) {
this.allStatuses.delete(status.id)
}
})
},
// Search
search({ q, resolve, limit, offset, following, type }) {
return search2({

View file

@ -317,22 +317,24 @@ export const useTimelinesStore = defineStore('timelines', {
},
// Misc
removeUserStatuses({ timelineName, userId }) {
const timeline = this.timelines[timelineName]
wipeUserStatuses(userId) {
TIMELINES.forEach((timelineName) => {
const timeline = this.timelines[timelineName]
timeline.statuses
.values()
.filter(({ user }) => user.id === userId)
.forEach(({ id }) => {
timeline.statuses.delete(id)
timeline.visibleStatusesIds.delete(id)
})
timeline.minVisibleId =
timeline.visibleStatusesIds.size > 0
? last(timeline.visibleStatusesIds).id
: 0
timeline.maxId =
timeline.statuses.length > 0 ? first(timeline.statuses).id : 0
timeline.statuses
.values()
.filter(({ user }) => user.id === userId)
.forEach(({ id }) => {
timeline.statuses.delete(id)
timeline.visibleStatusesIds.delete(id)
})
timeline.minVisibleId =
timeline.visibleStatusesIds.size > 0
? last(timeline.visibleStatusesIds).id
: 0
timeline.maxId =
timeline.statuses.length > 0 ? first(timeline.statuses).id : 0
})
},
},
})

File diff suppressed because it is too large Load diff