nolanlawson/pinafore

Disable push notifications when logging out of instance

nolanlawson opened this issue · 0 comments

As far as I can tell, we don't unsubscribe from push notifications when you log out of an instance:

export async function logOutOfInstance (instanceName, message) {
message = message || formatIntl('intl.loggedOutOfInstance', { instance: instanceName })
const {
composeData,
currentInstance,
customEmoji,
instanceInfos,
instanceLists,
instanceThemes,
loggedInInstances,
loggedInInstancesInOrder,
verifyCredentials
} = store.get()
loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1)
const newInstance = instanceName === currentInstance ? loggedInInstancesInOrder[0] : currentInstance
const objectsToClear = [
composeData,
customEmoji,
instanceInfos,
instanceLists,
instanceThemes,
loggedInInstances,
verifyCredentials
]
for (const obj of objectsToClear) {
delete obj[instanceName]
}
store.set({
composeData,
currentInstance: newInstance,
customEmoji,
instanceInfos,
instanceLists,
instanceThemes,
loggedInInstances,
loggedInInstancesInOrder,
queryInSearch: '',
searchResults: null,
timelineInitialized: false,
timelinePreinitialized: false,
verifyCredentials
})
store.clearTimelineDataForInstance(instanceName)
store.clearAutosuggestDataForInstance(instanceName)
store.save()
const { virtualListStore } = await importVirtualListStore()
virtualListStore.clearRealmByPrefix(currentInstance + '/') // TODO: this is a hacky way to clear the vlist cache
toast.say(message)
const { enableGrayscale } = store.get()
switchToTheme(instanceThemes[newInstance], enableGrayscale)
/* no await */ database.clearDatabaseForInstance(instanceName)
goto('/settings/instances')
}

I'm surprised we haven't gotten a bug about this, though, so I could be wrong. Maybe it "just works" somehow already.