2020-04-21 19:00:31 +00:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2020-05-28 00:16:42 +00:00
|
|
|
import { List as ImmutableList } from 'immutable';
|
2020-04-21 19:00:31 +00:00
|
|
|
|
2020-09-03 03:38:04 +00:00
|
|
|
const guessDomain = account => {
|
|
|
|
try {
|
2021-08-03 17:10:42 +00:00
|
|
|
const re = /https?:\/\/(.*?)\//i;
|
2020-09-03 03:38:04 +00:00
|
|
|
return re.exec(account.get('url'))[1];
|
|
|
|
} catch(e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-18 19:18:04 +00:00
|
|
|
export const getDomain = account => {
|
2020-09-03 03:38:04 +00:00
|
|
|
let domain = account.get('acct').split('@')[1];
|
|
|
|
if (!domain) domain = guessDomain(account);
|
|
|
|
return domain;
|
2020-04-14 18:44:40 +00:00
|
|
|
};
|
2020-03-28 18:07:36 +00:00
|
|
|
|
2021-04-10 18:10:44 +00:00
|
|
|
export const guessFqn = account => {
|
2020-09-03 03:38:04 +00:00
|
|
|
const [user, domain] = account.get('acct').split('@');
|
|
|
|
if (!domain) return [user, guessDomain(account)].join('@');
|
|
|
|
return account.get('acct');
|
2020-04-14 18:44:40 +00:00
|
|
|
};
|
2020-04-18 20:09:54 +00:00
|
|
|
|
2021-04-10 18:10:44 +00:00
|
|
|
// user@domain even for local users
|
2021-04-10 19:13:07 +00:00
|
|
|
export const acctFull = account => (
|
|
|
|
account.get('fqn') || guessFqn(account)
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getAcct = (account, displayFqn) => (
|
|
|
|
displayFqn === true ? acctFull(account) : account.get('acct')
|
|
|
|
);
|
2021-04-10 18:10:44 +00:00
|
|
|
|
2020-04-27 20:05:07 +00:00
|
|
|
export const isStaff = (account = ImmutableMap()) => (
|
|
|
|
[isAdmin, isModerator].some(f => f(account) === true)
|
|
|
|
);
|
|
|
|
|
|
|
|
export const isAdmin = account => (
|
|
|
|
account.getIn(['pleroma', 'is_admin']) === true
|
|
|
|
);
|
|
|
|
|
|
|
|
export const isModerator = account => (
|
|
|
|
account.getIn(['pleroma', 'is_moderator']) === true
|
|
|
|
);
|
2020-05-28 00:16:42 +00:00
|
|
|
|
2020-05-28 00:36:23 +00:00
|
|
|
export const getFollowDifference = (state, accountId, type) => {
|
|
|
|
const listSize = state.getIn(['user_lists', type, accountId, 'items'], ImmutableList()).size;
|
|
|
|
const counter = state.getIn(['accounts_counters', accountId, `${type}_count`], 0);
|
2020-06-07 20:11:41 +00:00
|
|
|
return Math.max(counter - listSize, 0);
|
2020-05-28 00:16:42 +00:00
|
|
|
};
|
2021-03-16 00:29:42 +00:00
|
|
|
|
|
|
|
export const isLocal = account => {
|
2021-08-03 17:10:42 +00:00
|
|
|
const domain = account.get('acct').split('@')[1];
|
2021-03-16 00:29:42 +00:00
|
|
|
return domain === undefined ? true : false;
|
|
|
|
};
|
2021-03-16 02:50:16 +00:00
|
|
|
|
|
|
|
export const isVerified = account => (
|
|
|
|
account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified')
|
|
|
|
);
|