From 94b96bd53493789bf96d3f99f6f796d5ad0b56aa Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 18 Mar 2023 17:04:47 +0800 Subject: [PATCH] Fix wrong "info", when viewing remote accounts --- src/components/account-info.jsx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/components/account-info.jsx b/src/components/account-info.jsx index b4b92c43..f53f6f41 100644 --- a/src/components/account-info.jsx +++ b/src/components/account-info.jsx @@ -406,6 +406,8 @@ function RelatedActions({ info, instance, authenticated }) { endorsed, } = relationship || {}; + const [currentInfo, setCurrentInfo] = useState(null); + useEffect(() => { if (info) { const currentAccount = store.session.get('currentAccount'); @@ -424,7 +426,10 @@ function RelatedActions({ info, instance, authenticated }) { resolve: true, }); console.log('🥏 Fetched account from logged-in instance', results); - currentID = results.accounts[0].id; + if (results.accounts.length) { + currentID = results.accounts[0].id; + setCurrentInfo(results.accounts[0]); + } } catch (e) { console.error(e); } @@ -544,7 +549,7 @@ function RelatedActions({ info, instance, authenticated }) { onClick={() => { states.showCompose = { draftStatus: { - status: `@${acct} `, + status: `@${currentInfo?.acct || acct} `, }, }; }} @@ -606,7 +611,9 @@ function RelatedActions({ info, instance, authenticated }) { (async () => { try { const newRelationship = - await currentMasto.v1.accounts.unmute(id); + await currentMasto.v1.accounts.unmute( + currentInfo?.id || id, + ); console.log('unmuting', newRelationship); setRelationship(newRelationship); setRelationshipUIState('default'); @@ -646,9 +653,12 @@ function RelatedActions({ info, instance, authenticated }) { (async () => { try { const newRelationship = - await currentMasto.v1.accounts.mute(id, { - duration, - }); + await currentMasto.v1.accounts.mute( + currentInfo?.id || id, + { + duration, + }, + ); console.log('muting', newRelationship); setRelationship(newRelationship); setRelationshipUIState('default'); @@ -679,14 +689,18 @@ function RelatedActions({ info, instance, authenticated }) { try { if (blocking) { const newRelationship = - await currentMasto.v1.accounts.unblock(id); + await currentMasto.v1.accounts.unblock( + currentInfo?.id || id, + ); console.log('unblocking', newRelationship); setRelationship(newRelationship); setRelationshipUIState('default'); showToast(`Unblocked @${username}`); } else { const newRelationship = - await currentMasto.v1.accounts.block(id); + await currentMasto.v1.accounts.block( + currentInfo?.id || id, + ); console.log('blocking', newRelationship); setRelationship(newRelationship); setRelationshipUIState('default');