diff options
| author | Christophe Matthieu <chm@odoo.com> | 2018-08-08 18:54:43 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2018-08-09 02:31:59 +0200 |
| commit | 6448420c5dd160470e465dee7729d19d8d5e7bab (patch) | |
| tree | c2696ff4e1f7abd90af8570804bc86a524790860 /addons/mail/static/src/js/services/mail_document_thread_manager.js | |
| parent | 791c70b329bf513a4c9359d38603b10dc6066829 (diff) | |
[IMP] bus: re-factoring of bus.bus (Longpolling and CrossTab)
The purpose of this change is to make the code clearer and testable.
In this change, the 'tab_manager' static object was merged with the bus
cross tab.
Cleaning was done to clearly define private and public functions as well
as handlers. The methods are documented and the constants are now defined
on the class. The bus use the service behavior with 'trigger_up'.
'bus.CrossTab' who extend 'bus.Longpolling' are instantiated by the
bus service.
The class is always instantiated with a parent, or root in the case of the website
(im_livechat), to use the ajax and localstorage services. So the behavior, perhaps
logger or redefined by the parents.
Diffstat (limited to 'addons/mail/static/src/js/services/mail_document_thread_manager.js')
| -rw-r--r-- | addons/mail/static/src/js/services/mail_document_thread_manager.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/addons/mail/static/src/js/services/mail_document_thread_manager.js b/addons/mail/static/src/js/services/mail_document_thread_manager.js index b1417d62fc6..6e4c8fb591c 100644 --- a/addons/mail/static/src/js/services/mail_document_thread_manager.js +++ b/addons/mail/static/src/js/services/mail_document_thread_manager.js @@ -25,9 +25,9 @@ MailManager.include({ // retrieve the open DocumentThreads from the localStorage var state = this.call('local_storage', 'getItem', this.DOCUMENT_THREAD_STATE_KEY); if (!state) { - this.call('local_storage', 'setItem', this.DOCUMENT_THREAD_STATE_KEY, '{}'); + this.call('local_storage', 'setItem', this.DOCUMENT_THREAD_STATE_KEY, {}); } else { - this.isReady().then(this._updateDocumentThreadWindows.bind(this, JSON.parse(state))); + this.isReady().then(this._updateDocumentThreadWindows.bind(this, state)); } // listen to localStorage changes to synchronize DocumentThread's // windows between tabs @@ -67,7 +67,7 @@ MailManager.include({ data.author_id[0] === session.partner_id ) { var key = this.DOCUMENT_THREAD_MESSAGE_KEY; - this.call('local_storage', 'setItem', key, JSON.stringify(data)); + this.call('local_storage', 'setItem', key, data); } return this._super.apply(this, arguments); }, @@ -149,15 +149,12 @@ MailManager.include({ * @param {string} state.windowState ('closed', 'folded' or 'open') */ updateDocumentThreadState: function (threadID, state) { - var item = this.call('local_storage', 'getItem', this.DOCUMENT_THREAD_STATE_KEY); - var states = JSON.parse(item); + var states = this.call('local_storage', 'getItem', this.DOCUMENT_THREAD_STATE_KEY); states = _.omit(states, function (state) { return state.windowState === 'closed'; }); states[threadID] = state; - this.call('local_storage', 'setItem', - this.DOCUMENT_THREAD_STATE_KEY, - JSON.stringify(states)); + this.call('local_storage', 'setItem', this.DOCUMENT_THREAD_STATE_KEY, states); }, //-------------------------------------------------------------------------- @@ -223,11 +220,11 @@ MailManager.include({ _onStorage: function (ev) { if (ev.key === this.DOCUMENT_THREAD_STATE_KEY) { var state = this.call('local_storage', 'getItem', this.DOCUMENT_THREAD_STATE_KEY); - this._updateDocumentThreadWindows(JSON.parse(state)); + this._updateDocumentThreadWindows(state); } else if (ev.key === this.DOCUMENT_THREAD_MESSAGE_KEY) { var message = this.call('local_storage', 'getItem', this.DOCUMENT_THREAD_MESSAGE_KEY); if (message) { - this.addMessage(JSON.parse(message)); + this.addMessage(message); } } }, |
