2022-02-28 12:15:09 -08:00
|
|
|
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2022-02-26 16:13:35 -08:00
|
|
|
|
2022-04-01 17:35:57 -07:00
|
|
|
import type { Account } from 'soapbox/types/entities';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-03-31 15:00:31 -07:00
|
|
|
const getDomainFromURL = (account: Account): string => {
|
2022-02-26 16:13:35 -08:00
|
|
|
try {
|
2022-03-31 15:00:31 -07:00
|
|
|
const url = account.url;
|
2022-02-26 16:13:35 -08:00
|
|
|
return new URL(url).host;
|
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 15:00:31 -07:00
|
|
|
export const getDomain = (account: Account): string => {
|
|
|
|
const domain = account.acct.split('@')[1];
|
2022-02-26 16:13:35 -08:00
|
|
|
return domain ? domain : getDomainFromURL(account);
|
|
|
|
};
|
|
|
|
|
2022-04-24 12:28:07 -07:00
|
|
|
export const getBaseURL = (account: Account): string => {
|
2022-02-26 16:13:35 -08:00
|
|
|
try {
|
2022-04-24 12:28:07 -07:00
|
|
|
return new URL(account.url).origin;
|
2022-02-26 16:13:35 -08:00
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
export const getAcct = (account: Account, displayFqn: boolean): string => (
|
|
|
|
displayFqn === true ? account.fqn : account.acct
|
2022-02-26 16:13:35 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getFollowDifference = (state: ImmutableMap<string, any>, accountId: string, type: string): number => {
|
|
|
|
const items: any = state.getIn(['user_lists', type, accountId, 'items'], ImmutableOrderedSet());
|
|
|
|
const counter: number = Number(state.getIn(['accounts_counters', accountId, `${type}_count`], 0));
|
|
|
|
return Math.max(counter - items.size, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isLocal = (account: ImmutableMap<string, any>): boolean => {
|
|
|
|
const domain: string = account.get('acct').split('@')[1];
|
|
|
|
return domain === undefined ? true : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isRemote = (account: ImmutableMap<string, any>): boolean => !isLocal(account);
|