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
|
|
|
);
|
|
|
|
|
2022-06-19 11:38:51 -07:00
|
|
|
export const isLocal = (account: Account): boolean => {
|
|
|
|
const domain: string = account.acct.split('@')[1];
|
2022-02-26 16:13:35 -08:00
|
|
|
return domain === undefined ? true : false;
|
|
|
|
};
|
|
|
|
|
2022-06-19 11:38:51 -07:00
|
|
|
export const isRemote = (account: Account): boolean => !isLocal(account);
|
2022-12-12 15:08:33 -08:00
|
|
|
|
|
|
|
/** Default header filenames from various backends */
|
|
|
|
const DEFAULT_HEADERS = [
|
|
|
|
'/headers/original/missing.png', // Mastodon
|
|
|
|
'/images/banner.png', // Pleroma
|
|
|
|
];
|
|
|
|
|
|
|
|
/** Check if the avatar is a default avatar */
|
|
|
|
export const isDefaultHeader = (url: string) => {
|
|
|
|
return DEFAULT_HEADERS.some(header => url.endsWith(header));
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Default avatar filenames from various backends */
|
|
|
|
const DEFAULT_AVATARS = [
|
|
|
|
'/avatars/original/missing.png', // Mastodon
|
|
|
|
'/images/avi.png', // Pleroma
|
|
|
|
];
|
|
|
|
|
|
|
|
/** Check if the avatar is a default avatar */
|
|
|
|
export const isDefaultAvatar = (url: string) => {
|
|
|
|
return DEFAULT_AVATARS.some(avatar => url.endsWith(avatar));
|
|
|
|
};
|