Skip to content

Commit 894ff2d

Browse files
committed
[IMP]mail_ux: avatar image loading time
1 parent 2ea70ea commit 894ff2d

4 files changed

Lines changed: 56 additions & 1 deletion

File tree

mail_ux/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
"name": "Mail UX",
22-
"version": "18.0.1.3.0",
22+
"version": "18.0.1.4.0",
2323
"category": "Base",
2424
"sequence": 14,
2525
"summary": "",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fields } from "@mail/core/common/record";
2+
import { ResUsers } from "@mail/core/common/res_users_model";
3+
import { patch } from "@web/core/utils/patch";
4+
5+
patch(ResUsers.prototype, {
6+
write_date: fields.Datetime(),
7+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Avatar } from "@mail/views/web/fields/avatar/avatar";
2+
import { useState } from "@odoo/owl";
3+
import { useService } from "@web/core/utils/hooks";
4+
import { patch } from "@web/core/utils/patch";
5+
import { imageUrl } from "@web/core/utils/urls";
6+
7+
patch(Avatar.prototype, {
8+
setup() {
9+
super.setup();
10+
this.store = useState(useService("mail.store"));
11+
},
12+
13+
/**
14+
* Builds the avatar image URL including a `unique` cache-buster when the
15+
* record's `write_date` is available in the mail store. This allows the
16+
* browser to cache avatars as immutable resources (up to 1 year), avoiding
17+
* a conditional HTTP request on every page load.
18+
*
19+
* Falls back to the plain URL (current Odoo behaviour) when `write_date`
20+
* is not yet known in the store.
21+
*/
22+
get avatarSrc() {
23+
const { resModel, resId } = this.props;
24+
let writeDate;
25+
26+
if (resModel === "res.users") {
27+
writeDate = this.store["res.users"].get(resId)?.partner_id?.write_date;
28+
} else if (resModel === "res.partner") {
29+
writeDate = this.store["res.partner"].get(resId)?.write_date;
30+
}
31+
32+
if (writeDate) {
33+
return imageUrl(resModel, resId, "avatar_128", { unique: writeDate });
34+
}
35+
return `/web/image/${resModel}/${resId}/avatar_128`;
36+
},
37+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="mail.Avatar" t-inherit="mail.Avatar" t-inherit-mode="primary">
5+
<xpath expr="//img" position="attributes">
6+
<attribute name="t-att-src">avatarSrc</attribute>
7+
<attribute name="t-attf-src"/>
8+
</xpath>
9+
</t>
10+
11+
</templates>

0 commit comments

Comments
 (0)