Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Rename endTs property on Message to webRtcCallEndTs
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 committed Nov 19, 2021
1 parent 747142f commit f08bd01
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/components/Messages/Message/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { formatDistance } from 'date-fns';
import format from 'date-fns/format';
import { parseISO } from 'date-fns/fp';
import isToday from 'date-fns/isToday';
import { h } from 'preact';

import I18n from '../../../i18n';
import { getAttachmentUrl, memo, normalizeTransferHistoryMessage } from '../../helpers';
import { getAttachmentUrl, memo, normalizeTransferHistoryMessage, resolveDate } from '../../helpers';
import { AudioAttachment } from '../AudioAttachment';
import { FileAttachment } from '../FileAttachment';
import { ImageAttachment } from '../ImageAttachment';
Expand Down Expand Up @@ -85,14 +84,16 @@ const renderContent = ({
),
].filter(Boolean);

const resolveWebRTCEndCallMessage = ({ endTs: callEndTime, ts: callStartTime }) => {
const callDuration = formatDistance(new Date(callEndTime), new Date(callStartTime));
const timestamp = new Date(callEndTime).toISOString();
const time = format(parseISO(timestamp), isToday(parseISO(timestamp)) ? 'HH:mm' : 'dddd HH:mm');

const resolveWebRTCEndCallMessage = ({ webRtcCallEndTs, ts }) => {
const callEndTime = resolveDate(webRtcCallEndTs);
const callStartTime = resolveDate(ts);
const callDuration = formatDistance(callEndTime, callStartTime);
const time = format(callEndTime, isToday(callEndTime) ? 'HH:mm' : 'dddd HH:mm');
return `${ I18n.t('Call ended at %{time}', { time }) } ${ I18n.t(' - Lasted %{callDuration}', { callDuration }) }`;
};

const getSystemMessageText = ({ t, conversationFinishedMessage, transferData, u, endTs, ts }) =>
const getSystemMessageText = ({ t, conversationFinishedMessage, transferData, u, webRtcCallEndTs, ts }) =>
(t === MESSAGE_TYPE_ROOM_NAME_CHANGED && I18n.t('Room name changed'))
|| (t === MESSAGE_TYPE_USER_ADDED && I18n.t('User added by'))
|| (t === MESSAGE_TYPE_USER_REMOVED && I18n.t('User removed by'))
Expand All @@ -102,7 +103,7 @@ const getSystemMessageText = ({ t, conversationFinishedMessage, transferData, u,
|| (t === MESSAGE_TYPE_LIVECHAT_CLOSED && (conversationFinishedMessage || I18n.t('Conversation finished')))
|| (t === MESSAGE_TYPE_LIVECHAT_STARTED && I18n.t('Chat started'))
|| (t === MESSAGE_TYPE_LIVECHAT_TRANSFER_HISTORY && normalizeTransferHistoryMessage(transferData, u))
|| (t === MESSAGE_WEBRTC_CALL && endTs && ts && resolveWebRTCEndCallMessage({ endTs, ts }));
|| (t === MESSAGE_WEBRTC_CALL && webRtcCallEndTs && ts && resolveWebRTCEndCallMessage({ webRtcCallEndTs, ts }));

const getMessageUsernames = (compact, message) => {
if (compact || !message.u) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Messages/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class MessageList extends MemoizedComponent {
if ((message.t === constants.webRTCCallStartedMessageType || message.t === constants.jitsiCallStartedMessageType)
&& message.actionLinks && message.actionLinks.length
&& ongoingCall && isCallOngoing(ongoingCall.callStatus)
&& !message.endTs) {
&& !message.webRtcCallEndTs) {
const { url, callProvider, rid } = incomingCallAlert || {};
items.push(
<JoinCallButton callStatus={ongoingCall.callStatus} url={url} callProvider={callProvider} rid={rid} />,
Expand Down
18 changes: 18 additions & 0 deletions src/components/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import parseISO from 'date-fns/parseISO';
import { Component } from 'preact';

import { Livechat, useSsl } from '../api';
Expand Down Expand Up @@ -246,3 +247,20 @@ export const isActiveSession = () => {
};

export const isMobileDevice = () => window.innerWidth <= 800 && window.innerHeight >= 630;

export const resolveDate = (dateInput) => {
switch (typeof dateInput) {
case Date: {
return dateInput;
}
case 'object': {
return new Date(dateInput.$date);
}
case 'string': {
return parseISO(dateInput);
}
default: {
return new Date(dateInput);
}
}
};
2 changes: 1 addition & 1 deletion src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const processMessage = async (message) => {
closeChat(message);
} else if (message.t === 'command') {
commands[message.msg] && commands[message.msg]();
} else if (message.endTs) {
} else if (message.webRtcCallEndTs) {
await store.setState({ ongoingCall: { callStatus: CallStatus.ENDED, time: message.ts }, incomingCallAlert: null });
} else if (message.t === constants.webRTCCallStartedMessageType || message.t === constants.jitsiCallStartedMessageType) {
await processIncomingCallMessage(message);
Expand Down

0 comments on commit f08bd01

Please sign in to comment.