[IMP] mail: hide message error notifications if not origin thread

task-2282370

closes odoo/odoo#54768

X-original-commit: 4f693105bcaac7546590302cdc25c2b11b0f42cd
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Xavier Dubuc
2020-07-22 11:12:35 +00:00
parent 1c2bc40a95
commit c43cdd3f19
6 changed files with 176 additions and 38 deletions
@@ -411,6 +411,54 @@ QUnit.test('"reply to" composer should send message if message replied to is not
assert.verifySteps(['message_post']);
});
QUnit.test('error notifications should not be shown in inbox', async function (assert) {
assert.expect(3);
Object.assign(this.data.initMessaging, {
channel_slots: {
channel_channel: [{
channel_type: 'channel',
id: 20,
is_pinned: true,
name: "General",
}],
},
needaction_inbox_counter: 1,
});
this.data['mail.message'].records = [{
author_id: [7, "Demo"],
body: "<p>Test</p>",
date: "2019-04-20 11:00:00",
id: 100,
message_type: 'comment',
model: 'mail.channel',
needaction: true,
needaction_partner_ids: [3],
notifications: [{
id: 11,
notification_status: 'exception',
notification_type: 'email',
}],
res_id: 20,
}];
await this.start();
assert.containsOnce(
document.body,
'.o_Message',
"should display a single message"
);
assert.containsOnce(
document.body,
'.o_Message_originThreadLink',
"should display origin thread link"
);
assert.containsNone(
document.body,
'.o_Message_notificationIcon',
"should not display any notification icon in inbox"
);
});
QUnit.test('show subject of message in inbox', async function (assert) {
assert.expect(3);
@@ -168,24 +168,6 @@ class Message extends Component {
return true;
}
/**
* Determine whether the message origin thread is the same as the context
* of displaying this message. In other word, if the enclosing thread
* component of this message component is linked to the origin thread of
* this message, then the origin is the same.
*
* @returns {boolean}
*/
get hasDifferentOriginThread() {
if (!this.threadViewer) {
return false;
}
if (!this.message.originThread) {
return false;
}
return this.message.originThread !== this.threadViewer.thread;
}
/**
* @returns {mail.attachment[]}
*/
@@ -78,7 +78,7 @@
<t t-if="message.isCurrentPartnerAuthor and threadViewer and threadViewer.thread">
<MessageSeenIndicator class="o_Message_seenIndicator" messageLocalId="message.localId" threadLocalId="threadViewer.thread.localId"/>
</t>
<t t-if="hasDifferentOriginThread">
<t t-if="threadViewer and message.originThread and message.originThread !== threadViewer.thread">
<div class="o_Message_originThread" t-att-class="{ 'o-message-selected': props.isSelected }">
<t t-if="message.originThread.model === 'mail.channel'">
(from <a class="o_Message_originThreadLink" href="#" t-on-click="_onClickOriginThread">#<t t-esc="message.originThread.name"/></a>)
@@ -91,7 +91,7 @@
<t t-if="message.moderation_status === 'pending_moderation' and !message.isModeratedByCurrentPartner">
<span class="o_Message_moderationPending o-author" title="Your message is pending moderation.">Pending moderation</span>
</t>
<t t-if="message.notifications.length > 0">
<t t-if="threadViewer and message.originThread and message.originThread === threadViewer.thread and message.notifications.length > 0">
<t t-if="message.failureNotifications.length > 0">
<span class="o_Message_notificationIconContainer o-error" t-on-click="_onClickFailure">
<i name="failureIcon" class="o_Message_notificationIcon fa fa-envelope"/>
@@ -220,6 +220,12 @@ QUnit.test('Notification Sent', async function (assert) {
assert.expect(9);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'email',
@@ -229,8 +235,11 @@ QUnit.test('Notification Sent', async function (assert) {
notification_type: 'email',
partner: [['insert', { id: 12, name: "Someone" }]],
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -302,6 +311,12 @@ QUnit.test('Notification Error', async function (assert) {
});
await this.start({ env: { bus } });
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'email',
@@ -310,8 +325,11 @@ QUnit.test('Notification Error', async function (assert) {
notification_status: 'exception',
notification_type: 'email',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -20,12 +20,12 @@ QUnit.module('message_tests.js', {
beforeEach() {
utilsBeforeEach(this);
this.createMessageComponent = async message => {
this.createMessageComponent = async (message, otherProps) => {
const MessageComponent = components.Message;
MessageComponent.env = this.env;
this.component = new MessageComponent(null, {
this.component = new MessageComponent(null, Object.assign({
messageLocalId: message.localId,
});
}, otherProps));
delete MessageComponent.env;
await this.component.mount(this.widget.el);
};
@@ -57,6 +57,12 @@ QUnit.test('Notification Sent', async function (assert) {
assert.expect(9);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'sms',
@@ -66,8 +72,11 @@ QUnit.test('Notification Sent', async function (assert) {
notification_type: 'sms',
partner: [['insert', { id: 12, name: "Someone" }]],
}]],
originThread: [['link', threadViewer.thread]]
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -139,6 +148,12 @@ QUnit.test('Notification Error', async function (assert) {
});
await this.start({ env: { bus } });
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'sms',
@@ -147,8 +162,11 @@ QUnit.test('Notification Error', async function (assert) {
notification_status: 'exception',
notification_type: 'sms',
}]],
originThread: [['link', threadViewer.thread]]
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -20,12 +20,12 @@ QUnit.module('message_tests.js', {
beforeEach() {
utilsBeforeEach(this);
this.createMessageComponent = async message => {
this.createMessageComponent = async (message, otherProps) => {
const MessageComponent = components.Message;
MessageComponent.env = this.env;
this.component = new MessageComponent(null, {
this.component = new MessageComponent(null, Object.assign({
messageLocalId: message.localId,
});
}, otherProps));
delete MessageComponent.env;
await this.component.mount(this.widget.el);
};
@@ -57,6 +57,12 @@ QUnit.test('Sent', async function (assert) {
assert.expect(8);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -65,8 +71,11 @@ QUnit.test('Sent', async function (assert) {
notification_status: 'sent',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -118,6 +127,12 @@ QUnit.test('Canceled', async function (assert) {
assert.expect(8);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -126,8 +141,11 @@ QUnit.test('Canceled', async function (assert) {
notification_status: 'canceled',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -179,6 +197,12 @@ QUnit.test('Pending', async function (assert) {
assert.expect(8);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -187,8 +211,11 @@ QUnit.test('Pending', async function (assert) {
notification_status: 'ready',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -248,6 +275,12 @@ QUnit.test('No Price Available', async function (assert) {
return this._super(...arguments);
},
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -257,8 +290,11 @@ QUnit.test('No Price Available', async function (assert) {
notification_status: 'exception',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -329,6 +365,12 @@ QUnit.test('Credit Error', async function (assert) {
return this._super(...arguments);
},
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -338,8 +380,11 @@ QUnit.test('Credit Error', async function (assert) {
notification_status: 'exception',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -415,6 +460,12 @@ QUnit.test('Trial Error', async function (assert) {
return this._super(...arguments);
},
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -424,8 +475,11 @@ QUnit.test('Trial Error', async function (assert) {
notification_status: 'exception',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -505,6 +559,12 @@ QUnit.test('Format Error', async function (assert) {
});
await this.start({ env: { bus } });
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -514,8 +574,11 @@ QUnit.test('Format Error', async function (assert) {
notification_status: 'exception',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]],
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,
@@ -575,6 +638,12 @@ QUnit.test('Missing Required Fields', async function (assert) {
return this._super(...arguments);
},
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'snailmail',
@@ -584,8 +653,11 @@ QUnit.test('Missing Required Fields', async function (assert) {
notification_status: 'exception',
notification_type: 'snail',
}]],
originThread: [['link', threadViewer.thread]]
});
await this.createMessageComponent(message, {
threadViewerLocalId: threadViewer.localId
});
await this.createMessageComponent(message);
assert.containsOnce(
document.body,