diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53161f0a03..44298cbb8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ exclude: | (LICENSE.*|COPYING.*) default_language_version: python: python3 - node: "16.17.0" + node: system repos: - repo: local hooks: diff --git a/mail_discuss_channel_hide_sidebar/README.rst b/mail_discuss_channel_hide_sidebar/README.rst new file mode 100644 index 0000000000..05c4fb264d --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/README.rst @@ -0,0 +1,92 @@ +================================= +Mail Discuss Channel Hide Sidebar +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ce66e5e1521809c0aa1260386bb2d48a121a174c1cd67c6b0a3b3d0ba2db5fa4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/17.0/mail_discuss_channel_hide_sidebar + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_discuss_channel_hide_sidebar + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a "Hide from list" action in Discuss sidebar channels. + +The action hides the channel for the current user without unsubscribing. +If a new message arrives in that channel, it appears again +automatically. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to Discuss and open the Channels sidebar section. + +Hover a channel and click the new eye-slash icon to hide it from the +list. You remain subscribed to the channel. + +When a new message is posted in that channel, it becomes visible again. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* APSL-Nagarro + +Contributors +------------ + +- `APSL Nagarro `__ + + - Miquel Alzanillas + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_discuss_channel_hide_sidebar/__init__.py b/mail_discuss_channel_hide_sidebar/__init__.py new file mode 100644 index 0000000000..31660d6a96 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mail_discuss_channel_hide_sidebar/__manifest__.py b/mail_discuss_channel_hide_sidebar/__manifest__.py new file mode 100644 index 0000000000..6eb65d15ec --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/__manifest__.py @@ -0,0 +1,23 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Discuss Channel Hide Sidebar", + "summary": ( + "Hide subscribed channels from Discuss sidebar " "until a new message arrives" + ), + "version": "17.0.1.0.0", + "category": "Discuss", + "author": "APSL-Nagarro, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "license": "AGPL-3", + "depends": ["mail"], + "assets": { + "web.assets_backend": [ + "mail_discuss_channel_hide_sidebar/static/src/core/common/channel_member_model_patch.esm.js", + "mail_discuss_channel_hide_sidebar/static/src/discuss/core/common/discuss_core_common_service_patch.esm.js", + "mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.esm.js", + "mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.xml", + ], + }, + "installable": True, +} diff --git a/mail_discuss_channel_hide_sidebar/models/__init__.py b/mail_discuss_channel_hide_sidebar/models/__init__.py new file mode 100644 index 0000000000..4184e13dcd --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import discuss_channel +from . import discuss_channel_member diff --git a/mail_discuss_channel_hide_sidebar/models/discuss_channel.py b/mail_discuss_channel_hide_sidebar/models/discuss_channel.py new file mode 100644 index 0000000000..b6e0bad6bd --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/models/discuss_channel.py @@ -0,0 +1,46 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class DiscussChannel(models.Model): + _inherit = "discuss.channel" + + def _get_self_member(self): + self.ensure_one() + current_partner, current_guest = self.env["res.partner"]._get_current_persona() + domain = [("channel_id", "=", self.id)] + if current_partner: + domain.append(("partner_id", "=", current_partner.id)) + elif current_guest: + domain.append(("guest_id", "=", current_guest.id)) + else: + return self.env["discuss.channel.member"] + return self.env["discuss.channel.member"].search(domain, limit=1) + + def action_set_sidebar_hidden(self, hidden=True): + self.ensure_one() + member = self._get_self_member() + if not member: + return + vals = {"is_sidebar_hidden": bool(hidden)} + if hidden: + vals["is_pinned"] = False + member.write(vals) + if hidden: + # Keep native unpin bus behavior for immediate UI feedback. + self.env["bus.bus"]._sendone( + self.env.user.partner_id, "discuss.channel/unpin", {"id": self.id} + ) + else: + self.env["bus.bus"]._sendone( + self.env.user.partner_id, + "mail.record/insert", + {"Thread": self._channel_info()[0]}, + ) + + @api.returns("mail.message", lambda value: value.id) + def message_post(self, *, message_type="notification", **kwargs): + # Any new activity makes hidden channels visible again for members. + self.sudo().channel_member_ids.write({"is_sidebar_hidden": False}) + return super().message_post(message_type=message_type, **kwargs) diff --git a/mail_discuss_channel_hide_sidebar/models/discuss_channel_member.py b/mail_discuss_channel_hide_sidebar/models/discuss_channel_member.py new file mode 100644 index 0000000000..056547858d --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/models/discuss_channel_member.py @@ -0,0 +1,24 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class DiscussChannelMember(models.Model): + _inherit = "discuss.channel.member" + + is_sidebar_hidden = fields.Boolean( + string="Hidden in Discuss sidebar", + default=False, + help=( + "If enabled, this channel is hidden from the Discuss sidebar " + "for this member." + ), + ) + + def _discuss_channel_member_format(self, fields=None): + include_sidebar_hidden = not fields or fields.get("is_sidebar_hidden") + member_data = super()._discuss_channel_member_format(fields=fields) + if include_sidebar_hidden: + for member, values in member_data.items(): + values["is_sidebar_hidden"] = member.is_sidebar_hidden + return member_data diff --git a/mail_discuss_channel_hide_sidebar/pyproject.toml b/mail_discuss_channel_hide_sidebar/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_discuss_channel_hide_sidebar/readme/CONTRIBUTORS.md b/mail_discuss_channel_hide_sidebar/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..60601749f0 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [APSL Nagarro](https://nagarro.com) + - Miquel Alzanillas diff --git a/mail_discuss_channel_hide_sidebar/readme/DESCRIPTION.md b/mail_discuss_channel_hide_sidebar/readme/DESCRIPTION.md new file mode 100644 index 0000000000..374f79deca --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module adds a "Hide from list" action in Discuss sidebar channels. + +The action hides the channel for the current user without unsubscribing. +If a new message arrives in that channel, it appears again automatically. diff --git a/mail_discuss_channel_hide_sidebar/readme/USAGE.md b/mail_discuss_channel_hide_sidebar/readme/USAGE.md new file mode 100644 index 0000000000..7702f26468 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/readme/USAGE.md @@ -0,0 +1,6 @@ +Go to Discuss and open the Channels sidebar section. + +Hover a channel and click the new eye-slash icon to hide it from the list. +You remain subscribed to the channel. + +When a new message is posted in that channel, it becomes visible again. diff --git a/mail_discuss_channel_hide_sidebar/static/description/icon.png b/mail_discuss_channel_hide_sidebar/static/description/icon.png new file mode 100644 index 0000000000..e78da4cfd0 Binary files /dev/null and b/mail_discuss_channel_hide_sidebar/static/description/icon.png differ diff --git a/mail_discuss_channel_hide_sidebar/static/description/index.html b/mail_discuss_channel_hide_sidebar/static/description/index.html new file mode 100644 index 0000000000..f1aecf1764 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +Mail Discuss Channel Hide Sidebar + + + +
+

