MOBILE-4362 messages: Update sender name when last message changes
The sender name displayed in group conversations page wasn't updated when a NEW_MESSAGE_EVENT was received. Also, if last message was deleted we still displayed a sender name when there were no messages.main
parent
28235b0553
commit
31bd7a6955
|
@ -65,7 +65,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
|||
|
||||
protected messagesBeingSent = 0;
|
||||
protected pagesLoaded = 1;
|
||||
protected lastMessage = { text: '', timecreated: 0 };
|
||||
protected lastMessage?: { text: string; timecreated: number };
|
||||
protected keepMessageMap: {[hash: string]: boolean} = {};
|
||||
protected syncObserver: CoreEventObserver;
|
||||
protected oldContentHeight = 0;
|
||||
|
@ -465,7 +465,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
|||
|
||||
// If we received a new message while using group messaging, force mark messages as read.
|
||||
const last = this.messages[this.messages.length - 1];
|
||||
const forceMark = this.groupMessagingEnabled && last && last.useridfrom != this.currentUserId && this.lastMessage.text != ''
|
||||
const forceMark = this.groupMessagingEnabled && last && last.useridfrom !== this.currentUserId && !!this.lastMessage
|
||||
&& (last.text !== this.lastMessage.text || last.timecreated !== this.lastMessage.timecreated);
|
||||
|
||||
// Notify that there can be a new message.
|
||||
|
@ -773,14 +773,14 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
|||
* Notify the last message found so discussions list controller can tell if last message should be updated.
|
||||
*/
|
||||
protected notifyNewMessage(): void {
|
||||
const last = this.messages[this.messages.length - 1];
|
||||
const last = this.messages[this.messages.length - 1] as AddonMessagesConversationMessageFormatted | undefined;
|
||||
|
||||
let trigger = false;
|
||||
|
||||
if (!last) {
|
||||
this.lastMessage = { text: '', timecreated: 0 };
|
||||
this.lastMessage = undefined;
|
||||
trigger = true;
|
||||
} else if (last.text !== this.lastMessage.text || last.timecreated !== this.lastMessage.timecreated) {
|
||||
} else if (last.text !== this.lastMessage?.text || last.timecreated !== this.lastMessage?.timecreated) {
|
||||
this.lastMessage = { text: last.text || '', timecreated: last.timecreated };
|
||||
trigger = true;
|
||||
}
|
||||
|
@ -790,8 +790,9 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
|||
CoreEvents.trigger(AddonMessagesProvider.NEW_MESSAGE_EVENT, {
|
||||
conversationId: this.conversationId,
|
||||
userId: this.userId,
|
||||
message: this.lastMessage.text,
|
||||
timecreated: this.lastMessage.timecreated,
|
||||
message: this.lastMessage?.text,
|
||||
timecreated: this.lastMessage?.timecreated ?? 0,
|
||||
userFrom: last?.useridfrom ? this.members[last.useridfrom] : undefined,
|
||||
isfavourite: !!this.conversation?.isfavourite,
|
||||
type: this.conversation?.type,
|
||||
}, this.siteId);
|
||||
|
|
|
@ -89,7 +89,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
|
|||
});
|
||||
} else if (discussion.message) {
|
||||
// An existing discussion has a new message, update the last message.
|
||||
discussion.message.message = data.message;
|
||||
discussion.message.message = data.message ?? '';
|
||||
discussion.message.timecreated = data.timecreated;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@
|
|||
<p *ngIf="conversation.subname">
|
||||
<core-format-text [text]="conversation.subname" contextLevel="system" [contextInstanceId]="0"></core-format-text>
|
||||
</p>
|
||||
<p class="addon-message-last-message">
|
||||
<p *ngIf="conversation.lastmessage !== undefined" class="addon-message-last-message">
|
||||
<span *ngIf="conversation.sentfromcurrentuser" class="addon-message-last-message-user">
|
||||
{{ 'addon.messages.you' | translate }}
|
||||
</span>
|
||||
|
|
|
@ -132,12 +132,27 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
|||
|
||||
return;
|
||||
}
|
||||
if (conversation.lastmessage != data.message || conversation.lastmessagedate != data.timecreated / 1000) {
|
||||
|
||||
if (data.message === undefined) {
|
||||
conversation.lastmessage = undefined;
|
||||
conversation.lastmessagedate = undefined;
|
||||
conversation.sentfromcurrentuser = undefined;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (conversation.lastmessage !== data.message || conversation.lastmessagedate !== data.timecreated / 1000) {
|
||||
const isNewer = data.timecreated / 1000 > (conversation.lastmessagedate || 0);
|
||||
|
||||
// An existing conversation has a new message, update the last message.
|
||||
conversation.lastmessage = data.message;
|
||||
conversation.lastmessagedate = data.timecreated / 1000;
|
||||
if (data.userFrom) {
|
||||
conversation.sentfromcurrentuser = data.userFrom.id === this.currentUserId;
|
||||
if (conversation.type === AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) {
|
||||
conversation.members[0] = data.userFrom;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the affected list.
|
||||
const option = this.getConversationOption(conversation);
|
||||
|
|
|
@ -3669,8 +3669,9 @@ export type AddonMessagesReadChangedEventData = {
|
|||
export type AddonMessagesNewMessagedEventData = {
|
||||
conversationId?: number;
|
||||
userId?: number;
|
||||
message: string;
|
||||
message?: string; // If undefined it means the conversation has no messages, e.g. last message was deleted.
|
||||
timecreated: number;
|
||||
userFrom?: AddonMessagesConversationMember;
|
||||
isfavourite: boolean;
|
||||
type?: number;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue