Skip to content

Commit 2558768

Browse files
committed
[FIX] mail: improve subject of message in inbox
PURPOSE Displaying the subject when the name of the record is exactly the same is redundant and crowds the interface needlessly SPECIFICATION Subject should only be displayed if it is different than the name of the record LINKS closes odoo#61044 Taskid: 2363130 Pr: odoo#61044 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
1 parent 5d9ed8b commit 2558768

File tree

3 files changed

+222
-1
lines changed

3 files changed

+222
-1
lines changed

addons/mail/static/src/components/discuss/tests/discuss_inbox_tests.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,174 @@ QUnit.test('click on (non-channel/non-partner) origin thread link should redirec
550550
assert.verifySteps(['do-action'], "should have made an action on click on origin thread (to open form view)");
551551
});
552552

553+
QUnit.test('subject should not be shown when subject is the same as the thread name', async function (assert) {
554+
assert.expect(1);
555+
556+
this.data['mail.message'].records.push({
557+
body: "not empty",
558+
channel_ids: [100],
559+
model: 'mail.channel',
560+
res_id: 100,
561+
needaction: true,
562+
subject: "Salutations, voyageur",
563+
});
564+
this.data['mail.channel'].records.push({
565+
id: 100,
566+
name: "Salutations, voyageur",
567+
});
568+
await this.start();
569+
570+
assert.containsNone(
571+
document.body,
572+
'.o_Message_subject',
573+
"subject should not be shown when subject is the same as the thread name"
574+
);
575+
});
576+
577+
QUnit.test('subject should not be shown when subject is the same as the thread name and both have the same prefix', async function (assert) {
578+
assert.expect(1);
579+
580+
this.data['mail.message'].records.push({
581+
body: "not empty",
582+
channel_ids: [100],
583+
model: 'mail.channel',
584+
res_id: 100,
585+
needaction: true,
586+
subject: "Re: Salutations, voyageur",
587+
});
588+
this.data['mail.channel'].records.push({
589+
id: 100,
590+
name: "Re: Salutations, voyageur",
591+
});
592+
await this.start();
593+
594+
assert.containsNone(
595+
document.body,
596+
'.o_Message_subject',
597+
"subject should not be shown when subject is the same as the thread name and both have the same prefix"
598+
);
599+
});
600+
601+
QUnit.test('subject should not be shown when subject differs from thread name only by the "Re:" prefix', async function (assert) {
602+
assert.expect(1);
603+
604+
this.data['mail.message'].records.push({
605+
body: "not empty",
606+
channel_ids: [100],
607+
model: 'mail.channel',
608+
res_id: 100,
609+
needaction: true,
610+
subject: "Re: Salutations, voyageur",
611+
});
612+
this.data['mail.channel'].records.push({
613+
id: 100,
614+
name: "Salutations, voyageur",
615+
});
616+
await this.start();
617+
618+
assert.containsNone(
619+
document.body,
620+
'.o_Message_subject',
621+
"should not display subject when subject differs from thread name only by the 'Re:' prefix"
622+
);
623+
});
624+
625+
QUnit.test('subject should not be shown when subject differs from thread name only by the "Fw:" and "Re:" prefix', async function (assert) {
626+
assert.expect(1);
627+
628+
this.data['mail.message'].records.push({
629+
body: "not empty",
630+
channel_ids: [100],
631+
model: 'mail.channel',
632+
res_id: 100,
633+
needaction: true,
634+
subject: "Fw: Re: Salutations, voyageur",
635+
});
636+
this.data['mail.channel'].records.push({
637+
id: 100,
638+
name: "Salutations, voyageur",
639+
});
640+
await this.start();
641+
642+
assert.containsNone(
643+
document.body,
644+
'.o_Message_subject',
645+
"should not display subject when subject differs from thread name only by the 'Fw:' and Re:' prefix"
646+
);
647+
});
648+
649+
QUnit.test('subject should be shown when the thread name has an extra prefix compared to subject', async function (assert) {
650+
assert.expect(1);
651+
652+
this.data['mail.message'].records.push({
653+
body: "not empty",
654+
channel_ids: [100],
655+
model: 'mail.channel',
656+
res_id: 100,
657+
needaction: true,
658+
subject: "Salutations, voyageur",
659+
});
660+
this.data['mail.channel'].records.push({
661+
id: 100,
662+
name: "Re: Salutations, voyageur",
663+
});
664+
await this.start();
665+
666+
assert.containsOnce(
667+
document.body,
668+
'.o_Message_subject',
669+
"subject should be shown when the thread name has an extra prefix compared to subject"
670+
);
671+
});
672+
673+
QUnit.test('subject should not be shown when subject differs from thread name only by the "fw:" prefix and both contain another common prefix', async function (assert) {
674+
assert.expect(1);
675+
676+
this.data['mail.message'].records.push({
677+
body: "not empty",
678+
channel_ids: [100],
679+
model: 'mail.channel',
680+
res_id: 100,
681+
needaction: true,
682+
subject: "fw: re: Salutations, voyageur",
683+
});
684+
this.data['mail.channel'].records.push({
685+
id: 100,
686+
name: "Re: Salutations, voyageur",
687+
});
688+
await this.start();
689+
690+
assert.containsNone(
691+
document.body,
692+
'.o_Message_subject',
693+
"subject should not be shown when subject differs from thread name only by the 'fw:' prefix and both contain another common prefix"
694+
);
695+
});
696+
697+
QUnit.test('subject should not be shown when subject differs from thread name only by the "Re: Re:" prefix', async function (assert) {
698+
assert.expect(1);
699+
700+
this.data['mail.message'].records.push({
701+
body: "not empty",
702+
channel_ids: [100],
703+
model: 'mail.channel',
704+
res_id: 100,
705+
needaction: true,
706+
subject: "Re: Re: Salutations, voyageur",
707+
});
708+
this.data['mail.channel'].records.push({
709+
id: 100,
710+
name: "Salutations, voyageur",
711+
});
712+
await this.start();
713+
714+
assert.containsNone(
715+
document.body,
716+
'.o_Message_subject',
717+
"should not display subject when subject differs from thread name only by the 'Re: Re:'' prefix"
718+
);
719+
});
720+
553721
});
554722
});
555723
});

