From c3da48ebf4d58a1371b5c119815069576a2b017c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 7 Oct 2021 14:43:14 -0500 Subject: [PATCH] Compare hosts in findAccountByUsername, fixes #730 --- app/soapbox/selectors/index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/soapbox/selectors/index.js b/app/soapbox/selectors/index.js index 4520ee40e..b382957ee 100644 --- a/app/soapbox/selectors/index.js +++ b/app/soapbox/selectors/index.js @@ -47,14 +47,36 @@ export const makeGetAccount = () => { }); }; -export const findAccountByUsername = (state, username) => { +const findAccountsByUsername = (state, username) => { const accounts = state.get('accounts'); - return accounts.find(account => { + return accounts.filter(account => { return username.toLowerCase() === account.getIn(['acct'], '').toLowerCase(); }); }; +export const findAccountByUsername = (state, username) => { + const accounts = findAccountsByUsername(state, username); + + if (accounts.size > 1) { + const me = state.get('me'); + const meURL = state.getIn(['accounts', me, 'url']); + + return accounts.find(account => { + try { + // If more than one account has the same username, try matching its host + const { host } = new URL(account.get('url')); + const { host: meHost } = new URL(meURL); + return host === meHost; + } catch { + return false; + } + }); + } else { + return accounts.first(); + } +}; + const toServerSideType = columnType => { switch (columnType) { case 'home':