Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mail_ux/static/src/core/common/res_users_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { fields } from "@mail/core/common/record";
import { ResUsers } from "@mail/core/common/res_users_model";
import { patch } from "@web/core/utils/patch";

patch(ResUsers.prototype, {
write_date: fields.Datetime(),
});
37 changes: 37 additions & 0 deletions mail_ux/static/src/views/web/fields/avatar/avatar_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Avatar } from "@mail/views/web/fields/avatar/avatar";
import { useState } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { patch } from "@web/core/utils/patch";
import { imageUrl } from "@web/core/utils/urls";

patch(Avatar.prototype, {
setup() {
super.setup();
this.store = useState(useService("mail.store"));
},

/**
* Builds the avatar image URL including a `unique` cache-buster when the
* record's `write_date` is available in the mail store. This allows the
* browser to cache avatars as immutable resources (up to 1 year), avoiding
* a conditional HTTP request on every page load.
*
* Falls back to the plain URL (current Odoo behaviour) when `write_date`
* is not yet known in the store.
*/
get avatarSrc() {
const { resModel, resId } = this.props;
let writeDate;

if (resModel === "res.users") {
writeDate = this.store["res.users"].get(resId)?.partner_id?.write_date;
} else if (resModel === "res.partner") {
writeDate = this.store["res.partner"].get(resId)?.write_date;
}

if (writeDate) {
return imageUrl(resModel, resId, "avatar_128", { unique: writeDate });
}
return `/web/image/${resModel}/${resId}/avatar_128`;
},
});
11 changes: 11 additions & 0 deletions mail_ux/static/src/views/web/fields/avatar/avatar_patch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="mail.Avatar" t-inherit="mail.Avatar" t-inherit-mode="primary">
<xpath expr="//img" position="attributes">
<attribute name="t-att-src">avatarSrc</attribute>
<attribute name="t-attf-src"/>
</xpath>
</t>

</templates>
Loading