RATIONALE
Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.
PURPOSE
Remove channel ability to follow records as it mainly adds noise without a lot
of added value. Simplify channel notification flow by using directly members
and not a delegation through a channel self-following trick. Remove followers
being channels and posting with added listeners being channels.
SPECIFICATIONS
In this commit we force messages to belong to a single document using
``model`` / ``res_id`` pair. It is not possible anymore to link a message
to channels using ``channel_ids``. A message belongs to a document and
is displayed in that document's chatter.
This change implies modifying a lot of domains, notably in chatter. Indeed
discuss for channels does not use ``('channel_ids', 'in', [3])`` domains.
They now use ``('model', '=', 'mail.channel'), ('res_id', 'in', [3])`` like
other documents fetching their messages.
This commit also removes ``channel_message_ids`` field on ``mail.channel``
model. As channels are now considered as standard documents they will use
``message_ids`` field like all other documents. Linking a channel on a message
is possible only as a link in message from now on. It is not possible to push
it into a channel anymore (no more listener channels, no more channel link).
Finally a global cleaning also linked to all previous commits is done.
LINKS
Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models, _
|
|
from odoo.addons.http_routing.models.ir_http import url_for
|
|
|
|
|
|
class Website(models.Model):
|
|
|
|
_inherit = "website"
|
|
|
|
channel_id = fields.Many2one('im_livechat.channel', string='Website Live Chat Channel')
|
|
|
|
def get_livechat_channel_info(self):
|
|
""" Get the livechat info dict (button text, channel name, ...) for the livechat channel of
|
|
the current website.
|
|
"""
|
|
self.ensure_one()
|
|
if self.channel_id:
|
|
livechat_info = self.channel_id.sudo().get_livechat_info()
|
|
if livechat_info['available']:
|
|
livechat_request_session = self._get_livechat_request_session()
|
|
if livechat_request_session:
|
|
livechat_info['options']['chat_request_session'] = livechat_request_session
|
|
return livechat_info
|
|
return {}
|
|
|
|
def _get_livechat_request_session(self):
|
|
"""
|
|
Check if there is an opened chat request for the website livechat channel and the current visitor (from request).
|
|
If so, prepare the livechat session information that will be stored in visitor's cookies
|
|
and used by livechat widget to directly open this session instead of allowing the visitor to
|
|
initiate a new livechat session.
|
|
:param {int} channel_id: channel
|
|
:return: {dict} livechat request session information
|
|
"""
|
|
visitor = self.env['website.visitor']._get_visitor_from_request()
|
|
if visitor:
|
|
# get active chat_request linked to visitor
|
|
chat_request_channel = self.env['mail.channel'].sudo().search([
|
|
('livechat_visitor_id', '=', visitor.id),
|
|
('livechat_channel_id', '=', self.channel_id.id),
|
|
('livechat_active', '=', True),
|
|
('message_ids', '!=', False)
|
|
], order='create_date desc', limit=1)
|
|
if chat_request_channel:
|
|
return {
|
|
"folded": False,
|
|
"id": chat_request_channel.id,
|
|
"operator_pid": [
|
|
chat_request_channel.livechat_operator_id.id,
|
|
chat_request_channel.livechat_operator_id.display_name
|
|
],
|
|
"name": chat_request_channel.name,
|
|
"uuid": chat_request_channel.uuid,
|
|
"type": "chat_request"
|
|
}
|
|
return {}
|
|
|
|
def get_suggested_controllers(self):
|
|
suggested_controllers = super(Website, self).get_suggested_controllers()
|
|
suggested_controllers.append((_('Live Support'), url_for('/livechat'), 'website_livechat'))
|
|
return suggested_controllers
|