[FIX] mail: fix handling of lastVisibleMessage in channel seen condition

also fix a problem with composer.hasFocus field not always correctly
updated (e.g. when switching from a channel to another in discuss)

task-2278915

closes odoo/odoo#61007

X-original-commit: ecb56a6893dd7b76402c2262fb93f8dea079fde0
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Xavier Dubuc
2020-10-29 16:35:37 +00:00
parent d296469ff4
commit eac3c08ce2
5 changed files with 69 additions and 2 deletions
@@ -83,6 +83,7 @@
t-on-o-composer-suggestion-clicked="_onComposerSuggestionClicked"
t-on-o-composer-text-input-send-shortcut="_onComposerTextInputSendShortcut"
t-on-paste="_onPasteTextInput"
t-key="composer.localId"
t-ref="textInput"
/>
<div class="o_Composer_buttons" t-att-class="{ 'o-composer-is-compact': props.isCompact, 'o-mobile': env.messaging.device.isMobile }">
@@ -179,7 +179,7 @@ class ComposerTextInput extends Component {
* @private
*/
_onFocusinTextarea() {
this.composer.update({ hasFocus: true });
this.composer.focus();
}
/**
@@ -4206,6 +4206,53 @@ QUnit.test('auto-focus composer on opening thread', async function (assert) {
);
});
QUnit.test('mark channel as seen if last message is visible when switching channels when the previous channel had a more recent last message than the current channel', async function (assert) {
assert.expect(1);
this.data['mail.channel'].records.push(
{ id: 10, message_unread_counter: 1, name: 'Bla' },
{ id: 11, message_unread_counter: 1, name: 'Blu' },
);
this.data['mail.message'].records.push({
body: 'oldest message',
channel_ids: [10],
id: 10,
}, {
body: 'newest message',
channel_ids: [11],
id: 11,
});
await this.start({
discuss: {
context: {
active_id: 'mail.channel_11',
},
},
});
await afterNextRender(() => {
document.querySelector(`
.o_DiscussSidebar_item[data-thread-local-id="${
this.env.models['mail.thread'].findFromIdentifyingData({
id: 10,
model: 'mail.channel',
}).localId
}"]
`).click();
});
assert.doesNotHaveClass(
document.querySelector(`
.o_DiscussSidebar_item[data-thread-local-id="${
this.env.models['mail.thread'].findFromIdentifyingData({
id: 10,
model: 'mail.channel',
}).localId
}"]
`),
'o-unread',
"sidebar item of channel ID 10 should no longer be unread"
);
});
});
});
});
@@ -102,6 +102,21 @@ function factory(dependencies) {
}
}
/**
* Focus this composer and remove focus from all others.
* Focus is a global concern, it makes no sense to have multiple composers focused at the
* same time.
*/
focus() {
const allComposers = this.env.models['mail.composer'].all();
for (const otherComposer of allComposers) {
if (otherComposer !== this && otherComposer.hasFocus) {
otherComposer.update({ hasFocus: false });
}
}
this.update({ hasFocus: true });
}
/**
* Inserts text content in text input based on selection.
*
@@ -136,6 +136,7 @@ function factory(dependencies) {
if (this.threadCache) {
this.threadCache.update({ isCacheRefreshRequested: true });
}
this.update({ lastVisibleMessage: [['unlink']] });
}
/**
@@ -225,12 +226,15 @@ function factory(dependencies) {
* hint `message-received`.
*/
hasAutoScrollOnMessageReceived: attr(),
/**
* Last message in the context of the currently displayed thread cache.
*/
lastMessage: many2one('mail.message', {
related: 'thread.lastMessage',
}),
/**
* Most recent message in this ThreadView that has been shown to the
* current partner.
* current partner in the currently displayed thread cache.
*/
lastVisibleMessage: many2one('mail.message'),
messages: many2many('mail.message', {