Allow users to unfollow easily document from the inbox for which he/she doesn't want to be notified anymore. When hovering on a follow up message with a related document followed by the user, the interface displays an action to unfollow it that allows the user to remove himself/herself as follower of the document. As a result of performing that action a toast is displayed as a feedback. Technical note: The unfollow link is displayed on a message.canUnfollow is true which check that the thread related to the message is followed by the user. In order to know if the user follows the record related to the message, we now transmit with each message the id of the follower table that link the user to the related record if it follows it. This allows to insert the follower on client side so that the unfollow action can use the standard mechaism already developed to unfollow a record. Unfortunately, that information coudn't be added in the already public method message_format of mail message because that method is not always called on the user retreiving the message but also by the one posting message. We didn't want also to include all followers in the formated message so we rely on additional method that add that information per partner. To support unfollowing a document in the inbox no matter the current company, we have modified message_unsubscribe in mail_thread to allow internal user to unsubscribe themself without checking any rights. Indeed, some document have record rule that prevents reading it if the user is not in the right company (ex. crm.lead) and then was preventing the user to unfollow the document using that method. Task-3061864 Part-of: odoo/odoo#107978
25 lines
1.3 KiB
Python
25 lines
1.3 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class MailboxController(http.Controller):
|
|
@http.route("/mail/inbox/messages", methods=["POST"], type="json", auth="user")
|
|
def discuss_inbox_messages(self, before=None, after=None, limit=30, around=None):
|
|
partner_id = request.env.user.partner_id.id
|
|
domain = [("needaction", "=", True)]
|
|
return (request.env["mail.message"]
|
|
._message_fetch(domain, before, after, around, limit)
|
|
._message_format_personalize(partner_id))
|
|
|
|
@http.route("/mail/history/messages", methods=["POST"], type="json", auth="user")
|
|
def discuss_history_messages(self, before=None, after=None, limit=30):
|
|
domain = [("needaction", "=", False)]
|
|
return request.env["mail.message"]._message_fetch(domain, before, after, limit=limit).message_format()
|
|
|
|
@http.route("/mail/starred/messages", methods=["POST"], type="json", auth="user")
|
|
def discuss_starred_messages(self, before=None, after=None, limit=30):
|
|
domain = [("starred_partner_ids", "in", [request.env.user.partner_id.id])]
|
|
return request.env["mail.message"]._message_fetch(domain, before, after, limit=limit).message_format()
|