From 045673f80edbc1fb28be265419781f3f66e4cdc2 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Mon, 9 Jan 2023 13:05:53 +0100 Subject: [PATCH] [ADD] web_notify_channel_message --- .../odoo/addons/web_notify_channel_message | 1 + setup/web_notify_channel_message/setup.py | 6 ++++++ web_notify_channel_message/README.rst | 0 web_notify_channel_message/__init__.py | 1 + web_notify_channel_message/__manifest__.py | 16 ++++++++++++++ web_notify_channel_message/models/__init__.py | 1 + .../models/mail_channel.py | 21 +++++++++++++++++++ .../readme/CONTRIBUTORS.rst | 4 ++++ .../readme/DESCRIPTION.rst | 1 + 9 files changed, 51 insertions(+) create mode 120000 setup/web_notify_channel_message/odoo/addons/web_notify_channel_message create mode 100644 setup/web_notify_channel_message/setup.py create mode 100644 web_notify_channel_message/README.rst create mode 100644 web_notify_channel_message/__init__.py create mode 100644 web_notify_channel_message/__manifest__.py create mode 100644 web_notify_channel_message/models/__init__.py create mode 100644 web_notify_channel_message/models/mail_channel.py create mode 100644 web_notify_channel_message/readme/CONTRIBUTORS.rst create mode 100644 web_notify_channel_message/readme/DESCRIPTION.rst diff --git a/setup/web_notify_channel_message/odoo/addons/web_notify_channel_message b/setup/web_notify_channel_message/odoo/addons/web_notify_channel_message new file mode 120000 index 000000000..2f4f9a844 --- /dev/null +++ b/setup/web_notify_channel_message/odoo/addons/web_notify_channel_message @@ -0,0 +1 @@ +../../../../web_notify_channel_message \ No newline at end of file diff --git a/setup/web_notify_channel_message/setup.py b/setup/web_notify_channel_message/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_notify_channel_message/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_notify_channel_message/README.rst b/web_notify_channel_message/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/web_notify_channel_message/__init__.py b/web_notify_channel_message/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/web_notify_channel_message/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_notify_channel_message/__manifest__.py b/web_notify_channel_message/__manifest__.py new file mode 100644 index 000000000..ffe9b5aea --- /dev/null +++ b/web_notify_channel_message/__manifest__.py @@ -0,0 +1,16 @@ +# pylint: disable=missing-docstring +# Copyright 2023 ForgeFlow, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Web Notify Channel Message", + "summary": """ + Send an instant notification to channel users when a new message is posted""", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "development_status": "Alpha", + "website": "https://github.com/OCA/web", + "depends": ["web_notify", "mail"], + "installable": True, +} diff --git a/web_notify_channel_message/models/__init__.py b/web_notify_channel_message/models/__init__.py new file mode 100644 index 000000000..3ce7ca7fe --- /dev/null +++ b/web_notify_channel_message/models/__init__.py @@ -0,0 +1 @@ +from . import mail_channel diff --git a/web_notify_channel_message/models/mail_channel.py b/web_notify_channel_message/models/mail_channel.py new file mode 100644 index 000000000..ce1c55772 --- /dev/null +++ b/web_notify_channel_message/models/mail_channel.py @@ -0,0 +1,21 @@ +# pylint: disable=missing-docstring +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, models + + +class MailChannel(models.Model): + _inherit = "mail.channel" + + def message_post(self, *, message_type="notification", **kwargs): + message = super().message_post(message_type=message_type, **kwargs) + for partner in self.channel_partner_ids: + users = partner.user_ids + for user in users: + if user in message.author_id.user_ids: + continue + user.notify_info( + message=_("You have a new message in channel %s") % self.name + ) + return message diff --git a/web_notify_channel_message/readme/CONTRIBUTORS.rst b/web_notify_channel_message/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..56ac1356f --- /dev/null +++ b/web_notify_channel_message/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Joan Sisquella +* Thiago Mulero +* David Jimenez +* Jordi Ballester diff --git a/web_notify_channel_message/readme/DESCRIPTION.rst b/web_notify_channel_message/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ddb6ae81f --- /dev/null +++ b/web_notify_channel_message/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module will send an instant notifications to all users of a channel when a new message has been posted.