2022-01-12 12:54:04 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import { IAttachment } from '../definitions/IAttachment';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription';
|
2022-01-12 12:54:04 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
export const isBlocked = (room: TSubscriptionModel): boolean => {
|
2022-01-12 12:54:04 +00:00
|
|
|
if (room) {
|
|
|
|
const { t, blocked, blocker } = room;
|
|
|
|
if (t === SubscriptionType.DIRECT && (blocked || blocker)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const capitalize = (s: string): string => {
|
|
|
|
if (typeof s !== 'string') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
|
|
};
|
|
|
|
|
2022-02-22 12:04:01 +00:00
|
|
|
export const formatDate = (date: string | Date): string =>
|
2022-01-12 12:54:04 +00:00
|
|
|
moment(date).calendar(null, {
|
|
|
|
lastDay: `[${I18n.t('Yesterday')}]`,
|
|
|
|
sameDay: 'LT',
|
|
|
|
lastWeek: 'dddd',
|
|
|
|
sameElse: 'L'
|
|
|
|
});
|
|
|
|
|
2022-02-22 12:04:01 +00:00
|
|
|
export const formatDateThreads = (date: string | Date): string =>
|
2022-01-12 12:54:04 +00:00
|
|
|
moment(date).calendar(null, {
|
|
|
|
sameDay: 'LT',
|
|
|
|
lastDay: `[${I18n.t('Yesterday')}] LT`,
|
|
|
|
lastWeek: 'dddd LT',
|
|
|
|
sameElse: 'LL'
|
|
|
|
});
|
|
|
|
|
|
|
|
export const getBadgeColor = ({
|
|
|
|
subscription,
|
|
|
|
messageId,
|
|
|
|
theme
|
|
|
|
}: {
|
|
|
|
// TODO: Refactor when migrate model folder
|
|
|
|
subscription: any;
|
|
|
|
messageId: string;
|
|
|
|
theme: string;
|
|
|
|
}): string | undefined => {
|
|
|
|
if (subscription?.tunreadUser?.includes(messageId)) {
|
|
|
|
return themes[theme].mentionMeColor;
|
|
|
|
}
|
|
|
|
if (subscription?.tunreadGroup?.includes(messageId)) {
|
|
|
|
return themes[theme].mentionGroupColor;
|
|
|
|
}
|
|
|
|
if (subscription?.tunread?.includes(messageId)) {
|
|
|
|
return themes[theme].tunreadColor;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const makeThreadName = (messageRecord: { id?: string; msg?: string; attachments?: IAttachment[] }): string | undefined =>
|
2022-01-19 20:41:21 +00:00
|
|
|
messageRecord.msg || messageRecord?.attachments?.[0]?.title;
|
2022-01-12 12:54:04 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
export const isTeamRoom = ({ teamId, joined }: { teamId?: string; joined?: boolean }): boolean => (!!teamId && joined) ?? false;
|