blob: 53c60534f3e72a455609b8ddb9656b830237a422 [file] [log] [blame]
idillon9e542ca2022-12-15 17:54:07 -05001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
18import dayjs from 'dayjs';
19import { i18n } from 'i18next';
20import { Message } from 'jami-web-common';
21
22import { formatCallDuration } from './dates&times';
23
24export const getMessageCallText = (isAccountMessage: boolean, message: Message, i18n: i18n) => {
25 const callDuration = dayjs.duration(parseInt(message?.duration || ''));
26 const formattedCallDuration = formatCallDuration(callDuration);
27 if (callDuration.asSeconds() === 0) {
28 if (isAccountMessage) {
29 return i18n.t('message_call_outgoing_missed');
30 } else {
31 return i18n.t('message_call_incoming_missed');
32 }
33 } else {
34 if (isAccountMessage) {
35 return i18n.t('message_call_outgoing', formattedCallDuration);
36 } else {
37 return i18n.t('message_call_incoming', formattedCallDuration);
38 }
39 }
40};
41
42export const getMessageMemberText = (message: Message, i18n: i18n) => {
43 switch (message.action) {
44 case 'add':
45 return i18n.t('message_member_invited', { user: message.author });
46 case 'join':
47 return i18n.t('message_member_joined', { user: message.author });
48 case 'remove':
49 return i18n.t('message_member_left', { user: message.author });
50 case 'ban':
51 return i18n.t('message_member_banned', { user: message.author });
52 case 'unban':
53 return i18n.t('message_member_unbanned', { user: message.author });
54 default:
55 console.error(`${getMessageMemberText.name} received an unexpected message action: ${message.action}`);
56 }
57};