Message Requests improvements

This commit is contained in:
Scott Nonnenberg 2020-08-06 17:50:54 -07:00 committed by GitHub
parent b63291507a
commit 81cb7730a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 302 additions and 263 deletions

View file

@ -1,58 +0,0 @@
import { Message } from './Message';
interface ConversationLastMessageUpdate {
lastMessage: string;
lastMessageStatus: string | null;
timestamp: number | null;
lastMessageDeletedForEveryone?: boolean;
}
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 { type, expirationTimerUpdate, deletedForEveryone } = lastMessage;
const isMessageHistoryUnsynced = type === 'message-history-unsynced';
const isProfileChangedMessage = type === 'profile-change';
const isVerifiedChangeMessage = type === 'verified-change';
const isExpireTimerUpdateFromSync = Boolean(
expirationTimerUpdate && expirationTimerUpdate.fromSync
);
const shouldUpdateTimestamp = Boolean(
!isMessageHistoryUnsynced &&
!isProfileChangedMessage &&
!isVerifiedChangeMessage &&
!isExpireTimerUpdateFromSync
);
const newTimestamp = shouldUpdateTimestamp
? lastMessage.sent_at
: currentTimestamp;
const shouldUpdateLastMessageText = !isVerifiedChangeMessage;
const newLastMessageText = shouldUpdateLastMessageText
? lastMessageNotificationText
: '';
return {
lastMessage: deletedForEveryone ? '' : newLastMessageText || '',
lastMessageStatus: lastMessageStatus || null,
timestamp: newTimestamp || null,
lastMessageDeletedForEveryone: deletedForEveryone,
};
};