diff --git a/mail_base/README.rst b/mail_base/README.rst index 0aa46ac..9e936a2 100644 --- a/mail_base/README.rst +++ b/mail_base/README.rst @@ -6,14 +6,23 @@ Mail Base * fixes toggling left bar * fixes Recipients field. Out-of-box this field could be empty. -Usage ------ -To use this module you need either install module that depends on it or create new module. +One can say, that the module do this todo from `addons/mail/static/src/js/chat_manager.js `__ + + // to do: move this to mail.utils + + + +Note. Due to odoo restrictions, module makes mail initialization again. That is browser loads emoji and other chat data twice. This is the only way to make Mail feature extendable. Further information -------------------- -Due to odoo restrictions, module makes mail initialization again. That is browser loads emoji and other chat data twice. This is the only way to make Mail feature extendable. +=================== -One can say, that the module do this todo from `addons/mail/static/src/js/chat_manager.js `__ +Demo: http://runbot.it-projects.info/demo/mail-addons/9.0 - // to do: move this to mail.utils +.. HTML Description: https://apps.odoo.com/apps/modules/9.0/mail_base/ + +Usage instructions: ``_ + +Changelog: ``_ + +Tested on Odoo 9.0 c8cd67c5d98b410cabe0a6efb3347a8a4de731d8 diff --git a/mail_base/__init__.py b/mail_base/__init__.py index cde864b..c3d410e 100644 --- a/mail_base/__init__.py +++ b/mail_base/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import models +from . import controllers diff --git a/mail_base/__openerp__.py b/mail_base/__openerp__.py index b9c9b6d..8f56427 100644 --- a/mail_base/__openerp__.py +++ b/mail_base/__openerp__.py @@ -4,7 +4,7 @@ "summary": """Makes Mail extendable""", "category": "Discuss", "images": [], - "version": "1.0.0", + "version": "1.0.1", "author": "IT-Projects LLC, Pavel Romanchenko", "website": "https://it-projects.info", diff --git a/mail_base/controllers/__init__.py b/mail_base/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/mail_base/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/mail_base/controllers/main.py b/mail_base/controllers/main.py new file mode 100644 index 0000000..8812df9 --- /dev/null +++ b/mail_base/controllers/main.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from openerp.http import request +import openerp + + +class MailChatController(openerp.addons.bus.controllers.main.BusController): + # ----------------------------- + # Extends BUS Controller Poll + # ----------------------------- + + def _poll(self, dbname, channels, last, options): + if request.session.uid: + channels.append((request.db, 'mail_base.mail_sent')) + + return super(MailChatController, self)._poll(dbname, channels, last, options) diff --git a/mail_base/doc/changelog.rst b/mail_base/doc/changelog.rst new file mode 100644 index 0000000..a42098f --- /dev/null +++ b/mail_base/doc/changelog.rst @@ -0,0 +1,9 @@ +`1.0.1` +------- + +- **FIX**: clear messages cache on sending message via Mail Composer. Otherwise Sent, Arhives menus will have new message until user refresh whole web page + +`1.0.0` +------- + +- Init version diff --git a/mail_base/doc/index.rst b/mail_base/doc/index.rst new file mode 100644 index 0000000..9f8b977 --- /dev/null +++ b/mail_base/doc/index.rst @@ -0,0 +1,4 @@ +Mail Base +========= + +To use this module you need either install module that depends on it or create new module. diff --git a/mail_base/models.py b/mail_base/models.py index ade9a35..953f49f 100644 --- a/mail_base/models.py +++ b/mail_base/models.py @@ -16,3 +16,16 @@ class MailMessage(models.Model): for id in triplet[2]: values['partner_ids'].append((4, id, False)) return super(MailMessage, self).write(values) + + +class MailComposer(models.TransientModel): + + _inherit = 'mail.compose.message' + + @api.multi + def send_mail(self, auto_commit=False): + res = super(MailComposer, self).send_mail(auto_commit=auto_commit) + notification = {} + self.env['bus.bus'].sendone((self._cr.dbname, 'mail_base.mail_sent'), notification) + + return res diff --git a/mail_base/static/src/js/base.js b/mail_base/static/src/js/base.js index 53c9f0e..a9d64ef 100644 --- a/mail_base/static/src/js/base.js +++ b/mail_base/static/src/js/base.js @@ -482,6 +482,12 @@ var MailTools = core.Class.extend({ }); }, + clear_cache_all_channels: function(){ + _.each(channels, function(channel){ + channel.cache = {}; + }) + }, + add_to_cache: function (message, domain) { _.each(message.channel_ids, function (channel_id) { var channel = chat_manager.get_channel(channel_id); @@ -616,6 +622,14 @@ var MailTools = core.Class.extend({ } else if (model === 'bus.presence') { // update presence of users chat_manager.mail_tools.on_presence_notification(notification[1]); + } else if (model === 'mail_base.mail_sent') { + // Delete cache in order to fetch new message + + // TODO find a solution without deleting cache. Currently + // problem is that on inheriting send_mail in + // mail.compose.message it's not possible to get id of new + // message + chat_manager.mail_tools.clear_cache_all_channels(); } }); },