[IMP] mail: merge chat initial RPCs
Two RPCs were performed by the chat_manager on webclient launch. One of them was about emojis, and recent messages received in the past 10 minutes in detached channels. This RPC has been removed as the emojis fetching can be done in the other RPC (mail/client_action), and the recent messages are not useful since the refactoring of mail and the introduction of the chat_manager.
This commit is contained in:
@@ -50,14 +50,3 @@ class MailChatController(openerp.addons.bus.controllers.main.BusController):
|
||||
request_uid = self._default_request_uid()
|
||||
channel = request.env["mail.channel"].sudo(request_uid).search([('uuid', '=', uuid)], limit=1)
|
||||
return channel.sudo(request_uid).channel_fetch_message(last_id, limit)
|
||||
|
||||
@openerp.http.route('/mail/chat_init', type="json", auth="none")
|
||||
def mail_chat_init(self):
|
||||
result = {
|
||||
'emoji': request.env['mail.shortcode'].sudo().search_read([('shortcode_type', '=', 'image')], ['source', 'substitution', 'description'])
|
||||
}
|
||||
# include the previous notifications, only for identified user
|
||||
if request.session.uid:
|
||||
request_uid = self._default_request_uid()
|
||||
result['notifications'] = request.env['mail.channel'].sudo(request_uid).get_init_notifications()
|
||||
return result
|
||||
|
||||
@@ -243,5 +243,6 @@ class MailController(http.Controller):
|
||||
'needaction_inbox_counter': request.env['res.partner'].get_needaction_count(),
|
||||
'channel_slots': request.env['mail.channel'].channel_fetch_slot(),
|
||||
'mention_partner_suggestions': request.env['res.partner'].get_static_mention_suggestions(),
|
||||
'emoji': request.env['mail.shortcode'].sudo().search_read([('shortcode_type', '=', 'image')], ['source', 'substitution', 'description']),
|
||||
}
|
||||
return values
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from openerp import _, api, fields, models, modules, tools
|
||||
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from openerp.exceptions import UserError
|
||||
from openerp.osv import expression
|
||||
|
||||
from openerp.addons.bus.models.bus_presence import AWAY_TIMER
|
||||
|
||||
|
||||
class ChannelPartner(models.Model):
|
||||
@@ -452,40 +449,6 @@ class Channel(models.Model):
|
||||
#------------------------------------------------------
|
||||
# Instant Messaging View Specific (Slack Client Action)
|
||||
#------------------------------------------------------
|
||||
@api.model
|
||||
def get_init_notifications(self):
|
||||
""" Get unread messages and old messages received less than AWAY_TIMER
|
||||
ago of minimized channel ONLY. This aims to set the minimized channel
|
||||
when refreshing the page.
|
||||
Note : the user need to be logged
|
||||
"""
|
||||
# get current user's minimzed channel
|
||||
minimized_channels = self.env['mail.channel.partner'].search([('is_minimized', '=', True), ('partner_id', '=', self.env.user.partner_id.id)]).mapped('channel_id')
|
||||
|
||||
# get the message since the AWAY_TIMER
|
||||
threshold = datetime.datetime.now() - datetime.timedelta(seconds=AWAY_TIMER)
|
||||
threshold = threshold.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
domain = [('channel_ids', 'in', minimized_channels.ids), ('create_date', '>', threshold)]
|
||||
|
||||
# get the message since the last poll of the user
|
||||
presence = self.env['bus.presence'].search([('user_id', '=', self._uid)], limit=1)
|
||||
if presence:
|
||||
domain.append(('create_date', '>', presence.last_poll))
|
||||
|
||||
# do the message search
|
||||
message_values = self.env['mail.message'].message_fetch(domain=domain)
|
||||
|
||||
# create the notifications (channel infos first, then messages)
|
||||
notifications = []
|
||||
for channel_info in minimized_channels.channel_info():
|
||||
notifications.append([(self._cr.dbname, 'res.partner', self.env.user.partner_id.id), channel_info])
|
||||
for message_value in message_values:
|
||||
for channel_id in message_value['channel_ids']:
|
||||
if channel_id in minimized_channels.ids:
|
||||
message_value['channel_ids'] = [channel_id]
|
||||
notifications.append([(self._cr.dbname, 'mail.channel', channel_id), dict(message_value)])
|
||||
return notifications
|
||||
|
||||
@api.model
|
||||
def channel_fetch_slot(self):
|
||||
""" Return the channels of the user grouped by 'slot' (channel, direct_message or private_group), and
|
||||
|
||||
@@ -812,9 +812,6 @@ function init () {
|
||||
});
|
||||
needaction_counter = result.needaction_inbox_counter;
|
||||
mention_partner_suggestions = result.mention_partner_suggestions;
|
||||
});
|
||||
|
||||
var load_emojis = session.rpc("/mail/chat_init").then(function (result) {
|
||||
emojis = result.emoji;
|
||||
_.each(emojis, function(emoji) {
|
||||
emoji_substitutions[emoji.source] = emoji.substitution;
|
||||
@@ -827,7 +824,7 @@ function init () {
|
||||
|
||||
bus.on('notification', null, on_notification);
|
||||
|
||||
return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) {
|
||||
return $.when(load_menu_id, load_action_id, load_channels).then(function (menu_id, action_id) {
|
||||
discuss_ids = {
|
||||
menu_id: menu_id,
|
||||
action_id: action_id,
|
||||
|
||||
Reference in New Issue
Block a user