You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/types/Conversation.ts

42 lines
1.0 KiB
TypeScript

import { Message } from './Message';
interface ConversationLastMessageUpdate {
lastMessage: string;
lastMessageStatus: string | null;
timestamp: number | null;
}
export const createLastMessageUpdate = ({
currentTimestamp,
lastMessage,
lastMessageStatus,
lastMessageNotificationText,
}: {
currentTimestamp?: number;
lastMessage?: Message;
lastMessageStatus?: string;
lastMessageNotificationText?: string;
}): ConversationLastMessageUpdate => {
if (!lastMessage) {
return {
lastMessage: '',
lastMessageStatus: null,
timestamp: null,
};
}
const { expirationTimerUpdate } = lastMessage;
const isExpireTimerUpdateFromSync = Boolean(
expirationTimerUpdate && expirationTimerUpdate.fromSync
);
const shouldUpdateTimestamp = Boolean(!isExpireTimerUpdateFromSync);
const newTimestamp = shouldUpdateTimestamp ? lastMessage.sent_at : currentTimestamp;
return {
lastMessage: lastMessageNotificationText || '',
lastMessageStatus: lastMessageStatus || null,
timestamp: newTimestamp || null,
};
};