Compare hosts in findAccountByUsername, fixes #730
This commit is contained in:
parent
079736e199
commit
c3da48ebf4
1 changed files with 24 additions and 2 deletions
|
@ -47,14 +47,36 @@ export const makeGetAccount = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAccountByUsername = (state, username) => {
|
const findAccountsByUsername = (state, username) => {
|
||||||
const accounts = state.get('accounts');
|
const accounts = state.get('accounts');
|
||||||
|
|
||||||
return accounts.find(account => {
|
return accounts.filter(account => {
|
||||||
return username.toLowerCase() === account.getIn(['acct'], '').toLowerCase();
|
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 => {
|
const toServerSideType = columnType => {
|
||||||
switch (columnType) {
|
switch (columnType) {
|
||||||
case 'home':
|
case 'home':
|
||||||
|
|
Loading…
Reference in a new issue