Browse Source

[FIX] clear messages cache on sending message via Mail Composer. Otherwise Sent, Arhives menus will have new message until user refresh whole web page

[DOC] refactoring in docs
pull/78/head
Ivan Yelizariev 8 years ago
parent
commit
5cf4bf8481
  1. 23
      mail_base/README.rst
  2. 1
      mail_base/__init__.py
  3. 2
      mail_base/__openerp__.py
  4. 1
      mail_base/controllers/__init__.py
  5. 15
      mail_base/controllers/main.py
  6. 9
      mail_base/doc/changelog.rst
  7. 4
      mail_base/doc/index.rst
  8. 13
      mail_base/models.py
  9. 14
      mail_base/static/src/js/base.js

23
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 <https://github.com/odoo/odoo/blob/9.0/addons/mail/static/src/js/chat_manager.js#L57>`__
// 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 <https://github.com/odoo/odoo/blob/9.0/addons/mail/static/src/js/chat_manager.js#L57>`__
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: `<doc/index.rst>`_
Changelog: `<doc/changelog.rst>`_
Tested on Odoo 9.0 c8cd67c5d98b410cabe0a6efb3347a8a4de731d8

1
mail_base/__init__.py

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import models
from . import controllers

2
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",

1
mail_base/controllers/__init__.py

@ -0,0 +1 @@
from . import main

15
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)

9
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

4
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.

13
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

14
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();
}
});
},

Loading…
Cancel
Save