From 4c60be8c913b05b6829af09e515e3c37d2edb10c Mon Sep 17 00:00:00 2001 From: mav-adhoc Date: Tue, 7 Apr 2026 11:45:32 -0300 Subject: [PATCH] [IMP]mail_ux: avatar image loading time --- .../static/src/core/common/res_users_patch.js | 7 ++++ .../views/web/fields/avatar/avatar_patch.js | 37 +++++++++++++++++++ .../views/web/fields/avatar/avatar_patch.xml | 11 ++++++ 3 files changed, 55 insertions(+) create mode 100644 mail_ux/static/src/core/common/res_users_patch.js create mode 100644 mail_ux/static/src/views/web/fields/avatar/avatar_patch.js create mode 100644 mail_ux/static/src/views/web/fields/avatar/avatar_patch.xml diff --git a/mail_ux/static/src/core/common/res_users_patch.js b/mail_ux/static/src/core/common/res_users_patch.js new file mode 100644 index 00000000..f16e9b34 --- /dev/null +++ b/mail_ux/static/src/core/common/res_users_patch.js @@ -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(), +}); diff --git a/mail_ux/static/src/views/web/fields/avatar/avatar_patch.js b/mail_ux/static/src/views/web/fields/avatar/avatar_patch.js new file mode 100644 index 00000000..801779b3 --- /dev/null +++ b/mail_ux/static/src/views/web/fields/avatar/avatar_patch.js @@ -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`; + }, +}); diff --git a/mail_ux/static/src/views/web/fields/avatar/avatar_patch.xml b/mail_ux/static/src/views/web/fields/avatar/avatar_patch.xml new file mode 100644 index 00000000..c12dcb9f --- /dev/null +++ b/mail_ux/static/src/views/web/fields/avatar/avatar_patch.xml @@ -0,0 +1,11 @@ + + + + + + avatarSrc + + + + +