updateLastMessage: If we don't update last text, clear it
This commit is contained in:
parent
0ffda78ecb
commit
22f7a352f9
3 changed files with 3 additions and 9 deletions
|
@ -1157,7 +1157,6 @@
|
||||||
? lastMessageModel.getMessagePropStatus()
|
? lastMessageModel.getMessagePropStatus()
|
||||||
: null;
|
: null;
|
||||||
const lastMessageUpdate = Conversation.createLastMessageUpdate({
|
const lastMessageUpdate = Conversation.createLastMessageUpdate({
|
||||||
currentLastMessageText: this.get('lastMessage') || null,
|
|
||||||
currentTimestamp: this.get('timestamp') || null,
|
currentTimestamp: this.get('timestamp') || null,
|
||||||
lastMessage: lastMessageJSON,
|
lastMessage: lastMessageJSON,
|
||||||
lastMessageStatus: lastMessageStatusModel,
|
lastMessageStatus: lastMessageStatusModel,
|
||||||
|
|
|
@ -24,7 +24,6 @@ describe('Conversation', () => {
|
||||||
context('for regular message', () => {
|
context('for regular message', () => {
|
||||||
it('should update last message text and timestamp', () => {
|
it('should update last message text and timestamp', () => {
|
||||||
const input = {
|
const input = {
|
||||||
currentLastMessageText: 'Existing message',
|
|
||||||
currentTimestamp: 555,
|
currentTimestamp: 555,
|
||||||
lastMessageStatus: 'read',
|
lastMessageStatus: 'read',
|
||||||
lastMessage: {
|
lastMessage: {
|
||||||
|
@ -48,7 +47,6 @@ describe('Conversation', () => {
|
||||||
context('for verified change message', () => {
|
context('for verified change message', () => {
|
||||||
it('should skip update', () => {
|
it('should skip update', () => {
|
||||||
const input = {
|
const input = {
|
||||||
currentLastMessageText: 'bingo',
|
|
||||||
currentTimestamp: 555,
|
currentTimestamp: 555,
|
||||||
lastMessage: {
|
lastMessage: {
|
||||||
type: 'verified-change',
|
type: 'verified-change',
|
||||||
|
@ -59,7 +57,7 @@ describe('Conversation', () => {
|
||||||
lastMessageNotificationText: 'Verified Changed',
|
lastMessageNotificationText: 'Verified Changed',
|
||||||
};
|
};
|
||||||
const expected = {
|
const expected = {
|
||||||
lastMessage: 'bingo',
|
lastMessage: '',
|
||||||
lastMessageStatus: null,
|
lastMessageStatus: null,
|
||||||
timestamp: 555,
|
timestamp: 555,
|
||||||
};
|
};
|
||||||
|
@ -72,7 +70,6 @@ describe('Conversation', () => {
|
||||||
context('for expire timer update from sync', () => {
|
context('for expire timer update from sync', () => {
|
||||||
it('should update message but not timestamp (to prevent bump to top)', () => {
|
it('should update message but not timestamp (to prevent bump to top)', () => {
|
||||||
const input = {
|
const input = {
|
||||||
currentLastMessageText: 'I am expired',
|
|
||||||
currentTimestamp: 555,
|
currentTimestamp: 555,
|
||||||
lastMessage: {
|
lastMessage: {
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
|
|
@ -7,13 +7,11 @@ interface ConversationLastMessageUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLastMessageUpdate = ({
|
export const createLastMessageUpdate = ({
|
||||||
currentLastMessageText,
|
|
||||||
currentTimestamp,
|
currentTimestamp,
|
||||||
lastMessage,
|
lastMessage,
|
||||||
lastMessageStatus,
|
lastMessageStatus,
|
||||||
lastMessageNotificationText,
|
lastMessageNotificationText,
|
||||||
}: {
|
}: {
|
||||||
currentLastMessageText?: string;
|
|
||||||
currentTimestamp?: number;
|
currentTimestamp?: number;
|
||||||
lastMessage?: Message;
|
lastMessage?: Message;
|
||||||
lastMessageStatus?: string;
|
lastMessageStatus?: string;
|
||||||
|
@ -32,10 +30,10 @@ export const createLastMessageUpdate = ({
|
||||||
const isExpireTimerUpdateFromSync = Boolean(
|
const isExpireTimerUpdateFromSync = Boolean(
|
||||||
expirationTimerUpdate && expirationTimerUpdate.fromSync
|
expirationTimerUpdate && expirationTimerUpdate.fromSync
|
||||||
);
|
);
|
||||||
|
|
||||||
const shouldUpdateTimestamp = Boolean(
|
const shouldUpdateTimestamp = Boolean(
|
||||||
!isVerifiedChangeMessage && !isExpireTimerUpdateFromSync
|
!isVerifiedChangeMessage && !isExpireTimerUpdateFromSync
|
||||||
);
|
);
|
||||||
|
|
||||||
const newTimestamp = shouldUpdateTimestamp
|
const newTimestamp = shouldUpdateTimestamp
|
||||||
? lastMessage.sent_at
|
? lastMessage.sent_at
|
||||||
: currentTimestamp;
|
: currentTimestamp;
|
||||||
|
@ -43,7 +41,7 @@ export const createLastMessageUpdate = ({
|
||||||
const shouldUpdateLastMessageText = !isVerifiedChangeMessage;
|
const shouldUpdateLastMessageText = !isVerifiedChangeMessage;
|
||||||
const newLastMessageText = shouldUpdateLastMessageText
|
const newLastMessageText = shouldUpdateLastMessageText
|
||||||
? lastMessageNotificationText
|
? lastMessageNotificationText
|
||||||
: currentLastMessageText;
|
: '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lastMessage: newLastMessageText || '',
|
lastMessage: newLastMessageText || '',
|
||||||
|
|
Loading…
Reference in a new issue