diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index eb1d8e068..310d66d1d 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -9,6 +9,7 @@ import UserCard from 'src/components/user_card/user_card.vue'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
+import { useUsersStore } from 'src/stores/users.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
@@ -54,12 +55,12 @@ const UserProfile = {
isUs() {
return (
this.userId &&
- this.$store.state.users.currentUser.id &&
- this.userId === this.$store.state.users.currentUser.id
+ useUsersStore().currentUser.id &&
+ this.userId === useUsersStore().currentUser.id
)
},
user() {
- return this.$store.getters.findUser(this.userId)
+ return useUsersStore().findUser(this.userId)
},
isExternal() {
return this.$route.name === 'external-user-profile'
@@ -81,18 +82,14 @@ const UserProfile = {
return useMergedConfigStore().mergedConfig.compactProfiles
},
friends() {
- return get(
- this.$store.getters.findUser(this.userId),
- 'friendIds',
- [],
- ).map((id) => this.$store.getters.findUser(id))
+ return get(useUsersStore().findUser(this.userId), 'friendIds', []).map(
+ (id) => useUsersStore().findUser(id),
+ )
},
followers() {
- return get(
- this.$store.getters.findUser(this.userId),
- 'followerIds',
- [],
- ).map((id) => this.$store.getters.findUser(id))
+ return get(useUsersStore().findUser(this.userId), 'followerIds', []).map(
+ (id) => useUsersStore().findUser(id),
+ )
},
},
methods: {
@@ -136,8 +133,8 @@ const UserProfile = {
// Check if user data is already loaded in store
const user = maybeId
- ? this.$store.getters.findUser(maybeId)
- : this.$store.getters.findUserByName(maybeName)
+ ? useUsersStore().findUser(maybeId)
+ : useUsersStore().findUserByName(maybeName)
if (user) {
loadById(user.id)
} else {
diff --git a/src/components/user_profile/user_profile_admin_view.js b/src/components/user_profile/user_profile_admin_view.js
index da2c6c322..342ca1109 100644
--- a/src/components/user_profile/user_profile_admin_view.js
+++ b/src/components/user_profile/user_profile_admin_view.js
@@ -5,6 +5,7 @@ import UserCard from 'src/components/user_card/user_card.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInterfaceStore } from 'src/stores/interface.js'
+import { useUsersStore } from 'src/stores/users.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
@@ -38,7 +39,7 @@ const UserProfileAdminView = {
}
},
user() {
- return this.$store.getters.findUser(this.userId)
+ return useUsersStore().findUser(this.userId)
},
userId() {
return this.$route.params.id
diff --git a/src/components/user_reporting_modal/user_reporting_modal.js b/src/components/user_reporting_modal/user_reporting_modal.js
index 017a17efa..232305415 100644
--- a/src/components/user_reporting_modal/user_reporting_modal.js
+++ b/src/components/user_reporting_modal/user_reporting_modal.js
@@ -7,6 +7,7 @@ import UserLink from 'src/components/user_link/user_link.vue'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useReportsStore } from 'src/stores/reports.js'
+import { useUsersStore } from 'src/stores/users.js'
import { reportUser } from 'src/api/user.js'
@@ -28,7 +29,7 @@ const UserReportingModal = {
},
computed: {
isLoggedIn() {
- return !!this.$store.state.users.currentUser
+ return !!useUsersStore().currentUser
},
isOpen() {
return this.isLoggedIn && this.reportModal.activated
@@ -37,7 +38,7 @@ const UserReportingModal = {
return this.reportModal.userId
},
user() {
- return this.$store.getters.findUser(this.userId)
+ return useUsersStore().findUser(this.userId)
},
remoteInstance() {
return (
diff --git a/src/components/who_to_follow_panel/who_to_follow_panel.js b/src/components/who_to_follow_panel/who_to_follow_panel.js
index 7a65ba39d..7e241d6eb 100644
--- a/src/components/who_to_follow_panel/who_to_follow_panel.js
+++ b/src/components/who_to_follow_panel/who_to_follow_panel.js
@@ -3,6 +3,7 @@ import { shuffle } from 'lodash'
import { useInstanceStore } from 'src/stores/instance.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { fetchUser, suggestions } from 'src/api/public.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
@@ -31,7 +32,7 @@ function showWhoToFollow(panel, reply) {
}
function getWhoToFollow(panel) {
- const credentials = panel.$store.state.users.currentUser.credentials
+ const credentials = panel.$useUsersStore().currentUser.credentials
if (credentials) {
panel.usersToFollow.forEach((toFollow) => {
toFollow.name = 'Loading...'
@@ -48,7 +49,7 @@ const WhoToFollowPanel = {
}),
computed: {
user: function () {
- return this.$store.state.users.currentUser.screen_name
+ return useUsersStore().currentUser.screen_name
},
suggestionsEnabled() {
return useInstanceCapabilitiesStore().suggestionsEnabled
diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js
index 5fcf259aa..a4dfe7d00 100644
--- a/src/lib/persisted_state.js
+++ b/src/lib/persisted_state.js
@@ -16,8 +16,6 @@ const defaultReducer = (state, paths) =>
const saveImmedeatelyActions = [
'markNotificationsAsSeen',
- 'clearCurrentUser',
- 'setCurrentUser',
'setHighlight',
'setOption',
'setClientData',
@@ -75,19 +73,13 @@ export default function createPersistedState({
setState(key, reducer(cloneDeep(state), paths), storage).then(
(success) => {
if (success !== undefined) {
- if (
- mutation.type === 'setOption' ||
- mutation.type === 'setCurrentUser'
- ) {
+ if (mutation.type === 'setOption') {
useInterfaceStore().settingsSaved({ success })
}
}
},
(error) => {
- if (
- mutation.type === 'setOption' ||
- mutation.type === 'setCurrentUser'
- ) {
+ if (mutation.type === 'setOption') {
useInterfaceStore().settingsSaved({ error })
}
},
diff --git a/src/lib/push_notifications_plugin.js b/src/lib/push_notifications_plugin.js
index f4dcb1dbc..5f8d65aba 100644
--- a/src/lib/push_notifications_plugin.js
+++ b/src/lib/push_notifications_plugin.js
@@ -1,6 +1,7 @@
import { useInstanceStore } from 'src/stores/instance.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
+import { useUsersStore } from 'src/stores/users.js'
export const piniaPushNotificationsPlugin = ({ store }) => {
if (
@@ -25,7 +26,7 @@ export const piniaPushNotificationsPlugin = ({ store }) => {
useInterfaceStore().notificationPermission === 'granted'
let permissionPresent =
useInterfaceStore().notificationPermission !== undefined
- let user = !!window.vuex.state.users.currentUser
+ let user = !!useUsersStore().currentUser
if (store.$id === 'instance') {
if (actionName === 'set' && args[0].path === 'vapidPublicKey') {
@@ -66,6 +67,7 @@ export const piniaPushNotificationsPlugin = ({ store }) => {
})
}
+// TODO make it work with pinia
export const vuexPushNotificationsPlugin = (store) => {
store.subscribe((mutation, state) => {
// Initial state
diff --git a/src/modules/index.js b/src/modules/index.js
index c8f3dce39..9b469c6df 100644
--- a/src/modules/index.js
+++ b/src/modules/index.js
@@ -3,12 +3,10 @@ import drafts from './drafts.js'
import notifications from './notifications.js'
import profileConfig from './profileConfig.js'
import statuses from './statuses.js'
-import users from './users.js'
export default {
statuses,
notifications,
- users,
api,
profileConfig,
drafts,
diff --git a/src/modules/notifications.js b/src/modules/notifications.js
index b77683811..100de3974 100644
--- a/src/modules/notifications.js
+++ b/src/modules/notifications.js
@@ -13,6 +13,7 @@ import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useReportsStore } from 'src/stores/reports.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
+import { useUsersStore } from 'src/stores/users.js'
import { dismissNotification, markNotificationsAsSeen } from 'src/api/user.js'
@@ -158,7 +159,7 @@ export const notifications = {
commit('markNotificationsAsSeen')
markNotificationsAsSeen({
id: state.maxId,
- credentials: rootState.users.currentUser.credentials,
+ credentials: useUsersStore().currentUser.credentials,
}).then(() => {
closeAllDesktopNotifications(rootState)
})
@@ -168,7 +169,7 @@ export const notifications = {
markNotificationsAsSeen({
single: true,
id,
- credentials: rootState.users.currentUser.credentials,
+ credentials: useUsersStore().currentUser.credentials,
}).then(() => {
closeDesktopNotification(rootState, { id })
})
diff --git a/src/modules/profileConfig.js b/src/modules/profileConfig.js
index 3fca7d6a8..8b9c77425 100644
--- a/src/modules/profileConfig.js
+++ b/src/modules/profileConfig.js
@@ -1,6 +1,7 @@
import { get, set } from 'lodash'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { updateNotificationSettings, updateProfile } from 'src/api/user.js'
@@ -10,9 +11,8 @@ const defaultApi = ({ rootState, commit }, { path, value }) => {
return updateProfile({
params,
credentials: useOAuthStore().token,
- }).then(({ data: result }) => {
- commit('addNewUsers', [result])
- commit('setCurrentUser', result)
+ }).then((result) => {
+ useUsersStore().addNewUsers(result)
})
}
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index f39da5b3f..bcef660a0 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -14,6 +14,7 @@ import {
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import {
fetchEmojiReactions,
@@ -619,7 +620,7 @@ const statuses = {
showImmediately,
timeline,
noIdUpdate,
- user: rootState.users.currentUser,
+ user: useUsersStore().currentUser,
userId,
pagination,
})
@@ -671,7 +672,7 @@ const statuses = {
}).then(({ data: status }) =>
commit('setFavoritedConfirm', {
status,
- user: rootState.users.currentUser,
+ user: useUsersStore().currentUser,
}),
)
},
@@ -684,7 +685,7 @@ const statuses = {
}).then(({ data: status }) =>
commit('setFavoritedConfirm', {
status,
- user: rootState.users.currentUser,
+ user: useUsersStore().currentUser,
}),
)
},
@@ -739,7 +740,7 @@ const statuses = {
}).then(({ data: status }) =>
commit('setRetweetedConfirm', {
status: status.retweeted_status,
- user: rootState.users.currentUser,
+ user: useUsersStore().currentUser,
}),
)
},
@@ -752,7 +753,7 @@ const statuses = {
}).then(({ data: status }) =>
commit('setRetweetedConfirm', {
status,
- user: rootState.users.currentUser,
+ user: useUsersStore().currentUser,
}),
)
},
@@ -795,17 +796,17 @@ const statuses = {
commit('addFavs', {
id,
favoritedByUsers,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
})
commit('addRepeats', {
id,
rebloggedByUsers,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
})
})
},
reactWithEmoji({ rootState, dispatch, commit }, { id, emoji }) {
- const currentUser = rootState.users.currentUser
+ const currentUser = useUsersStore().currentUser
if (!currentUser) return
commit('addOwnReaction', { id, emoji, currentUser })
@@ -818,14 +819,14 @@ const statuses = {
})
},
unreactWithEmoji({ rootState, dispatch, commit }, { id, emoji }) {
- const currentUser = rootState.users.currentUser
+ const currentUser = useUsersStore().currentUser
if (!currentUser) return
commit('removeOwnReaction', { id, emoji, currentUser })
unreactWithEmoji({
id,
emoji,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
}).then(() => {
dispatch('fetchEmojiReactionsBy', id)
})
@@ -838,7 +839,7 @@ const statuses = {
commit('addEmojiReactionsBy', {
id,
emojiReactions,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
})
})
},
@@ -850,7 +851,7 @@ const statuses = {
commit('addFavs', {
id,
favoritedByUsers,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
}),
)
},
@@ -862,7 +863,7 @@ const statuses = {
commit('addRepeats', {
id,
rebloggedByUsers,
- currentUser: rootState.users.currentUser,
+ currentUser: useUsersStore().currentUser,
}),
)
},
diff --git a/src/modules/users.js b/src/modules/users.js
deleted file mode 100644
index 9e24c1bdd..000000000
--- a/src/modules/users.js
+++ /dev/null
@@ -1,870 +0,0 @@
-import Cookies from 'js-cookie'
-import { compact, each, last, map, mergeWith } from 'lodash'
-
-import {
- registerPushNotifications,
- unregisterPushNotifications,
-} from '../services/sw/sw.js'
-import {
- windowHeight,
- windowWidth,
-} from '../services/window_utils/window_utils'
-
-import { useAnnouncementsStore } from 'src/stores/announcements.js'
-import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js'
-import { useChatsStore } from 'src/stores/chats.js'
-import { useEmojiStore } from 'src/stores/emoji.js'
-import { useInstanceStore } from 'src/stores/instance.js'
-import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
-import { useInterfaceStore } from 'src/stores/interface.js'
-import { useListsStore } from 'src/stores/lists.js'
-import { useMergedConfigStore } from 'src/stores/merged_config.js'
-import { useOAuthStore } from 'src/stores/oauth.js'
-import { useSyncConfigStore } from 'src/stores/sync_config.js'
-import { useUserHighlightStore } from 'src/stores/user_highlight.js'
-
-import { revokeToken } from 'src/api/oauth.js'
-import {
- fetchFollowers,
- fetchFriends,
- fetchUser,
- fetchUserByName,
- getCaptcha,
- register,
- searchUsers,
- verifyCredentials,
-} from 'src/api/public.js'
-import {
- blockUser as apiBlockUser,
- editUserNote as apiEditUserNote,
- muteUser as apiMuteUser,
- unblockUser as apiUnblockUser,
- unmuteUser as apiUnmuteUser,
- fetchBlocks,
- fetchDomainMutes,
- fetchMutes,
- fetchUserInLists,
- fetchUserRelationship,
- followUser,
-} from 'src/api/user.js'
-
-// TODO: Unify with mergeOrAdd in statuses.js
-export const mergeOrAdd = (arr, obj, item) => {
- if (!item) {
- return false
- }
- const oldItem = obj[item.id]
- if (oldItem) {
- // We already have this, so only merge the new info.
- mergeWith(oldItem, item, mergeArrayLength)
- return { item: oldItem, new: false }
- } else {
- // This is a new item, prepare it
- arr.push(item)
- obj[item.id] = item
- return { item, new: true }
- }
-}
-
-const mergeArrayLength = (oldValue, newValue) => {
- if (Array.isArray(oldValue) && Array.isArray(newValue)) {
- oldValue.length = newValue.length
- return mergeWith(oldValue, newValue, mergeArrayLength)
- }
-}
-
-const getNotificationPermission = async () => {
- const Notification = window.Notification
-
- if (!Notification) return null
- if (Notification.permission === 'default')
- return Notification.requestPermission()
- return Notification.permission
-}
-
-const blockUser = (store, args) => {
- const id = args.id
- const expiresIn = typeof args === 'object' ? args.expiresIn : 0
-
- const predictedRelationship = store.state.relationships[id] || { id }
- store.commit('updateUserRelationship', [predictedRelationship])
- store.commit('addBlockId', id)
-
- return apiBlockUser({ id, expiresIn }).then(({ data: relationship }) => {
- store.commit('updateUserRelationship', [relationship])
- store.commit('addBlockId', id)
-
- store.commit('removeStatus', { timeline: 'friends', userId: id })
- store.commit('removeStatus', { timeline: 'public', userId: id })
- store.commit('removeStatus', {
- timeline: 'publicAndExternal',
- userId: id,
- })
- })
-}
-
-const unblockUser = (store, id) => {
- return apiUnblockUser({ id }).then(({ data: relationship }) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const removeUserFromFollowers = (store, id) => {
- return removeUserFromFollowers({ id }).then((relationship) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const editUserNote = (store, { id, comment }) => {
- return apiEditUserNote({ id, comment }).then((relationship) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const muteUser = (store, args) => {
- const id = typeof args === 'object' ? args.id : args
- const expiresIn = typeof args === 'object' ? args.expiresIn : 0
-
- const predictedRelationship = store.state.relationships[id] || { id }
- store.commit('updateUserRelationship', [predictedRelationship])
- store.commit('addMuteId', id)
-
- return apiMuteUser({
- id,
- expiresIn,
- credentials: useOAuthStore().token,
- }).then(({ data: relationship }) => {
- store.commit('updateUserRelationship', [relationship])
- store.commit('addMuteId', id)
- })
-}
-
-const unmuteUser = (store, id) => {
- const predictedRelationship = store.state.relationships[id] || { id }
- predictedRelationship.muting = false
- store.commit('updateUserRelationship', [predictedRelationship])
-
- return apiUnmuteUser({ id }).then(({ data: relationship }) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const hideReblogs = (store, userId) => {
- return followUser({
- id: userId,
- reblogs: false,
- credentials: useOAuthStore().token,
- }).then(({ data: relationship }) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const showReblogs = (store, userId) => {
- return followUser({
- id: userId,
- reblogs: true,
- credentials: useOAuthStore().token,
- }).then(({ data: relationship }) =>
- store.commit('updateUserRelationship', [relationship]),
- )
-}
-
-const muteDomain = (store, domain) => {
- return muteDomain({
- domain,
- credentials: useOAuthStore().token,
- }).then(() => store.commit('addDomainMute', domain))
-}
-
-const unmuteDomain = (store, domain) => {
- return unmuteDomain({
- domain,
- credentials: useOAuthStore().token,
- }).then(() => store.commit('removeDomainMute', domain))
-}
-
-export const mutations = {
- tagUser(state, { user: { id }, tag }) {
- const user = state.usersObject[id]
- user.tags.add(tag)
- },
- untagUser(state, { user: { id }, tag }) {
- const user = state.usersObject[id]
- user.tags.delete(tag)
- },
- updateRight(state, { user: { id }, right, value }) {
- const user = state.usersObject[id]
- const newRights = user.rights
- newRights[right] = value
- user.rights = newRights
- },
- updateUserAdminData(state, { user }) {
- const { id } = user
- const localUser = state.usersObject[id]
- localUser.adminData = user
- localUser.deactivated = !user.is_active
- localUser.tags = new Set(user.tags)
- },
- setCurrentUser(state, user) {
- state.lastLoginName = user.screen_name
- state.currentUser = mergeWith(
- state.currentUser || {},
- user,
- mergeArrayLength,
- )
- },
- clearCurrentUser(state) {
- state.currentUser = false
- state.lastLoginName = false
- },
- beginLogin(state) {
- state.loggingIn = true
- },
- endLogin(state) {
- state.loggingIn = false
- },
- saveFriendIds(state, { id, friendIds }) {
- const user = state.usersObject[id]
- user.friendIds = [...new Set([...(user.friendIds || []), ...friendIds])]
- },
- saveFollowerIds(state, { id, followerIds }) {
- const user = state.usersObject[id]
- user.followerIds = [...new Set([user.followerIds || [], ...followerIds])]
- },
- // Because frontend doesn't have a reason to keep these stuff in memory
- // outside of viewing someones user profile.
- clearFriends(state, userId) {
- const user = state.usersObject[userId]
- if (user) {
- user.friendIds = []
- }
- },
- clearFollowers(state, userId) {
- const user = state.usersObject[userId]
- if (user) {
- user.followerIds = []
- }
- },
- addNewUsers(state, users) {
- each(users, (user) => {
- if (user.relationship) {
- state.relationships[user.relationship.id] = user.relationship
- }
- const res = mergeOrAdd(state.users, state.usersObject, user)
- const item = res.item
- if (res.new && item.screen_name && !item.screen_name.includes('@')) {
- state.usersByNameObject[item.screen_name.toLowerCase()] = item
- }
- })
- },
- updateUserRelationship(state, relationships) {
- relationships.forEach((relationship) => {
- state.relationships[relationship.id] = relationship
- })
- },
- updateUserInLists(state, { id, inLists }) {
- state.usersObject[id].inLists = inLists
- },
- saveBlockIds(state, blockIds) {
- state.currentUser.blockIds = blockIds
- },
- addBlockId(state, blockId) {
- if (state.currentUser.blockIds.includes(blockId)) {
- state.currentUser.blockIds.push(blockId)
- }
- },
- setBlockIdsMaxId(state, blockIdsMaxId) {
- state.currentUser.blockIdsMaxId = blockIdsMaxId
- },
- saveMuteIds(state, muteIds) {
- state.currentUser.muteIds = muteIds
- },
- setMuteIdsMaxId(state, muteIdsMaxId) {
- state.currentUser.muteIdsMaxId = muteIdsMaxId
- },
- addMuteId(state, muteId) {
- if (state.currentUser.muteIds.includes(muteId)) {
- state.currentUser.muteIds.push(muteId)
- }
- },
- saveDomainMutes(state, domainMutes) {
- state.currentUser.domainMutes = domainMutes
- },
- addDomainMute(state, domain) {
- if (state.currentUser.domainMutes.includes(domain)) {
- state.currentUser.domainMutes.push(domain)
- }
- },
- removeDomainMute(state, domain) {
- const index = state.currentUser.domainMutes.indexOf(domain)
- if (index !== -1) {
- state.currentUser.domainMutes.splice(index, 1)
- }
- },
- setPinnedToUser(state, status) {
- const user = state.usersObject[status.user.id]
- user.pinnedStatusIds = user.pinnedStatusIds || []
- const index = user.pinnedStatusIds.indexOf(status.id)
-
- if (status.pinned && index === -1) {
- user.pinnedStatusIds.push(status.id)
- } else if (!status.pinned && index !== -1) {
- user.pinnedStatusIds.splice(index, 1)
- }
- },
- setUserForStatus(state, status) {
- status.user = state.usersObject[status.user.id]
- },
- setUserForNotification(state, notification) {
- if (notification.type !== 'follow') {
- notification.action.user = state.usersObject[notification.action.user.id]
- }
- notification.from_profile = state.usersObject[notification.from_profile.id]
- },
- setColor(state, { user: { id }, highlighted }) {
- const user = state.usersObject[id]
- user.highlight = highlighted
- },
- signUpPending(state) {
- state.signUpPending = true
- state.signUpErrors = []
- state.signUpNotice = {}
- },
- signUpSuccess(state) {
- state.signUpPending = false
- },
- signUpFailure(state, errors) {
- state.signUpPending = false
- state.signUpErrors = errors
- state.signUpNotice = {}
- },
- signUpNotice(state, notice) {
- state.signUpPending = false
- state.signUpErrors = []
- state.signUpNotice = notice
- },
-}
-
-export const getters = {
- findUser: (state) => (query) => {
- return state.usersObject[query]
- },
- findUserByName: (state) => (query) => {
- return state.usersByNameObject[query.toLowerCase()]
- },
- findUserByUrl: (state) => (query) => {
- return state.users.find(
- (u) =>
- u.statusnet_profile_url &&
- u.statusnet_profile_url.toLowerCase() === query.toLowerCase(),
- )
- },
- relationship: (state) => (id) => {
- const rel = id && state.relationships[id]
- return rel || { id, loading: true }
- },
-}
-
-export const defaultState = {
- loggingIn: false,
- lastLoginName: false,
- currentUser: false,
- users: [],
- usersObject: {},
- usersByNameObject: {},
- signUpPending: false,
- signUpErrors: [],
- signUpNotice: {},
- relationships: {},
-}
-
-const users = {
- state: defaultState,
- mutations,
- getters,
- actions: {
- async fetchUserIfMissing(store, id) {
- const user = store.getters.findUser(id)
- if (!user) {
- return store.dispatch('fetchUser', id)
- } else {
- return user
- }
- },
- updateUserAdminData(store, { userAdminData }) {
- return store
- .dispatch('fetchUserIfMissing', userAdminData.id)
- .then((user) => {
- user.adminData = userAdminData
- store.commit('addNewUsers', [user])
- return user
- })
- },
- fetchUser(store, id) {
- return fetchUser({
- id,
- credentials: useOAuthStore().token,
- })
- .then(({ data: user }) => {
- store.commit('addNewUsers', [user])
- return user
- })
- .catch((error) => {
- if (error.statusCode === 404) {
- console.warn(`User ${id} not found`)
- } else {
- throw error
- }
- })
- },
- fetchUserByName(store, name) {
- return fetchUserByName({
- name,
- credentials: useOAuthStore().token,
- }).then(({ data: user }) => {
- store.commit('addNewUsers', [user])
- return user
- })
- },
- fetchUserRelationship(store, id) {
- if (store.state.currentUser) {
- fetchUserRelationship({
- id,
- credentials: useOAuthStore().token,
- }).then(({ data: relationships }) =>
- store.commit('updateUserRelationship', relationships),
- )
- }
- },
- fetchUserInLists(store, id) {
- if (store.state.currentUser) {
- fetchUserInLists({
- id,
- credentials: useOAuthStore().token,
- }).then(({ data: inLists }) =>
- store.commit('updateUserInLists', { id, inLists }),
- )
- }
- },
- fetchBlocks(store, args) {
- const { reset } = args || {}
-
- const maxId = store.state.currentUser.blockIdsMaxId
- return fetchBlocks({
- maxId,
- credentials: useOAuthStore().token,
- }).then(({ data: blocks }) => {
- if (reset) {
- store.commit('saveBlockIds', map(blocks, 'id'))
- } else {
- map(blocks, 'id').map((id) => store.commit('addBlockId', id))
- }
- if (blocks.length) {
- store.commit('setBlockIdsMaxId', last(blocks).id)
- }
- store.commit('addNewUsers', blocks)
- return blocks
- })
- },
- blockUser(store, data) {
- return blockUser(store, data)
- },
- unblockUser(store, data) {
- return unblockUser(store, data)
- },
- removeUserFromFollowers(store, id) {
- return removeUserFromFollowers(store, id)
- },
- blockUsers(store, data = []) {
- return Promise.all(data.map((d) => blockUser(store, d)))
- },
- unblockUsers(store, data = []) {
- return Promise.all(data.map((d) => unblockUser(store, d)))
- },
- editUserNote(store, args) {
- return editUserNote(store, args)
- },
- fetchMutes(store, args) {
- const { reset } = args || {}
-
- const maxId = store.state.currentUser.muteIdsMaxId
- return fetchMutes({
- maxId,
- credentials: useOAuthStore().token,
- }).then(({ data: mutes }) => {
- if (reset) {
- store.commit('saveMuteIds', map(mutes, 'id'))
- } else {
- map(mutes, 'id').map((id) => store.commit('addMuteId', id))
- }
- if (mutes.length) {
- store.commit('setMuteIdsMaxId', last(mutes).id)
- }
- store.commit('addNewUsers', mutes)
- return mutes
- })
- },
- muteUser(store, data) {
- return muteUser(store, data)
- },
- unmuteUser(store, id) {
- return unmuteUser(store, id)
- },
- hideReblogs(store, id) {
- return hideReblogs(store, id)
- },
- showReblogs(store, id) {
- return showReblogs(store, id)
- },
- muteUsers(store, data = []) {
- return Promise.all(data.map((d) => muteUser(store, d)))
- },
- unmuteUsers(store, ids = []) {
- return Promise.all(ids.map((d) => unmuteUser(store, d)))
- },
- fetchDomainMutes(store) {
- return fetchDomainMutes({
- credentials: useOAuthStore().token,
- }).then(({ data: domainMutes }) => {
- store.commit('saveDomainMutes', domainMutes)
- return domainMutes
- })
- },
- muteDomain(store, domain) {
- return muteDomain(store, domain)
- },
- unmuteDomain(store, domain) {
- return unmuteDomain(store, domain)
- },
- muteDomains(store, domains = []) {
- return Promise.all(domains.map((domain) => muteDomain(store, domain)))
- },
- unmuteDomains(store, domain = []) {
- return Promise.all(domain.map((domain) => unmuteDomain(store, domain)))
- },
- fetchFriends({ rootState, commit }, id) {
- const user = rootState.users.usersObject[id]
- const maxId = last(user.friendIds)
- return fetchFriends({
- id,
- maxId,
- credentials: useOAuthStore().token,
- }).then(({ data: friends }) => {
- commit('addNewUsers', friends)
- commit('saveFriendIds', { id, friendIds: map(friends, 'id') })
- return friends
- })
- },
- fetchFollowers({ rootState, commit }, id) {
- const user = rootState.users.usersObject[id]
- const maxId = last(user.followerIds)
- return fetchFollowers({
- id,
- maxId,
- credentials: useOAuthStore().token,
- }).then(({ data: followers }) => {
- commit('addNewUsers', followers)
- commit('saveFollowerIds', { id, followerIds: map(followers, 'id') })
- return followers
- })
- },
- clearFriends({ commit }, userId) {
- commit('clearFriends', userId)
- },
- clearFollowers({ commit }, userId) {
- commit('clearFollowers', userId)
- },
- subscribeUser({ rootState, commit }, id) {
- return followUser({
- id,
- notify: true,
- credentials: useOAuthStore().token,
- }).then(({ data: relationship }) =>
- commit('updateUserRelationship', [relationship]),
- )
- },
- unsubscribeUser({ rootState, commit }, id) {
- return followUser({
- id,
- notify: false,
- credentials: useOAuthStore().token,
- }).then(({ data: relationship }) =>
- commit('updateUserRelationship', [relationship]),
- )
- },
- registerPushNotifications(store) {
- const token = store.state.currentUser.credentials
- const vapidPublicKey = useInstanceStore().vapidPublicKey
- const isEnabled = useMergedConfigStore().mergedConfig.webPushNotifications
- const notificationVisibility =
- useMergedConfigStore().mergedConfig.notificationVisibility
-
- registerPushNotifications(
- isEnabled,
- vapidPublicKey,
- token,
- notificationVisibility,
- )
- },
- unregisterPushNotifications(store) {
- const token = store.state.currentUser.credentials
-
- unregisterPushNotifications(token)
- },
- addNewUsers({ commit }, users) {
- commit('addNewUsers', users)
- },
- addNewStatuses(store, { statuses }) {
- const users = map(statuses, 'user')
- const retweetedUsers = compact(map(statuses, 'retweeted_status.user'))
- store.commit('addNewUsers', users)
- store.commit('addNewUsers', retweetedUsers)
-
- each(statuses, (status) => {
- // Reconnect users to statuses
- store.commit('setUserForStatus', status)
- // Set pinned statuses to user
- store.commit('setPinnedToUser', status)
- })
- each(compact(map(statuses, 'retweeted_status')), (status) => {
- // Reconnect users to retweets
- store.commit('setUserForStatus', status)
- // Set pinned retweets to user
- store.commit('setPinnedToUser', status)
- })
- },
- addNewNotifications(store, { notifications }) {
- const users = map(notifications, 'from_profile')
- const targetUsers = map(notifications, 'target').filter(Boolean)
- const notificationIds = notifications.map((_) => _.id)
- store.commit('addNewUsers', users)
- store.commit('addNewUsers', targetUsers)
-
- const notificationsObject = store.rootState.notifications.idStore
- const relevantNotifications = Object.entries(notificationsObject)
- .filter(([k]) => notificationIds.includes(k))
- .map(([, val]) => val)
-
- // Reconnect users to notifications
- each(relevantNotifications, (notification) => {
- store.commit('setUserForNotification', notification)
- })
- },
- searchUsers({ rootState, commit }, { query }) {
- return searchUsers({
- query,
- credentials: useOAuthStore().token,
- }).then(({ data: users }) => {
- commit('addNewUsers', users)
- return users
- })
- },
- async signUp(store, userInfo) {
- const oauthStore = useOAuthStore()
- store.commit('signUpPending')
-
- try {
- const token = await oauthStore.ensureAppToken()
- const { data } = await register({
- credentials: token,
- params: { ...userInfo },
- })
-
- if (data.access_token) {
- store.commit('signUpSuccess')
- oauthStore.setToken(data.access_token)
- await store.dispatch('loginUser', data.access_token)
- return 'ok'
- } else {
- // Request succeeded, but user cannot login yet.
- store.commit('signUpNotice', data)
- return 'request_sent'
- }
- } catch (e) {
- const errors = e.message
- store.commit('signUpFailure', errors)
- throw e
- }
- },
- getCaptcha(store) {
- return getCaptcha({
- credentials: useOAuthStore().token,
- }).then(({ data }) => data)
- },
-
- logout(store) {
- const oauth = useOAuthStore()
-
- // NOTE: No need to verify the app still exists, because if it doesn't,
- // the token will be invalid too
- return oauth
- .ensureApp()
- .then((app) => {
- const params = {
- app,
- instance: useInstanceStore().server,
- token: oauth.userToken,
- }
-
- return revokeToken(params)
- })
- .then(() => {
- store.commit('clearCurrentUser')
- store.dispatch('disconnectFromSocket')
- store.dispatch('stopFetchingTimeline', 'friends')
- store.dispatch('stopFetchingNotifications')
- useListsStore().stopFetching()
- useBookmarkFoldersStore().stopFetching()
- store.dispatch('stopFetchingFollowRequests')
- store.commit('clearNotifications')
- store.commit('resetStatuses')
- useChatsStore().resetChats()
- oauth.clearToken()
- Cookies.remove('__Host-pleroma_key', { path: '/' })
- useInterfaceStore().setLastTimeline('public-timeline')
- useInterfaceStore().setLayoutWidth(windowWidth())
- useInterfaceStore().setLayoutHeight(windowHeight())
- })
- },
- loginUser(store, accessToken) {
- return new Promise((resolve, reject) => {
- const commit = store.commit
- const dispatch = store.dispatch
-
- commit('beginLogin')
-
- verifyCredentials({
- credentials: useOAuthStore().token,
- })
- .then(({ data: user }) => {
- // user.credentials = userCredentials
- user.credentials = accessToken
- user.blockIds = []
- user.muteIds = []
- user.domainMutes = []
- commit('setCurrentUser', user)
-
- useSyncConfigStore()
- .initSyncConfig(user)
- .then(() => {
- useInterfaceStore()
- .applyTheme()
- .catch((e) => {
- console.error('Error setting theme', e)
- })
- })
- useUserHighlightStore().initUserHighlight(user)
- commit('addNewUsers', [user])
-
- useEmojiStore().fetchEmoji()
-
- getNotificationPermission().then((permission) =>
- useInterfaceStore().setNotificationPermission(permission),
- )
-
- // Do server-side storage migrations
-
- // Debug snippet to clean up storage and reset migrations
- /*
- // Reset wordfilter
- Object.keys(
- useSyncConfigStore().prefsStorage.simple.muteFilters
- ).forEach(key => {
- useSyncConfigStore().unsetSimplePrefAndSave({ path: 'muteFilters.' + key, value: null })
- })
-
- // Reset flag to 0 to re-run migrations
- useSyncConfigStore().setFlag({ flag: 'configMigration', value: 0 })
- /**/
-
- if (user.token) {
- dispatch('setWsToken', user.token)
-
- // Initialize the shout socket.
- dispatch('initializeSocket')
- }
-
- const startPolling = () => {
- // Start getting fresh posts.
- dispatch('startFetchingTimeline', { timeline: 'friends' })
-
- // Start fetching notifications
- dispatch('startFetchingNotifications')
-
- if (useInstanceCapabilitiesStore().pleromaChatMessagesAvailable) {
- // Start fetching chats
- dispatch('startFetchingChats')
- }
- }
-
- useListsStore().startFetching()
- useBookmarkFoldersStore().startFetching()
-
- if (user.locked) {
- dispatch('startFetchingFollowRequests')
- }
-
- if (useMergedConfigStore().mergedConfig.useStreamingApi) {
- dispatch('fetchTimeline', {
- timeline: 'friends',
- sinceId: null,
- })
- dispatch('fetchNotifications', { sinceId: null })
- dispatch('enableMastoSockets', true)
- .catch((error) => {
- console.error(
- 'Failed initializing MastoAPI Streaming socket',
- error,
- )
- })
- .then(() => {
- dispatch('fetchChats', { latest: true })
- setTimeout(
- () => dispatch('setNotificationsSilence', false),
- 10000,
- )
- })
- } else {
- startPolling()
- }
-
- // Start fetching things that don't need to block the UI
- useAnnouncementsStore().startFetchingAnnouncements()
-
- dispatch('fetchMutes')
- dispatch('loadDrafts')
-
- useInterfaceStore().setLayoutWidth(windowWidth())
- useInterfaceStore().setLayoutHeight(windowHeight())
-
- // Fetch our friends
- fetchFriends({ id: user.id }).then(({ data: friends }) =>
- commit('addNewUsers', friends),
- )
- commit('endLogin')
- resolve()
- })
- .catch((error) => {
- console.error(error)
-
- // Authentication failed
- commit('endLogin')
-
- // remove authentication token on client/authentication errors
- if ([400, 401, 403, 422].includes(error.statusCode)) {
- useOAuthStore().clearToken()
- }
-
- commit('endLogin')
- if (error.tatusCode === 401) {
- throw new Error('Wrong username or password', error)
- } else {
- throw new Error('An error occurred, please try again', error)
- }
- })
- })
- },
- },
-}
-
-export default users
diff --git a/src/services/chat_utils/chat_utils.js b/src/services/chat_utils/chat_utils.js
index bc02981cd..d99c17ed8 100644
--- a/src/services/chat_utils/chat_utils.js
+++ b/src/services/chat_utils/chat_utils.js
@@ -1,9 +1,10 @@
import { showDesktopNotification } from '../desktop_notification_utils/desktop_notification_utils.js'
+import { useUsersStore } from 'src/stores/users.js'
+
export const maybeShowChatNotification = (chat) => {
if (!chat.lastMessage) return
- if (window.vuex.state.users.currentUser.id === chat.lastMessage.account_id)
- return
+ if (useUsersStore().currentUser.id === chat.lastMessage.account_id) return
const opts = {
tag: chat.lastMessage.id,
diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js
index 5b8fa5b57..5d35b9699 100644
--- a/src/services/entity_normalizer/entity_normalizer.service.js
+++ b/src/services/entity_normalizer/entity_normalizer.service.js
@@ -27,6 +27,7 @@ export const parseUser = (data) => {
output.screen_name = data.acct
output.fqn = data.fqn
+ output.url = data.url
output.statusnet_profile_url = data.url
if (Object.hasOwn(data, 'mute_expires_at')) {
diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js
index 9a26bd12f..af000a40e 100644
--- a/src/services/status_poster/status_poster.service.js
+++ b/src/services/status_poster/status_poster.service.js
@@ -1,5 +1,7 @@
import { map } from 'lodash'
+import { useUsersStore } from 'src/stores/users.js'
+
import {
editStatus as apiEditStatus,
postStatus as apiPostStatus,
@@ -24,7 +26,7 @@ const postStatus = ({
const mediaIds = map(media, 'id')
return apiPostStatus({
- credentials: store.state.users.currentUser.credentials,
+ credentials: useUsersStore().currentUser.credentials,
status,
spoilerText,
visibility,
@@ -63,7 +65,7 @@ const editStatus = ({
return apiEditStatus({
id: statusId,
- credentials: store.state.users.currentUser.credentials,
+ credentials: useUsersStore().currentUser.credentials,
status,
spoilerText,
sensitive,
@@ -90,12 +92,12 @@ const editStatus = ({
}
const uploadMedia = ({ store, formData }) => {
- const credentials = store.state.users.currentUser.credentials
+ const credentials = useUsersStore().currentUser.credentials
return apiUploadMedia({ credentials, formData }).then(({ data }) => data)
}
const setMediaDescription = ({ store, id, description }) => {
- const credentials = store.state.users.currentUser.credentials
+ const credentials = useUsersStore().currentUser.credentials
return apiSetMediaDescription({ credentials, id, description }).then(
({ data }) => data,
)
diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js
index 80dbc75d0..647ed90ef 100644
--- a/src/services/timeline_fetcher/timeline_fetcher.service.js
+++ b/src/services/timeline_fetcher/timeline_fetcher.service.js
@@ -5,6 +5,7 @@ import { promiseInterval } from '../promise_interval/promise_interval.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
+import { useUsersStore } from 'src/stores/users.js'
import { fetchTimeline } from 'src/api/timelines.js'
@@ -48,7 +49,7 @@ const fetchAndUpdate = ({
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
const { hideMutedPosts, replyVisibility } =
useMergedConfigStore().mergedConfig
- const loggedIn = !!rootState.users.currentUser
+ const loggedIn = !!useUsersStore().currentUser
if (older) {
// When minId = 0 we need to fetch without maxId param
diff --git a/src/stores/announcements.js b/src/stores/announcements.js
index b09655755..5110bd565 100644
--- a/src/stores/announcements.js
+++ b/src/stores/announcements.js
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { dismissAnnouncement, getAnnouncements } from 'src/api/user.js'
@@ -16,7 +17,7 @@ export const useAnnouncementsStore = defineStore('announcements', {
}),
getters: {
unreadAnnouncementCount() {
- if (!window.vuex.state.users.currentUser) {
+ if (!useUsersStore().currentUser) {
return 0
}
@@ -30,7 +31,7 @@ export const useAnnouncementsStore = defineStore('announcements', {
async fetchAnnouncements() {
if (!this.supportsAnnouncements) return
- const currentUser = window.vuex.state.users.currentUser
+ const currentUser = useUsersStore().currentUser
const isAdmin =
currentUser &&
currentUser.privileges.has('announcements_manage_announcements')
diff --git a/src/stores/auth_flow.js b/src/stores/auth_flow.js
index 64df30f2a..0841dc558 100644
--- a/src/stores/auth_flow.js
+++ b/src/stores/auth_flow.js
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
const PASSWORD_STRATEGY = 'password'
const TOKEN_STRATEGY = 'token'
@@ -63,7 +64,7 @@ export const useAuthFlowStore = defineStore('authFlow', {
},
async login({ access_token: accessToken }) {
useOAuthStore().setToken(accessToken)
- await window.vuex.dispatch('loginUser', accessToken, { root: true })
+ useUsersStore().loginUser(accessToken, { root: true })
this.resetState()
},
},
diff --git a/src/stores/emoji.js b/src/stores/emoji.js
index 8135a483e..1471f3dfb 100644
--- a/src/stores/emoji.js
+++ b/src/stores/emoji.js
@@ -3,6 +3,7 @@ import { defineStore } from 'pinia'
import { useInstanceStore } from 'src/stores/instance.js'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { listEmojiPacks } from 'src/api/public.js'
import { ensureFinalFallback } from 'src/i18n/languages.js'
@@ -194,7 +195,7 @@ export const useEmojiStore = defineStore('emoji', {
},
async getAdminPacks(instance, listFunction) {
- const currentUser = window.vuex.state.users.currentUser
+ const currentUser = useUsersStore().currentUser
if (!currentUser.rights.admin) return
diff --git a/src/stores/instance.js b/src/stores/instance.js
index 02edd1235..123f0b819 100644
--- a/src/stores/instance.js
+++ b/src/stores/instance.js
@@ -13,6 +13,7 @@ import {
} from '../modules/default_config_state.js'
import { useInterfaceStore } from 'src/stores/interface.js'
+import { useUsersStore } from 'src/stores/users.js'
import { fetchKnownDomains } from 'src/api/public.js'
@@ -212,7 +213,7 @@ export const useInstanceStore = defineStore('instance', {
async getKnownDomains() {
try {
const { data } = await fetchKnownDomains({
- credentials: window.vuex.state.users.currentUser.credentials,
+ credentials: useUsersStore().currentUser.credentials,
})
this.knownDomains = data
} catch (e) {
diff --git a/src/stores/interface.js b/src/stores/interface.js
index 7be72a8d2..6eede1d3a 100644
--- a/src/stores/interface.js
+++ b/src/stores/interface.js
@@ -10,6 +10,7 @@ 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 { useSyncConfigStore } from 'src/stores/sync_config.js'
+import { useUsersStore } from 'src/stores/users.js'
import {
CURRENT_VERSION,
@@ -245,7 +246,7 @@ export const useInterfaceStore = defineStore('interface', {
const mobileLayout = width <= 800
const normalOrMobile = mobileLayout ? 'mobile' : 'normal'
const { thirdColumnMode } = useMergedConfigStore().mergedConfig
- if (thirdColumnMode === 'none' || !window.vuex.state.users.currentUser) {
+ if (thirdColumnMode === 'none' || !useUsersStore().currentUser) {
this.layoutType = normalOrMobile
} else {
const wideLayout = width >= 1300
diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js
index 9464ffb68..17a60d3ef 100644
--- a/src/stores/sync_config.js
+++ b/src/stores/sync_config.js
@@ -21,6 +21,7 @@ import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/updat
import { useLocalConfigStore } from 'src/stores/local_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { updateProfileJSON } from 'src/api/user.js'
import { storage } from 'src/lib/storage.js'
@@ -807,7 +808,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
pushSyncConfig({ force = false } = {}) {
const needPush = this.dirty || force
if (!needPush) return
- this.updateCache({ username: window.vuex.state.users.currentUser.fqn })
+ this.updateCache({ username: useUsersStore().currentUser.fqn })
const params = { pleroma_settings_store: { 'pleroma-fe': this.cache } }
updateProfileJSON({
params,
diff --git a/src/stores/user_highlight.js b/src/stores/user_highlight.js
index 3cd3bfe7d..a4cbacd6e 100644
--- a/src/stores/user_highlight.js
+++ b/src/stores/user_highlight.js
@@ -10,6 +10,7 @@ import { defineStore } from 'pinia'
import { toRaw } from 'vue'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useUsersStore } from 'src/stores/users.js'
import { updateProfileJSON } from 'src/api/user.js'
import { storage } from 'src/lib/storage.js'
@@ -328,7 +329,7 @@ export const useUserHighlightStore = defineStore('user_highlight', {
pushHighlight({ force = false } = {}) {
const needPush = this.dirty || force
if (!needPush) return
- this.updateCache({ username: window.vuex.state.users.currentUser.fqn })
+ this.updateCache({ username: useUsersStore().currentUser.fqn })
const params = {
pleroma_settings_store: { user_highlight: this.cache },
}
diff --git a/src/stores/users.js b/src/stores/users.js
index 7d1255569..d03348bcb 100644
--- a/src/stores/users.js
+++ b/src/stores/users.js
@@ -59,18 +59,16 @@ const getNotificationPermission = async () => {
return Notification.permission
}
-export const defaultState = {
- loggingIn: false,
- lastLoginName: null,
- currentUser: null,
- users: new Map(),
- usersByName: new Map(),
- usersByURL: new Map(),
- relationships: new Map(),
-}
-
export const useUsersStore = defineStore('users', {
- state: defaultState,
+ state: () => ({
+ loggingIn: false,
+ lastLoginName: null,
+ currentUser: null,
+ users: new Map(),
+ usersByName: new Map(),
+ usersByURL: new Map(),
+ relationships: new Map(),
+ }),
getters: {
loggedIn: (state) => !!state.currentUser,
findUser: (state) => (query) => {
@@ -141,7 +139,7 @@ export const useUsersStore = defineStore('users', {
},
addNewUsers(users, timestamp) {
users.forEach((user) => {
- const existing = users.get(user.id) ?? {}
+ const existing = this.users.get(user.id) ?? {}
const { relationship, ...old } = existing
const { relationshop, ...neu } = user
@@ -150,6 +148,10 @@ export const useUsersStore = defineStore('users', {
this.users.set(user.id, newUser)
this.usersByName.set(user.screen_name.toLowerCase(), newUser)
this.usersByURL.set(user.url.toLowerCase(), newUser)
+
+ if (user.id === this.currentUser.id) {
+ this.currentUser = newUser
+ }
})
},
updateUserRelationship(relationships) {
diff --git a/test/unit/specs/components/post_status_form.spec.js b/test/unit/specs/components/post_status_form.spec.js
index f89102504..50b7471f2 100644
--- a/test/unit/specs/components/post_status_form.spec.js
+++ b/test/unit/specs/components/post_status_form.spec.js
@@ -6,6 +6,7 @@ import { mountOpts } from '../../../fixtures/setup_test'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
+import { useUsersStore } from 'src/stores/users.js'
const currentUser = {
id: 'current-user',
@@ -35,7 +36,7 @@ const replyMountOpts = (props) =>
mountOpts({
props,
afterStore(store) {
- store.state.users.currentUser = currentUser
+ useUsersStore().currentUser = currentUser
store.state.statuses.allStatusesObject = {
[repliedStatus.id]: repliedStatus,
}