Skip to content

Commit e6f982e

Browse files
authored
Merge pull request #1971 from dpalou/MOBILE-3039
MOBILE-3039 messages: Fix mark as read not called in 3.6+
2 parents dd6d7e8 + caa4d9e commit e6f982e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/addon/messages/pages/discussion/discussion.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,16 @@ export class AddonMessagesDiscussionPage implements OnDestroy {
391391
// Call resize to recalculate the dimensions.
392392
this.content && this.content.resize();
393393

394+
// If we received a new message while using group messaging, force mark messages as read.
395+
const last = this.messages[this.messages.length - 1],
396+
forceMark = this.groupMessagingEnabled && last && last.useridfrom != this.currentUserId && this.lastMessage.text != ''
397+
&& (last.text !== this.lastMessage.text || last.timecreated !== this.lastMessage.timecreated);
398+
394399
// Notify that there can be a new message.
395400
this.notifyNewMessage();
396401

397402
// Mark retrieved messages as read if they are not.
398-
this.markMessagesAsRead();
403+
this.markMessagesAsRead(forceMark);
399404
}
400405

401406
/**
@@ -577,15 +582,17 @@ export class AddonMessagesDiscussionPage implements OnDestroy {
577582
/**
578583
* Mark messages as read.
579584
*/
580-
protected markMessagesAsRead(): void {
585+
protected markMessagesAsRead(forceMark: boolean): void {
581586
let readChanged = false;
582587
const promises = [];
583588

584589
if (this.messagesProvider.isMarkAllMessagesReadEnabled()) {
585590
let messageUnreadFound = false;
586591

587592
// Mark all messages at a time if there is any unread message.
588-
if (this.groupMessagingEnabled) {
593+
if (forceMark) {
594+
messageUnreadFound = true;
595+
} else if (this.groupMessagingEnabled) {
589596
messageUnreadFound = this.conversation && this.conversation.unreadcount > 0 && this.conversationId > 0;
590597
} else {
591598
for (const x in this.messages) {
@@ -649,6 +656,7 @@ export class AddonMessagesDiscussionPage implements OnDestroy {
649656
const last = this.messages[this.messages.length - 1];
650657

651658
let trigger = false;
659+
652660
if (!last) {
653661
this.lastMessage = {text: '', timecreated: 0};
654662
trigger = true;

0 commit comments

Comments
 (0)