bigbuffet-rw/app/soapbox/utils/accounts.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-04-21 12:00:31 -07:00
import { Map as ImmutableMap } from 'immutable';
import { List as ImmutableList } from 'immutable';
2020-04-21 12:00:31 -07:00
const guessDomain = account => {
try {
let re = /https?:\/\/(.*?)\//i;
return re.exec(account.get('url'))[1];
} catch(e) {
return null;
}
};
2020-04-18 12:18:04 -07:00
export const getDomain = account => {
let domain = account.get('acct').split('@')[1];
if (!domain) domain = guessDomain(account);
return domain;
2020-04-14 11:44:40 -07:00
};
2020-03-28 11:07:36 -07:00
export const guessFqn = account => {
const [user, domain] = account.get('acct').split('@');
if (!domain) return [user, guessDomain(account)].join('@');
return account.get('acct');
2020-04-14 11:44:40 -07:00
};
2020-04-18 13:09:54 -07:00
// user@domain even for local users
export const acctFull = account => (
account.get('fqn') || guessFqn(account)
);
export const getAcct = (account, displayFqn) => (
displayFqn === true ? acctFull(account) : account.get('acct')
);
2020-04-27 13:05:07 -07: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-27 17:36:23 -07: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);
return Math.max(counter - listSize, 0);
};
export const isLocal = account => {
let domain = account.get('acct').split('@')[1];
return domain === undefined ? true : false;
};
2021-03-15 19:50:16 -07:00
export const isVerified = account => (
account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified')
);