addons/mail/static/src/components/message/message.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
</ul>
178178
</t>
179179
</div>
180-
<t t-if="message.subject and threadView and threadView.thread and (threadView.thread.mass_mailing or [env.messaging.inbox, env.messaging.history].includes(threadView.thread))">
180+
<t t-if="message.subject and !message.isSubjectSimilarToOriginThreadName and threadView and threadView.thread and (threadView.thread.mass_mailing or [env.messaging.inbox, env.messaging.history].includes(threadView.thread))">
181181
<p class="o_Message_subject">Subject: <t t-esc="message.subject"/></p>
182182
</t>
183183
<t t-if="message.attachments and message.attachments.length > 0">

addons/mail/static/src/models/message/message.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,37 @@ function factory(dependencies) {
465465
this.originThread.isModeratedByCurrentPartner
466466
);
467467
}
468+
/**
469+
* @private
470+
* @returns {boolean}
471+
*/
472+
_computeIsSubjectSimilarToOriginThreadName() {
473+
if (
474+
!this.subject ||
475+
!this.originThread ||
476+
!this.originThread.name
477+
) {
478+
return false;
479+
}
480+
const threadName = this.originThread.name.toLowerCase().trim();
481+
const prefixList = ['re:', 'fw:', 'fwd:'];
482+
let cleanedSubject = this.subject.toLowerCase();
483+
let wasSubjectCleaned = true;
484+
while (wasSubjectCleaned) {
485+
wasSubjectCleaned = false;
486+
if (threadName === cleanedSubject) {
487+
return true;
488+
}
489+
for (const prefix of prefixList) {
490+
if (cleanedSubject.startsWith(prefix)) {
491+
cleanedSubject = cleanedSubject.replace(prefix, '').trim();
492+
wasSubjectCleaned = true;
493+
break;
494+
}
495+
}
496+
}
497+
return false;
498+
}
468499

469500
/**
470501
* @private
@@ -636,6 +667,22 @@ function factory(dependencies) {
636667
'originThreadIsModeratedByCurrentPartner',
637668
],
638669
}),
670+
/**
671+
* States whether `originThread.name` and `subject` contain similar
672+
* values except it contains the extra prefix at the start
673+
* of the subject.
674+
*
675+
* This is necessary to avoid displaying the subject, if
676+
* the subject is same as threadname.
677+
*/
678+
isSubjectSimilarToOriginThreadName: attr({
679+
compute: '_computeIsSubjectSimilarToOriginThreadName',
680+
dependencies: [
681+
'originThread',
682+
'originThreadName',
683+
'subject',
684+
],
685+
}),
639686
isTemporary: attr({
640687
default: false,
641688
}),
@@ -710,6 +757,12 @@ function factory(dependencies) {
710757
default: false,
711758
related: 'originThread.isModeratedByCurrentPartner',
712759
}),
760+
/**
761+
* Serves as compute dependency for isSubjectSimilarToOriginThreadName
762+
*/
763+
originThreadName: attr({
764+
related: 'originThread.name',
765+
}),
713766
/**
714767
* This value is meant to be based on field body which is
715768
* returned by the server (and has been sanitized before stored into db).

0 commit comments

Comments
 (0)