pleroma/app/gabsocial/utils/accounts.js

47 lines
1.6 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
2020-04-18 12:18:04 -07:00
export const getDomain = account => {
2020-03-28 11:07:36 -07:00
let re = /https?:\/\/(.*?)\//i;
return re.exec(account.get('url'))[1];
2020-04-14 11:44:40 -07:00
};
2020-03-28 11:07:36 -07:00
// user@domain even for local users
export const acctFull = account => {
let [user, domain] = account.get('acct').split('@');
try {
if (!domain) domain = getDomain(account);
} catch(e) {
2020-03-28 13:10:35 -07:00
console.warning('Could not get domain for acctFull. Falling back to acct.');
2020-03-28 11:07:36 -07:00
return account.get('acct');
}
return [user, domain].join('@');
2020-04-14 11:44:40 -07:00
};
2020-04-18 13:09:54 -07:00
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
);
export const getHasMoreFollowsCount = (state, accountId, isFollowing) => {
let moreFollowsCount = undefined; //variable text in defaultMessage with null value preventing rendering
let emptyList = ImmutableList();
if (isFollowing) {
let followingList = ImmutableList();
followingList = state.getIn(['user_lists', 'following', accountId, 'items'], emptyList);
moreFollowsCount = parseInt(state.getIn(['accounts_counters', accountId, 'following_count']), 0) - followingList.size;
} else {
let followersList = ImmutableList();
followersList = state.getIn(['user_lists', 'followers', accountId, 'items'], emptyList);
moreFollowsCount = parseInt(state.getIn(['accounts_counters', accountId, 'followers_count']), 0) - followersList.size;
}
return moreFollowsCount;
};