From 55f5ae6a6cdcf414e38fabd4e30f93fd82be0169 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 14 Aug 2026 19:38:37 +0300 Subject: [PATCH] better handling of logged-out state --- src/App.js | 2 +- src/components/desktop_nav/desktop_nav.js | 2 +- src/components/mobile_nav/mobile_nav.js | 2 +- .../settings_modal/tabs/security_tab/security_tab.js | 4 ++-- src/components/status/status.js | 4 ++-- src/components/status_action_buttons/buttons_definitions.js | 5 +++-- src/stores/statuses.js | 4 ++-- src/stores/streaming.js | 4 +++- src/stores/users.js | 5 ++--- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/App.js b/src/App.js index 2854f7dfc..ed3d43e4a 100644 --- a/src/App.js +++ b/src/App.js @@ -155,7 +155,7 @@ export default { ] }, userBackground() { - return this.currentUser.background_image + return this.currentUser?.background_image }, foreignProfileBackground() { return ( diff --git a/src/components/desktop_nav/desktop_nav.js b/src/components/desktop_nav/desktop_nav.js index 8252ddf2b..f65186991 100644 --- a/src/components/desktop_nav/desktop_nav.js +++ b/src/components/desktop_nav/desktop_nav.js @@ -139,7 +139,7 @@ export default { }, doLogout() { this.$router.replace('/main/public') - this.$store.dispatch('logout') + useUsersStore().logout() this.hideConfirmLogout() }, onSearchBarToggled(hidden) { diff --git a/src/components/mobile_nav/mobile_nav.js b/src/components/mobile_nav/mobile_nav.js index 9a4c4c61d..80cfc5326 100644 --- a/src/components/mobile_nav/mobile_nav.js +++ b/src/components/mobile_nav/mobile_nav.js @@ -145,7 +145,7 @@ const MobileNav = { }, doLogout() { this.$router.replace('/main/public') - this.$store.dispatch('logout') + useUsersStore().logout() this.hideConfirmLogout() }, markNotificationsAsSeen() { diff --git a/src/components/settings_modal/tabs/security_tab/security_tab.js b/src/components/settings_modal/tabs/security_tab/security_tab.js index b30cd2f13..b0b72a4e9 100644 --- a/src/components/settings_modal/tabs/security_tab/security_tab.js +++ b/src/components/settings_modal/tabs/security_tab/security_tab.js @@ -80,7 +80,7 @@ const SecurityTab = { password: this.deleteAccountConfirmPasswordInput, }).then(({ data: res }) => { if (res.status === 'success') { - this.$store.dispatch('logout') + useUsersStore().logout() this.$router.push({ name: 'root' }) } else { this.deleteAccountError = res.error @@ -172,7 +172,7 @@ const SecurityTab = { }) }, logout() { - this.$store.dispatch('logout') + useUsersStore().logout() this.$router.replace('/') }, revokeToken(id) { diff --git a/src/components/status/status.js b/src/components/status/status.js index 28c7e040f..c88d120db 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -299,11 +299,11 @@ const Status = { }, muted() { if (this.ignoreMute) return false - if (this.statusoid.user.id === this.currentUser.id) return false + if (this.statusoid.user.id === this.currentUser?.id) return false return !this.unmuted && !this.shouldNotMute && this.muteReasons.length > 0 }, userIsMuted() { - if (this.statusoid.user.id === this.currentUser.id) return false + if (this.statusoid.user.id === this.currentUser?.id) return false const { status } = this const { reblog } = status const relationship = useUsersStore().relationship(status.user.id) diff --git a/src/components/status_action_buttons/buttons_definitions.js b/src/components/status_action_buttons/buttons_definitions.js index b13bed033..47b1baaf2 100644 --- a/src/components/status_action_buttons/buttons_definitions.js +++ b/src/components/status_action_buttons/buttons_definitions.js @@ -35,9 +35,10 @@ export const BUTTONS = [ name: 'retweet', label: ({ status }) => status.repeated ? 'tool_tip.unrepeat' : 'tool_tip.repeat', - icon({ status, currentUser }) { + icon({ status, loggedIn, currentUser }) { if ( - currentUser.id !== status.user.id && + loggedIn && + status.user.id !== currentUser.id && PRIVATE_SCOPES.has(status.visibility) ) { return 'lock' diff --git a/src/stores/statuses.js b/src/stores/statuses.js index fa1198a93..9897410a5 100644 --- a/src/stores/statuses.js +++ b/src/stores/statuses.js @@ -286,7 +286,7 @@ export const useStatusesStore = defineStore('statuses', { // repeats stats can be incorrect based on polling condition, let's update them using the most recent data newStatus.repeat_num = newStatus.rebloggedBy.length newStatus.repeated = !!newStatus.rebloggedBy.find( - ({ id }) => currentUser.id === id, + ({ id }) => currentUser?.id === id, ) }, addFavs({ id, favoritedByUsers }) { @@ -296,7 +296,7 @@ export const useStatusesStore = defineStore('statuses', { // favorites stats can be incorrect based on polling condition, let's update them using the most recent data newStatus.fave_num = newStatus.favoritedBy.length newStatus.favorited = !!newStatus.favoritedBy.find( - ({ id }) => currentUser.id === id, + ({ id }) => currentUser?.id === id, ) }, addEmojiReactionsBy({ id, emojiReactions }) { diff --git a/src/stores/streaming.js b/src/stores/streaming.js index 7038a709c..3ae00fb32 100644 --- a/src/stores/streaming.js +++ b/src/stores/streaming.js @@ -96,7 +96,9 @@ export const useStreamingStore = defineStore('streaming', { const { stream } = subscriber this.subscribers.delete(subscriber) - this.subscriptions.get(stream.name).delete(stream.argument) + if (stream) { + this.subscriptions.get(stream.name).delete(stream.argument) + } if (this.state === WSConnectionStatus.JOINED) { this.socket.unsubscribe(...this.getSubArgs(stream)) diff --git a/src/stores/users.js b/src/stores/users.js index 1702e4f80..6a2ed8a8a 100644 --- a/src/stores/users.js +++ b/src/stores/users.js @@ -190,7 +190,7 @@ export const useUsersStore = defineStore('users', { this.usersByURL.set(user.url.toLowerCase(), reactive) } - if (user.id === this.currentUser.id) { + if (user.id === this.currentUser?.id) { this.currentUser = reactive } @@ -647,11 +647,10 @@ export const useUsersStore = defineStore('users', { }) .then(() => { this.clearCurrentUser() - store.dispatch('stopFetchingNotifications') + useNotificationsStore().deactivate() useListsStore().stopFetching() useBookmarkFoldersStore().stopFetching() store.dispatch('stopFetchingFollowRequests') - store.commit('clearNotifications') useTimelinesStore().deactivateAll() useStatusesStore().resetStatuses() useNotificationsStore().clearNotifications()