diff --git a/src/components/account-info.jsx b/src/components/account-info.jsx index da2c399b..af30aaca 100644 --- a/src/components/account-info.jsx +++ b/src/components/account-info.jsx @@ -12,6 +12,7 @@ import shortenNumber from '../utils/shorten-number'; import showToast from '../utils/show-toast'; import states, { hideAllModals } from '../utils/states'; import store from '../utils/store'; +import { updateAccount } from '../utils/store-utils'; import AccountBlock from './account-block'; import Avatar from './avatar'; @@ -483,6 +484,12 @@ function RelatedActions({ info, instance, authenticated }) { } }, [info, authenticated]); + useEffect(() => { + if (info && isSelf) { + updateAccount(info); + } + }, [info, isSelf]); + const loading = relationshipUIState === 'loading'; const menuInstanceRef = useRef(null); diff --git a/src/utils/store-utils.js b/src/utils/store-utils.js index 059727e1..f624f9cd 100644 --- a/src/utils/store-utils.js +++ b/src/utils/store-utils.js @@ -34,6 +34,25 @@ export function saveAccount(account) { store.session.set('currentAccount', account.info.id); } +export function updateAccount(accountInfo) { + // Only update if displayName or avatar or avatar_static is different + const accounts = store.local.getJSON('accounts') || []; + const acc = accounts.find((a) => a.info.id === accountInfo.id); + if (acc) { + if ( + acc.info.displayName !== accountInfo.displayName || + acc.info.avatar !== accountInfo.avatar || + acc.info.avatar_static !== accountInfo.avatar_static + ) { + acc.info = { + ...acc.info, + ...accountInfo, + }; + store.local.setJSON('accounts', accounts); + } + } +} + let currentInstance = null; export function getCurrentInstance() { if (currentInstance) return currentInstance;