Files
talk/client/coral-framework/utils/user.js
T
2018-04-30 19:56:53 -03:00

52 lines
1.1 KiB
JavaScript

import get from 'lodash/get';
import moment from 'moment';
/**
* getReliability
* retrieves reliability value as string
*/
export const getReliability = reliabilityValue => {
if (reliabilityValue === null) {
return 'neutral';
} else if (reliabilityValue) {
return 'reliable';
} else {
return 'unreliable';
}
};
/**
* isSuspended
* retrieves boolean based on the user suspension status
*/
export const isSuspended = user => {
const suspensionUntil = get(user, 'state.status.suspension.until');
return user && suspensionUntil && new Date(suspensionUntil) > new Date();
};
/**
* isBanned
* retrieves boolean based on the user ban status
*/
export const isBanned = user => {
return get(user, 'state.status.banned.status');
};
/**
* canUsernameBeUpdated
* retrieves boolean whether a username can be updated or not
*/
export const canUsernameBeUpdated = status => {
const oldestEditTime = moment()
.subtract(14, 'days')
.toDate();
return !status.username.history.some(({ created_at }) =>
moment(created_at).isAfter(oldestEditTime)
);
};