Conversation.updateLastMessage: Properly clear timestamp/status

This commit is contained in:
Scott Nonnenberg 2019-04-01 09:50:45 -07:00
parent 81de5f9a76
commit a2fca80759
2 changed files with 10 additions and 6 deletions

View file

@ -13,6 +13,8 @@ describe('Conversation', () => {
const input = {};
const expected = {
lastMessage: '',
lastMessageStatus: null,
timestamp: null,
};
const actual = Conversation.createLastMessageUpdate(input);
@ -58,7 +60,7 @@ describe('Conversation', () => {
};
const expected = {
lastMessage: 'bingo',
lastMessageStatus: undefined,
lastMessageStatus: null,
timestamp: 555,
};
@ -87,7 +89,7 @@ describe('Conversation', () => {
};
const expected = {
lastMessage: 'Last message before expired',
lastMessageStatus: undefined,
lastMessageStatus: null,
timestamp: 555,
};

View file

@ -2,8 +2,8 @@ import { Message } from './Message';
interface ConversationLastMessageUpdate {
lastMessage: string;
lastMessageStatus?: string;
timestamp?: number;
lastMessageStatus: string | null;
timestamp: number | null;
}
export const createLastMessageUpdate = ({
@ -22,6 +22,8 @@ export const createLastMessageUpdate = ({
if (!lastMessage) {
return {
lastMessage: '',
lastMessageStatus: null,
timestamp: null,
};
}
@ -45,7 +47,7 @@ export const createLastMessageUpdate = ({
return {
lastMessage: newLastMessageText || '',
lastMessageStatus,
timestamp: newTimestamp,
lastMessageStatus: lastMessageStatus || null,
timestamp: newTimestamp || null,
};
};