Mail Discuss Channel Hide Sidebar

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module adds a “Hide from list” action in Discuss sidebar channels.

+

The action hides the channel for the current user without unsubscribing. +If a new message arrives in that channel, it appears again +automatically.

+

Table of contents

+ +
+

Usage

+

Go to Discuss and open the Channels sidebar section.

+

Hover a channel and click the new eye-slash icon to hide it from the +list. You remain subscribed to the channel.

+

When a new message is posted in that channel, it becomes visible again.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • APSL-Nagarro
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_discuss_channel_hide_sidebar/static/src/core/common/channel_member_model_patch.esm.js b/mail_discuss_channel_hide_sidebar/static/src/core/common/channel_member_model_patch.esm.js new file mode 100644 index 0000000000..dff6b747ec --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/static/src/core/common/channel_member_model_patch.esm.js @@ -0,0 +1,10 @@ +/* @odoo-module */ + +import {ChannelMember} from "@mail/core/common/channel_member_model"; +import {Record} from "@mail/core/common/record"; + +import {patch} from "@web/core/utils/patch"; + +patch(ChannelMember.prototype, { + is_sidebar_hidden: Record.attr(false), +}); diff --git a/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.esm.js b/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.esm.js new file mode 100644 index 0000000000..71654eb577 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.esm.js @@ -0,0 +1,43 @@ +/* @odoo-module */ + +import {DiscussSidebarCategories} from "@mail/discuss/core/web/discuss_sidebar_categories"; + +import {patch} from "@web/core/utils/patch"; + +patch(DiscussSidebarCategories.prototype, { + filteredThreads(category) { + const threads = super.filteredThreads(category); + if (category.id !== "channels") { + return threads; + } + return threads.filter((thread) => { + const selfMember = thread.selfMember; + const isHidden = selfMember && selfMember.is_sidebar_hidden; + if (!isHidden) { + return true; + } + return ( + (thread.message_unread_counter || 0) > 0 || + (thread.message_needaction_counter || 0) > 0 + ); + }); + }, + + async hideChannel(thread) { + await this.orm.call( + "discuss.channel", + "action_set_sidebar_hidden", + [[thread.id]], + { + hidden: true, + } + ); + thread.is_pinned = false; + if (thread.selfMember) { + thread.selfMember.is_sidebar_hidden = true; + } + if (thread.eq(this.store.discuss.thread)) { + this.threadService.setDiscussThread(this.store.discuss.inbox); + } + }, +}); diff --git a/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.xml b/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.xml new file mode 100644 index 0000000000..fb2144d831 --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/static/src/core/web/discuss_sidebar_categories_patch.xml @@ -0,0 +1,21 @@ + + + + +
+ + + diff --git a/mail_discuss_channel_hide_sidebar/static/src/discuss/core/common/discuss_core_common_service_patch.esm.js b/mail_discuss_channel_hide_sidebar/static/src/discuss/core/common/discuss_core_common_service_patch.esm.js new file mode 100644 index 0000000000..fa67c56ffb --- /dev/null +++ b/mail_discuss_channel_hide_sidebar/static/src/discuss/core/common/discuss_core_common_service_patch.esm.js @@ -0,0 +1,19 @@ +/* @odoo-module */ + +import {DiscussCoreCommon} from "@mail/discuss/core/common/discuss_core_common_service"; + +import {patch} from "@web/core/utils/patch"; + +patch(DiscussCoreCommon.prototype, { + async _handleNotificationNewMessage(notif) { + await super._handleNotificationNewMessage(notif); + const channel = this.store.Thread.get({ + id: notif.payload.id, + model: "discuss.channel", + }); + if (channel && channel.selfMember) { + channel.is_pinned = true; + channel.selfMember.is_sidebar_hidden = false; + } + }, +});