diff options
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/models/session.ts | 43 | ||||
-rw-r--r-- | src/state/models/shell-ui.ts | 6 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/state/models/session.ts b/src/state/models/session.ts index b15c866f4..b79283be1 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -1,4 +1,4 @@ -import {makeAutoObservable} from 'mobx' +import {makeAutoObservable, runInAction} from 'mobx' import { AtpAgent, AtpSessionEvent, @@ -368,4 +368,45 @@ export class SessionModel { this.clearSessionTokens() this.rootStore.clearAllSessionState() } + + /** + * Removes an account from the list of stored accounts. + */ + removeAccount(handle: string) { + this.accounts = this.accounts.filter(acc => acc.handle !== handle) + } + + /** + * Reloads the session from the server. Useful when account details change, like the handle. + */ + async reloadFromServer() { + const sess = this.currentSession + if (!sess) { + return + } + const res = await this.rootStore.api.app.bsky.actor + .getProfile({actor: sess.did}) + .catch(_e => undefined) + if (res?.success) { + const updated = { + ...sess, + handle: res.data.handle, + displayName: res.data.displayName, + aviUrl: res.data.avatar, + } + runInAction(() => { + this.accounts = [ + updated, + ...this.accounts.filter( + account => + !( + account.service === updated.service && + account.did === updated.did + ), + ), + ] + }) + await this.rootStore.me.load() + } + } } diff --git a/src/state/models/shell-ui.ts b/src/state/models/shell-ui.ts index 0dad2bd9e..68d9cd3d0 100644 --- a/src/state/models/shell-ui.ts +++ b/src/state/models/shell-ui.ts @@ -51,6 +51,11 @@ export interface RepostModal { isReposted: boolean } +export interface ChangeHandleModal { + name: 'change-handle' + onChanged: () => void +} + export type Modal = | ConfirmModal | EditProfileModal @@ -60,6 +65,7 @@ export type Modal = | CropImageModal | DeleteAccountModal | RepostModal + | ChangeHandleModal interface LightboxModel {} |