From 442edacee2129c8b2c7ffa4005dc9c03dc8b1014 Mon Sep 17 00:00:00 2001 From: zel-odoo Date: Thu, 2 Nov 2023 16:00:32 +0100 Subject: [PATCH] [FIX] mail: not _notify_thread_by_web_push if mute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not send the web_push notificaiton if the channel is muted. closes odoo/odoo#140285 Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/discuss/discuss_channel.py | 2 +- addons/test_mail_full/tests/test_web_push.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/discuss/discuss_channel.py b/addons/mail/models/discuss/discuss_channel.py index d7925863b1c..1f5e9021f7e 100644 --- a/addons/mail/models/discuss/discuss_channel.py +++ b/addons/mail/models/discuss/discuss_channel.py @@ -1223,7 +1223,7 @@ class Channel(models.Model): 'type': 'customer', 'groups': [], } - for partner in chat_channels.mapped("channel_partner_ids") + for partner in chat_channels.channel_member_ids.filtered(lambda member: not member.mute_until_dt).partner_id ] else: channel_rdata = recipients_data diff --git a/addons/test_mail_full/tests/test_web_push.py b/addons/test_mail_full/tests/test_web_push.py index 014f44ddb48..24474c126e4 100644 --- a/addons/test_mail_full/tests/test_web_push.py +++ b/addons/test_mail_full/tests/test_web_push.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import json import socket +from datetime import datetime import odoo from odoo.tools.misc import mute_logger @@ -167,7 +168,23 @@ class TestWebPushNotification(SMSCommon): self._assert_notification_count_for_cron(0) push_to_end_point.assert_called_once() + self.assertEqual(push_to_end_point.call_args.kwargs['device']['endpoint'], 'https://test.odoo.com/webpush/user2') + # Reset the mock counter + push_to_end_point.reset_mock() + + # Test Direct Message with channel Muted + self.env['discuss.channel.member'].search([ + ('partner_id', '=', self.user_inbox.partner_id.id), + ('channel_id', '=', self.direct_message_channel.id), + ]).write({ + 'mute_until_dt': datetime(9999, 1, 1, 14, 00), + }) + self.direct_message_channel.with_user(self.user_email).message_post( + body='Test', message_type='comment', subtype_xmlid='mail.mt_comment') + + self._assert_notification_count_for_cron(0) + push_to_end_point.assert_not_called() # Reset the mock counter push_to_end_point.reset_mock()