Skip to content

[19.0][FIX] mail_gateway: keep thread action conditions synchronous - #324

Open
vgavinas wants to merge 3 commits into
OCA:19.0from
vgavinas:19.0-fix-mail_gateway-thread_actions
Open

vgavinas wants to merge 3 commits into
OCA:19.0from
vgavinas:19.0-fix-mail_gateway-thread_actions

Conversation

@vgavinas

Copy link
Copy Markdown

Fixes #319.

The condition() of the open-gw-new-partner and open-gw-profile thread actions started an async searchRead and then called owner.render(). Conditions are evaluated on every render, so DiscussContent was re-rendered while still mounting and the Owl fiber never completed: Discuss showed no messages in any channel, without any error in the console.

Now the gateway partner of the channel and its single guest (if any) are sent with the channel store data (gateway_partner_id, gateway_guest_id), and the conditions only read them. After the guest is managed, the channel data is fetched again, so "Open Contact" replaces "New Partner" without reloading.

Tested on Odoo 19.0 CE with oca/mail 19.0 + #321 and a live WhatsApp Cloud API test number: Discuss shows the messages again, "New Partner" is shown for a guest sender and becomes "Open Contact" after creating the partner. mail_gateway tests: 0 failed, 0 errors (2 tests added).

Comment thread mail_gateway/models/discuss_channel.py
@vgavinas

Copy link
Copy Markdown
Author

@CarlosRoca13 Good point, thanks — done: _to_store now searches res.partner.gateway.channel once for the whole recordset. The single-record helpers are kept (used in the tests), and the if not record: continue is gone.

@pedrobaeza pedrobaeza added this to the 19.0 milestone Oct 28, 2026
@pedrobaeza

Copy link
Copy Markdown
Member

@etobella please check this important change

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error probably isn't related to this PR, but since the migration PR has been merged, could you check it? When I tested without this PR, the error didn't appear, but now, with these changes, I get this error. Maybe I just didn't notice it before and it was already there. I think it's more related to the migration.

Image

@carlos-lopez-tecnativa

Copy link
Copy Markdown
Contributor
image

These changes fix the error:

diff --git a/mail_gateway/static/src/core/common/message_model_patch.esm.js b/mail_gateway/static/src/core/common/message_model_patch.esm.js
index 1866de703..df00b207d 100644
--- a/mail_gateway/static/src/core/common/message_model_patch.esm.js
+++ b/mail_gateway/static/src/core/common/message_model_patch.esm.js
@@ -1,6 +1,6 @@
 import {Message} from "@mail/core/common/message_model";
 import {patch} from "@web/core/utils/patch";
-import {stateToUrl} from "@web/core/browser/router";
+import { router } from "@web/core/browser/router";
 import {url} from "@web/core/utils/urls";
 
 patch(Message.prototype, {
@@ -13,7 +13,7 @@ patch(Message.prototype, {
             return super.resUrl;
         }
         return url(
-            stateToUrl({
+            router.stateToUrl({
                 model: this.gateway_thread_data.model,
                 resId: this.gateway_thread_data.id,
             })

@etobella etobella left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically and functionaly ok.

According to AI Policy, Claude cannot be author/co-author, you should use assisted-by. Can you check that?

@vgavinas
vgavinas force-pushed the 19.0-fix-mail_gateway-thread_actions branch from 746983d to 8a4c942 Compare October 28, 2026 13:58
@vgavinas

Copy link
Copy Markdown
Author

@etobella Thanks for the review! Done — the commit now uses Assisted-by: Claude Opus 5.5 instead of Co-authored-by.

@luisDIXMIT luisDIXMIT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on runboat, LGTM! Thanks for your work!

@vgavinas

Copy link
Copy Markdown
Author

@carlos-lopez-tecnativa Thanks for spotting this — your fix is applied in 8a4c942 (router.stateToUrl). Could you take another look when you have a moment?

@etobella

Copy link
Copy Markdown
Member

/ocabot rebase

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, PR rebased to 19.0.

@etobella

Copy link
Copy Markdown
Member

Sorry to rebase again, but the new CLA Bot is there, and I want to check that everything works nicely

/ocabot rebase

The conditions of the "New Partner" and "Open Contact" thread actions
started an async searchRead and then re-rendered the owner. Conditions are
evaluated on every render, so this re-rendered DiscussContent while it was
still mounting and the Owl fiber never completed: Discuss showed no
messages in any channel.

The gateway partner and the single guest of the channel are now sent with
the channel store data, and the conditions only read them.

Fixes OCA#319

Assisted-by: Claude Opus 5.5
_to_store runs for every channel of the user on Discuss load: search
res.partner.gateway.channel once for the whole recordset instead of once
per gateway channel.
stateToUrl is not exported by @web/core/browser/router in 19.0 (only
through the router object), so building the URL of a gateway message
failed as soon as such a message was rendered. It went unnoticed while
Discuss did not render any message.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, PR rebased to 19.0.

@OCA-git-bot
OCA-git-bot force-pushed the 19.0-fix-mail_gateway-thread_actions branch from 8a4c942 to 96f2134 Compare October 28, 2026 14:26
@oca-cla-bot

oca-cla-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@etobella

Copy link
Copy Markdown
Member

@vgavinas I think you need to sign the CLA

@vgavinas

Copy link
Copy Markdown
Author

@etobella Done — CLA signed, the check is green now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[19.0] mail_gateway: Discuss shows no messages (thread action conditions re-render the owner)

7 participants