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':