Commit Graph
55 Commits
Author SHA1 Message Date
e0ed7b12ca [REF] bus: adapt code after jQuery update
Part of task 1896658

Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
2019-03-06 20:07:17 +01:00
Vincent Schippefilt 646db1e1b8 [FIX] bus: longpolling clears its handlers correctly
`this._id` is overriden by the crosstab_bus, so the event handlers
weren't unbound at destroy.

Manual forwardport of odoo/odoo#31578, as we need this for another
branch, in which it makes tests fail.

closes odoo/odoo#31579

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
2019-03-05 09:00:40 +00:00
Christophe Simonis 0e7675847f [MERGE] forward port branch saas-12.1 up to 0f4abc5c22 2019-02-22 16:25:02 +01:00
Christophe Simonis 1d2b6f1bef [MERGE] forward port branch 12.0 up to 84143a34b3 2019-02-21 15:37:19 +01:00
XavierDo 07a261db71 [IMP] bus, mail, mail_bot: add im_status service
This commit is a refactoring of im_status management.
This commit also add im_status in two places, near the author in a mail thread and on each suggestion when using mentions.

A service to manage im_status will have multiple benefits here:
-centralise information, avoid to call the server multiple time for the same im_status
-update all im_status at once and keep consistency in display.

With this commit, the im_status updates are now done by rpc call.
Updates where previously made with the bus but this has some drawback,
since the bus will only give the information 50 seconds after the beginning of
the request, in the worst case, we van wait 2*50 seconds to get an update.

More than that, the im_status where only updates for pinned dm_chat. Dm chat
are synchronized cross tabs, making the use of the bus possible for this purpose.
Since we will need to display im_status not linked to dm_chat, the list to update
will be different from tab to tab making the use of bus difficult for this purpose.

Technical notes:
-im_search has been moved from bus to mail addons since it concerns mail.channel
-Update of an im_status should be reflected everywhere in the page.
Since im_status is a rendered template used in multiple widget, we should add
the correct logic to all concerened widget. The current solution is simple:
use a jquery selector to find every place where im_status is rendered.
-we add a new im_status: im_partner. This will indicate that that
the partner has no user linked to him, making it possible to avoid to ask
for status updates for this partner.
-The update will only be done when the tab is focused. (and will be done
asap once the tab get focus back)
2019-02-07 08:54:33 +00:00
Xavier Morel 6772216842 [FIX] bus, mail, web: missing super() call in destroy overrides
closes odoo/odoo#30792
2019-02-04 09:21:04 +00:00
Alexandre Kühn 64f044761a [IMP] bus, mail, mail_bot: improved native notification
With this commit, no push notification is sent to user when
to acknowledge that he just has accepted them. Also, on native
push notifications, the Odoo Bot icon now has a transparent
background.

Task-ID 1881001
2018-12-06 14:51:28 +00:00
Alexandre Kühn ae5d22fa07 [FIX] bus,mail:tests: do not use deprecated test helpers
`testUtils.addMockEnvironment` is deprecated since https://github.com/odoo/odoo/commit/abf32b8b21394491040e5c11c1fea809c1d7c62c
We should use `testUtils.mock.addMockEnvironment` instead.
2018-12-06 14:51:28 +00:00
Christophe Simonis ce4cc24621 [MERGE] forward port branch 12.0 up to 82a1e1dcc3 2018-11-29 20:06:16 +01:00
Géry Debongnie abf32b8b21 [REF] *: update js test suite to use helpers
This rev. introduces robust helpers to use in the JS tests suite to
interact with DOM and components, and starts using them (almost)
everywhere.

All the helpers are exposed though testUtils.js.

There are 2 kinds of helpers:

1. Assertions
-------------
 * assert.containsNone, containsN, containsOnce check that the DOM
   (or a specific part of the DOM) contains a `selector`. It
   generates a correct error message automatically.
    ex: assert.strictEqual(form.$('.o_form_editable'), 1, "msg");
        -> assert.containsOnce(form, '.o_form_editable');
 * assert.isVisible, isNotVisible check that the DOM has an element
   visible or not. They also check that the element is actually in
   the DOM (before most tests didn't verify this).
 * assert.hasClass, doesNotHaveClass, hasAttrVAlue, check specific
   properties of a DOM element, and also validate that it is
   applied on a single existing DOM element (before most tests
   didn't verify this).
    ex: assert.notOk(form.$('button').hasClass('btn-primary'));
       -> assert.doesNotHaveClass(form.$('button'), 'btn-primary');

2. Utilities
------------
The goal of the utilities is to centralize the definition of many
standard components and interactions, ensuring that when we
refactor the JS framework, we do not need to change all the tests.

Existing mock utilities (addMockEnvironment, intercept, path,
patchDate, unpatch and fieldsViewGet) are moved to
'testUtils.mock.*'.
Existing DOM utilities are moved to 'testUtils.dom.*'.
New dom utilities are created for opendDatePicker, click,
clickFirst and clickLast. Helper `click` verifies that there is
exactly 1 element visible in the DOM you click on, `clickFirst`
and `clickLast` verify that there are more than one element on the
DOM.
 ex: form.$('button').click();
     -> testUtils.dom.click(form.$('button'));

New Form utilities: (testUtils.form.*)
 clickEdit, clickSave, clickCreate, clickDiscard, all clicks on
 the control panel buttons of the form.
 `reload` reloads the form data.

New modal, graph, kanban and pivot utils (testUtils.pivot.*,
testUtils.kanban.*, etc.).

New fields utils: (testUtils.fields.*)
 * editInput, editSelect: allow to change the value of a field,
   using a selector to identify it. They validate that the input
   exists and trigger the change event automatically.
 * editAndTrigger: allow to modify a field and trigger specific
   events after the value change
 * many2one (testUtils.fields.many2one.*)
   clickOpenDropdown, clickHighlightedItem, clickItem,
   searchAndClickItem: use a field name instead of a selector and
   do all the complex mechanism to open, filter and highlight
   many2one fields.

Joint work with aab, dam, ged, mge, svs and vsc.
2018-11-19 11:24:28 +00:00
Prakash PrajapatiandMohammed Shekha 8929960492 [FIX] im_livechat, bus: open livechat from customer url.
Before this commit, there was no livechat menu when accessing it from
the customer URL, e.g. `http://mycompany.odoo.com/im_livechat/support/1`)

This is due to missing JS modules, such as the root widget.

Also, the crosstab polling directly requires the session module,
because the public root widget does not return the session module
from the OdooEvent `get_session`.

Task-ID 1885445

Co-authored-by: Mohammed Shekha <msh@openerp.com>
2018-10-19 09:05:17 +00:00
Alexandre Kühn b4f132ca21 [FIX] bus: elect master tab when master tab is unloaded
Before this commit, chat windows could not be sync'ed
between browser tabs for about 10 to 20 seconds.

This issue is caused by the implementation of the
crosstab longpolling, which uses a master-slave
architecture with a single tab being the master tab.
The master tab is responsible for performing the
longpolling RPC, so that it keeps a single HTTP request
for all Odoo tabs. Other tabs are synchronized through
the local storage.

When the master tab was closed, a new master tab election
must occur. However, this process was taking up to 20 seconds,
due to the tab waiting for their next tick on the local
storage to initiate a new election. The tick for a slave
tab is 10 seconds, and it may jumps a tick in case the master
tab is closed exactly before the tick, hence extending the
duration to 20 seconds.

This commit fixes the problem by ensuring that the tab
election for the longpolling is done right after the master
tab is closed. As a result, a new master tab should follow
right away.

Steps to reproduce:

1. open two tabs.
2. open a chat window in one tab: it opens in both tabs.
3. fold/unfold chat window in one tab: both tab should sync.
4. refresh both tabs.
5. fold/unfold chat window in one tab: both tab should not sync.
6. after 10 or 20 seconds, both tabs should again sync.

Task-ID 1911437

closes odoo/odoo#28925
2018-11-21 16:43:27 +00:00
Alexandre Kühn 22f037e3af [FIX] bus: use || instead of |
Revision on https://github.com/odoo/odoo/commit/221f469045e32b3bd8bb975dad4467424602cefa
2018-10-02 19:05:01 +02:00
Alexandre Kühn 221f469045 [FIX] bus: do not receive all longpolling notifs after disconnect
Revision on bus refactoring: https://github.com/odoo/odoo/commit/6448420c5dd160470e465dee7729d19d8d5e7bab

Before this commit, when a user was disconnected for a very long
time, he would receive lots of chat notifications on his next login.

Here is an example of weird behaviour with this issue:

    - User folds and unfolds a chat window 50 times
    - User disconnects for more than 50 seconds
    - User reconnects
    ==> the chat window rapidly folds and unfolds itself 50 times!

This issue comes from the fact that after 50 seconds without any
longpolling, the web client ignores the last tracked notification
and sents the ID `-1` to the server.

The web client always provides a notification ID to the server
on a `longpolling/poll`. Usually, the server returns all
notifications of the user with an ID greater than the provided ID.
There is an exception with ID `0`, in which all notifications since
the last connection of the user are returned.

The cause of the issue is a mismatch of the special notification
ID between the server and the web client. For the web client, the
ID `-1` is used for not tracking any notification, whereas the
server uses the ID `0` for this case. As a result, when the server
receives the value `-1`, it returns all notifications having an ID
greater than `-1`. In other words, it returns all notifications
related to this user, even the ones received long time ago!

This commit fixes the issue by enforcing the special notification ID
`0` on both the webclient and server.

Note that this logic is similar to 11.0:

   - The webclient uses the ID `-1` most of the time to define 'untracked':
   https://github.com/odoo/odoo/blob/11.0/addons/bus/static/src/js/bus.js#L154

   - However, it passes the ID `0` to the server:
   https://github.com/odoo/odoo/blob/11.0/addons/bus/static/src/js/bus.js#L193
2018-10-02 17:58:47 +02:00
Christophe Matthieu 4ad896bd3d [FIX] bus: Displays messages when loading the page with multiple tabs
If we use the cross tab, and the session has more than 50 seconds (or
does not exist), a remove is done in the init. The change trigger in
local storage causes the value of _lastNotificationID to become null.
This causes a loading error in the long poll.
2018-09-10 16:46:29 +02:00
Alexandre Kühn f2302dfb27 [REF][FIX] mail, im_livechat: various improvements (JS)
This commit makes a lot of small improvements of the JS of mail and
related modules.

	A. Mail Manager
	---------------

		im_support:

		- [REF] Slightly more robust way to determine a support
		        message, so that it more reliably falls back on
		        default kind of message (i.e. support channel UUID
		        should be clearly set).

		mail:

		- [REF] Improved method names for readability purposes.
		        Some examples:

		        - `fetchFromServer` becomes `fetchMailStateFromServer`
		        - `_initialize{*}` becomes `_update{*}FromServer`
		        - `_isModerator` becomes `_isMyselfModerator`

		- [REF] Use 'template' pattern design to make Include on
				Mail Manager much more robust. In particular,
				the flow is always as follow:

					1. Initialize internal state.
					2. Listen on buses.
					3. Fetch mail data from server.

		- [REF] Improved workflow for thread window workflow
		        (Shorter & more readable).

	B. Mail Tests
	-------------

		- [REF] Thread Window Tests crashes with clean message when
		        there are some thread windows open before running the
		        tests.

	C. (Model) Message
	------------------

		- [REF] Improved method names for readability purposes
				(e.g. `isAuthor` becomes `isMyselfAuthor`).

	D. (Model) Thread
	-----------------

		- [REF] Improved `init` parameters on each kind of thread.
		- [REF] 'Thread With Cache' has been renamed to 'Searchable
		        Thread': it embraces all kinds of threads that can
		        be used with the search view.
		- [REF] 'DM' has been renamed to 'DM Chat' (for clarity).
		- [IMP] New Livechat model in the backend.
		- [REF] No more direct instances of the Channel class: public
		        and private channels are now 'Multi-User' channels,
		        while DM Chat and Livechat are 'Two-User' channels:

		        This change has been made so that instances of classes
		        always have direct classes as "leaf" in the Class
		        modeling. It eases making changes to a certain model
		        without being too constrained by another model.

		- [REF] As a consequence of above changed, the method `isChat`
		        has been renamed to `isTwoUserThread`.

		        This is to avoid confusion with the terminology
		        'chat', which is more like a shortcut for 'quick real-
		        time conversation'. In other words, the property of
		        'chat' depends of the way to interact on a thread, not
		        of the intrinsic type of the thread.

		        Still, some parts have kept the terminology 'chat',
		        such as in the systray messagin menu.

		- [IMP] Added `message_added` and `message_posted` hooks,
		        which may be useful to easily hook on those events.

	E. Thread Widget
	----------------

		- [REF] Now uses a `mail.model.AbstractThread` for the
		        rendering of a thread, instead of a list of
		        `{mail.model.AbstractMessage}`.
		- [FIX] Stick thread scroll height to bottom on new rendering,
		        if it was previously at the bottom of the thread.
		- [REF] Option ORDER has its meaning changed: it now refers
		        to the chronological order of messages in the thread,
		        in which DESC means 'from top to bottom', while ASC
		        means 'from bottom to top'.
		- [REF] Improved doc on templates, in particular with the
	            option `ORDER`.

	F. Thread Window
	----------------

		- [REF] Moved more logic to thread windows, which were
		        previously in Mail Window Manager.
		- [REF] Now hides the thread widget attribute. So instead of
		        `threadWindow.threadWidget.isAtBottom()`, it uses
		        `threadWindow.isAtBottom()`.
		- [FIX] New received messages when not having focus on Odoo
		        tab should always make the corresponding thread
		        windows "passive" (i.e. windows that keep threads
		        unread until click on them).
		- [FIX] Blank thread window (i.e. 'New message' TW) correctly
		        opens Discuss with 'Inbox' when clicking on 'Expand'
		        Button in the title
		- [FIX] Do not display the composer for channels with property
		        'mass-mailing' set in thread windows.

	G. (Website) Livechat
	---------------------

		- [REF] Some `trigger` have been turned into `trigger_up`.
		- [REF] Some logic has been moved to models (e.g.
		        `{im_livechat.model.WebsiteLivechat}`), from
		        `{im_livechat.im_livechat.LivechatButton}`.
		- [FIX] New messages should be received in real-time. The
		        longpolling was broken with a recent refactoring on
		        bus service (6448420c5d).
2018-08-13 14:17:27 +02:00
XavierDo cf505c3698 [ADD] mail_bot, im_livechat_mail_bot: add Odoobot, your new best friend
Purpose of this commit is to improve onboarding with a wow effect and a bot
to test the Discuss app. Otherwise new users have nobody to talk to. Retention
will be improved by both increasing interactions and onboarding of Discuss
features.

This commit adds a simple bot in discuss. It answers some questions, helps
users getting their hand on discuss and eases the onboarding.

In this version, the flow is quite simple, and only im_livechat adds some
logic in order to show canned response. The logic is contained in new
modules: mail_bot and im_livechat_mail_bot in order to keep everything
well separated. It also allows users to remove the mailbot if they do not
want to keep this functionality.

Odoobot will only answer if he is in the onboarding conversation (alone
with a user in a channel of type chat) or if a user pings odoobot.

Odoobot logic applies to both standard chatter / channel messages and
also transient messages (like help commands).

Specifications

 * 2 minutes after first sign in, users will receive a direct chat from
   Odoobot;
 * make Odoobot an archived partner;
 * scenario

  * Odoobot: "Hello, I'm here to help you discover chat features. Try
    answering me with an emoji :)";
  * User:  Send emoji
  * Odoobot: "Great! :) Did you notice that you can also send attachments,
    like a picture of your cute dog? Try it!"
  * Odoobot: "Not a cute dog, but you get it :) To access special features,
    start your sentence with "/" (I.E. /help)""
  * User: /help
  * Auto message then Odoobot: "Wow you're a natural! As a channel usually
    contain a lot of users, you can grab the attention with a ping. Try to
    ping me with @Odoobot!"
  * User: @Odoobot lorem ipsum

  * if Livechat installed

   * add 2 demo canned response so it does not look weird (like "Hello, how
    may I help you?" and "Have a nice day!")
   * Odoobot: "Perfect! <br> Try to type ":" to use canned responses."
   * User tries canned
   * Odoobot: "Good, you can customize your canned responses in the live chat
    application. <br><br> + réponse suivante"

 * Odoobot: "There's 3 different ways in Odoo to interact with your
   colleagues:  via this chat window, [img of chat window] via the Discuss
   application [img of Discuss app + icon on it] or via the chatter [img of
   the chatter]. Aaaaand that's it! Enjoy discovering Odoo! :)"
 * random answers to ping/bad answer

  * "Mmmmh I'm not sure what you mean.. Can you try again?"
  * "I'm afraid I don't understand. Sorry!"

 * when someone pings @OdooBot with no reason: Odoobot: Yaaaay that's me!
   [party emoji]
 * fun stuff to add for some answer

  * User: i love you / love
  * Odoobot: Aaaaaw that's really cute but, you know, bots don't work
    that way. You're too human for me! Let's keep it professional <3
  * User: Fuck
  * Odoobot: That's not a really nice thing to say, you know? I'm a bot but I
    have feelings, ok?! </3

This commit is linked to task ID 1838588 and PR #25075.
2018-08-10 13:33:28 +02:00
XavierDo c446fb2001 [IMP] auth_signup, mail: notify inviter user when invited user connects
Purpose of this commit is to improve the onboarding and the first steps of
Odoo notably when using Discuss and inviting first people to join Odoo.

When a new user connects the user who invited him will be notified with
a desktop notification inviting him to have a chat in Discuss and talk
together.

This commit is linked to task ID 1838588 and PR #25075.
2018-08-10 13:33:28 +02:00
Christophe Matthieu 6448420c5d [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.
2018-08-09 02:31:59 +02:00
Christophe Matthieu a8e4e625f4 [IMP] web: remove useless service name
We use the registry keys as name for the services.
2018-08-09 02:31:59 +02:00
Christophe Matthieu 693c771111 [IMP] web: abord the poll when destroy to avoid useless call
If the service bus are called and destroyed the rpc can be returned after, to
avoid a useless call to the database and unexpected behavior, we abort the
connection.
2018-08-09 02:31:59 +02:00
Alexandre Kühn cd34f6de72 [REF] mail: JS mail refactoring
----------------------
 Summary
----------------------

The purpose of this commit is to improve the JS code of the `mail` module.
It applies the new coding guidelines and makes some changes on the design
of some modules, such as the old ChatManager module.

Here is a short summary of the changes that have been made:

  1. New coding guidelines
    - snake_case to camelCase
    - prefix private attributes and methods with '_'
    - jsdoc on most methods
    - one class per module
  2. Rename/Merge some classes
    - 'chat manager' becomes 'mail manager' (internal) and 'mail service' (external)
    - 'chat window manager' is now included in mail manager
    - 'thread' widget now named 'thread widget'
  3. New model abstraction for mail objects:
    - modules 'mail.model.*'
    - modeling:

                    0..1    0..1        *     *
      ThreadWindow  <------>  Thread <-------> Message
                              /    \
                             /      \
              Thread With Cache     Document Thread
               /      |       \
              /       |        \
        Mailbox    Channel    Support Channel
                      |
                      |
                      DM

    - Thread: the superclass of threads.
    - ThreadWindow: the window component of a thread.
    - Message: mail objects representing messages.
    - Thread With Cache: threads that can be used with search view (Discuss app compatible).
    - Document Thread: represents the thread part of a chatter.
    - Mailbox: represents what was previously called 'static' channel, e.g. 'Inbox'.
    - Channel: mail objects representing channels, including livechat.
    - DM: special kind of Channel for 1:1 communication in the backend.
    - Support Channel: special channel for im_support module.

  This new modeling approach let us easily add features on all threads, such as the
  possibility to put any thread in a small window.

----------------------
 Known issues
----------------------

 [Already Present in Master]

    1. When the Discuss app is in the background with 'Inbox' as the selected
       Thread, when clicking on a document thread preview in the messaging menu
       of the systray, the rainbow man appears.

    2. When a document with the chatter is in the background, when receiving an
       inbox notification from this document thread, the document thread is
       automatically marked as read, which removes the notification right away.

    3. Sometimes, opening a DM window from the "blank" thread window does not work.

    4. Reply-to feature on Inbox is not working: no message is sent in the document
       thread.
    5. On the first login of admin user with demo data, the inbox counter is wrong
       (it displays 6, instead of 3).

       Explanation after investigation:

        > On page load, it fetches the correct number of Inbox messages (3),
          but the server notifies of 3 needaction messages right away,
          so it wrongly assumes these are new needaction messages.
        > Not possible for web client to detect that these messages should not
          increment the Inbox counter while keeping same API.

    6. Notifications for new document thread messages only work when the user sets
       'handle with Odoo' for the Notification Management in the preferences.

        > due to notifications on the longpoll bus for document thread
          messages that come from needaction notifications.
        > requires server-side changes to send notification on the longpoll
          bus to mentionned user.

  [New]

    7. When receiving a message on a unjoined channel, thread window flickers
       ('open' > 'close' > 'open')

        Explanation after investigation:

          > JS logic:

            a) On auto-join, ask server to join the channel and get channel infos.
            b) The info tells the channel is not detached, but JS code makes decision
               to detach it, and tells server the channel is now detached.
            c) From (a), server notifies on longpoll bus the state of channel, which is
               not detached. The web client thinks that the window state of the channel
               has been changed somewhere else, and the channel is now closed.
            d) From (b), server notifies on longpoll bus the state of channel, which is
               detached. The web client opens the thread window of this channel.

          > The flicker didn't occur before refactoring because the web client was only
            updating the model of channel when it receives the longpoll notification.
          > Server behaviour on 1st longpoll notification is necessary for cross-tab
            synchronization for channel window state.
          > New design implies that model and view should be synchronized, hence the
            issue now.
          > Solution: remove server-side thread window synchronization and replace with
            client-side synchronization.

----------------------
 Hacks
----------------------

The module `im_livechat` now uses mail objects that are compatible with Message
and Window objects:

      Modeling for messages:

                             AbstractMessage
                              /           \
                             /             \
                    LivechatMessage      Message

      - AbstractMessage: message compatible with the thread widget.
      - LivechatMessage: message used by im_livechat.
      - Message: message used with the mail manager.

      Modeling for thread windows:

                          AbstractThreadWindow
                              /           \
                             /             \
                    LivechatWindow    ThreadWindow

      - AbstractThreadWindow: behaviour share between all types of thread windows.
      - LivechatWindow: window used by im_livechat.
      - ThreadWindow: window used with mail_manager.

The reason for these hacks are twofold:

  1. Use the thread widget in the frontend and livechat external lib bundles.
  2. Do not have a dependency with the mail manager in the frontend and external
     lib bundles.
2018-07-02 15:06:54 +02:00
Aaron Bohy 239d460ae5 [FIX] bus: correctly forwardport 10161f9d61 2018-06-21 13:57:57 +02:00
Christophe Simonis e008ef302a [MERGE] forward port branch saas-11.3 up to 53300648ed 2018-05-30 12:18:52 +02:00
Aaron Bohy 10161f9d61 [FIX] bus: co-existing instances of bus.bus
Before this rev., it was not possible to have co-existing instances
of bus.bus, each one polling its own server, for several reasons.

First, the Bus class couldn't be overridden or parameterized to
specify which server and route to call to perform the longpolling.

Second, when several instances of bus.bus coexisted, their use of
the localStorage (for the CrosstabBus) conflicted, and as a result,
only one of them actually polled.

This rev. makes it possible, and it was necessary for the new addon
'im_support'.

Task 26762
2018-05-28 07:30:12 +02:00
Christophe Matthieu 1f5d65e74a [IMP] bus: properly restart longpoll when necessary
Whenever we add or delete a channel in the bus/longpolling system, we
want the long poll to restart immediately, to be able to receive the
correct messages.

Before this commit, we had to wait for the longpoll timeout to finish
before receiving the correct messages.
2018-04-18 11:43:07 +02:00
Christophe Simonis 9a84ba5533 [MERGE] forward port branch saas-11.1 up to e750bb6e11 2018-02-22 10:39:15 +01:00
David Arnold 59202d5e8c [FIX] bus: set timeout to gracefully recover
Before this in the event of a network failure that lasts longer than the respective return cycle of the deferred call,
this deferred will keep in purgatory forever (until reload of the client).
This is not problematic in the normal use case, but working with offline modules, such as POS or similar making use of the
long polling concept for synchronization purposes, this generates toxic behavior.
Simply: The client state never recovers on it's own from the network failure

(PR #21653)
2018-02-19 09:59:01 +01:00
Alexandre Kühn 7339ae978f [FIX] mail,web,*: Cleaning some JS code
- Whitespace trailing
- Split long lines
- Replace some 'self' to 'this'
- Improved some JS docs
- DRY in tests using services
2018-02-12 16:09:38 +01:00
Alexandre Kühn 066eaaeafa [FIX] mail,web: JS mail and services tracebacks
Fix over this commit: https://github.com/odoo/odoo/commit/02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498

In mobile, when discuss is installed, there is a traceback.

This is a consequence on an issue with JS services, where some of them
are not registered in the service provider.
For instance, the webclient (the service provider) was instantiated before
chat_manager (a service), so it was not aware of this service.

To solve this issue, service providers now listen on newly registered services.

Also improving deployment of JS services by not relying on topological sort.
2018-02-12 16:09:38 +01:00
Aaron Bohy 02ec09cb1c [REF][IMP] *: mail js refactoring
This commit improves the JS code of the mail module,
which comes maily from the new coding guidelines
and the addition of "JS services".

JS services are important objects that do not fit
well in the component tree, such as chat_manager
or ajax.

The benefits of JS services are improved readability
of the code, reduced coupling, and more testable
modules. In particular, discuss was hard to

Summary of the changes:

- ClientAction has been renamed into Discuss
- Clear instantiation of chatManager
- New coding guidelines in most mail modules
- JS Services can interact with each other
- Chat Manager and Window Manager are services
- Window Manager renamed to Chat Window Manager
- bus.bus is now encapsulated in Bus Service (a service)
- The test infrastructure has been tweaked with JS Services
- Chat Mixin has been removed

A future improvement would be to translate some 'trigger' into 'trigger_up'.
2018-02-01 14:51:58 +01:00
Xavier Morel f1a85ba70a [FIX] *: fix a bunch of incorrectly documented docstring
Fix a bunch of ill-documented/incomplete/incorrect method docs
Without this, the automatic doc generation does not work.
2017-09-18 11:54:39 +02:00
Christophe Simonis 63860373ac [MERGE] forward port branch saas-11 up to c19f546 2016-11-08 14:43:28 +01:00
Christophe Matthieu a8e79e960a [FIX] bus,im_odoo_support, web*: fix various memory leaks
* Tip are never destroyed when change view mode
* unbind methods
* mail: memory leak with unbind methods
* web: memory leak because 'ui-autocomplete' is never destroyed
* web_editor: memory leak for wrong unbind on destroy
* web: memory leak: must remove fileupload handler
* bus: memory leak: correctly debind handlers on window in bus.Bus
* remove handlers on switch buttons and views $buttons
* remove handlers on breadcrumbs
* web: memory leak: correctly debind handlers
* im_odoo_support: memory leak: remove fileupload handler odoo_support

Note: part of this commit was actually authored by aab
2016-11-04 14:07:35 +01:00
Adrien Dieudonne a9b0561106 [FIX] *: use new JS module to read from/write in localStorage
to prevent errors when the localStorage capacity is 0, which is the case e.g.
on private browsing with Safari.
2016-06-16 13:48:18 +02:00
Géry Debongnie 8af3841cb2 [FIX] mail: prevent mail to rejoin a channel that we just left
sometimes, the web client receives unsubscribe notification and an extra
notification on that channel.  This is then followed by an attempt to
rejoin the channel that we just left.  This commit prevents that
situation to occur.

For that, it needs to know the notifications received by the bus in one
batch, not one at a time.
2016-01-20 14:41:34 +01:00
Géry Debongnie cc8c355ecb [IMP] mail, bus: display native notifications if user away
This commit introduces native notifications (if available) to the
discuss application.

Those notifications will only appear if the user grants the permission
for that.  A notification bar will appear in the discuss application if
necessary to prompt the user.

Also, it always is the master bus that will be the one sending the
notification.

For this change, it was necessary to be able to detect if the user has
the focus on some other odoo tabs.  For this reason, the bus was
extended.
2015-12-29 14:47:40 +01:00
Aaron Bohy f6c20fa4b3 [FIX] bus,mail: user presence
Commit 5d1b323. re-enabled the user presence updates and notifications.
Unfortunately, it showed poor performance due to the high frequency of bus
notifications triggered on our instance (~600k users).

In this rev., we don't trigger notifications on presence changes anymore, but
we rather send the presence of users we have a DM open with, at the end of each
poll period. For performance reasons, we ensure not to do that more than once
every 30 seconds.

We also refined the detection of the 'away' status client side. 'Last presence'
timestamps are stored in the local storage, and the current inactivity period
is sent at each poll. Those presence timestamps now rely on browser activity
detection (click, keypress... events) rather than on the focus on Odoo tabs.

Finally, we removed the no more necessary cron introduced in 5d1b323.
2015-12-24 12:59:46 +01:00
Aaron Bohy 5d1b3232fc [FIX] bus,mail: user presence
Before this rev., no notification was sent on the bus when the user presence
changed. Thus, the bullets displayed in Discuss were never updated and stayed
as they were on the initialilization of the chat_manager (on webclient launch).

This rev. makes the bus.presence notifications work, and handles them client
side.

Moreover, the disconnections detection is now performed at each poll (with a
maximum of 1 per minute), instead of randomly (1/100 chance) at each poll, as
it scales better than the former solution. We also added a cron that performs
this check every 5 minutes. It is needed to detect that the last connected user
just disconnected (useful for visitors in the website, trying to talk with a
livechat operator).

Also, the 'away' status is now handled client side, as it makes more sense
that way (being away at each poll, e.g. every 50seconds, during 10 minutes
doesn't mean that we didn't come back between two polls).

Finaly, in bus.js, CrossTabBus, we moved the code writing in/reading the local
storage after the tab registration as this code depends on the fact that the
tab is the master tab or not (and this is known only once the tab is
registered).

This rev. was necessary in stable because the livechat uses the user status to
detect if there is an operator available, and this was often inaccurate.
Moreover, it improves the user experience of the chat in the backend.
2015-12-16 15:48:43 +01:00
Aaron Bohy 51461d591d [FIX] bus,mail: edit title and play sound on new message
Concerns only chat messages.
2015-12-08 16:30:37 +01:00
Géry Debongnie ce65e897f9 [FIX] bus: prevent crosstab bus from longpolling on init
only need to longpoll after start_polling...
2015-12-07 16:32:28 +01:00
Géry Debongnie 1378dc130c [FIX] bus: prevent duplicate messages on browser refresh
On browser refresh, the bus sends the last notifications for the last
50secs.  This is really annoying to deal with, especially in the chat
applicatiion.  This commits ensure that duplicate notifications are
ignored.  This is done by saving the id of the last notif in the local
storage.

Note: it is also necessary to clear the last message id in the local
storage to prevent problems when a developer resets his db, and will not
receive any notifications.
2015-11-16 09:51:08 +01:00
Aaron Bohy 2c60b1bc2d [FIX] bus: correctly detect master tabs
The problem was that the tab_manager compared its last heartbeat value with an
old value stored in the local storage (when being elicted master, the tab
writes a new heartbeat in the locat storage).

This solution makes sure to compare the actual value in the local storage with
the heartbeat value stored in the tab_manager.
2015-11-16 09:51:08 +01:00
Géry Debongnie 9f6f5fe512 [FIX] bus: allow bus to self-correct
The bus is somewhat tricky. (at least, the crosstab version).  It needs
to elect a leader, and to communicate with the server through it.

However, several tabs have a different event loop, so, we need to be
careful to avoid race conditions.  The current version was not
race-condition-proof, and this commits improves on this.

The idea is to allow the bus to detect if some other tab is also
considering himself master.  In that case, it is allowed to unelect
himself.

This should allow the bus to self correct those situations in a short
time.
2015-11-09 16:24:59 +01:00
Géry Debongnie 38581f6723 [FIX] bus: share longpolling among tabs
The bus used to do a long poll as soon as it is started.  This is fine
when the user has a single tab, but not so fine when 5 or 6 tabs are
open.  This commit introduce the concept of tab manager, a way to decide
among all tabs who is the leader.  The leader will then initiate the
long poll, and share the notifications via the local storage.
2015-10-30 15:39:42 +01:00
Géry Debongnie 6ae0309b99 [FIX] bus,mail,livechat: fix problem with multiple long polls
The bus was allowed to restart polling, client side, to allow the user
to directly receive messages in new channels.  This was only acceptable
as a temporary fix, the correct way to do this is to actually notify the
bus server side. This is even more urgent since the client was allowed
to keep multiple longpolls simultaneously, which degraded the experience
in some cases.
2015-10-16 15:52:01 +02:00
Géry Debongnie aa23a5a41d [IMP] bus: allow bus to restart polling on demand
The problem was that the bus didn't listen to new channels when they were
registered until the end of the current longpoll. This allows mail to manually
restart the polling.
2015-10-01 14:00:18 +02:00
Jérome Maes 4af9631072 [MOV] mail, im_chat : move files and code from im_chat to mail and bus
- im_chat.session will be replaced by mail.channel
- im_chat.shortode is renamed into mail.shortcode
- im_chat.presence is moved to bus module
- js and controller code is moved from im_chat to mail module

This commit only move files, and modify manifests, bundles, ... The code will be adapt in the next commits.
2015-09-01 20:16:08 +02:00
Géry Debongnie 4fdf74fe21 [IMP] web+addons: improvement to module system
The module system needs to know the dependencies of a given module
before executing the function.  This is why the dependencies were
defined once in an array, and then were described one more times in the
call to require.

But a trick can simplify this: the boot function can parse the string
representation of the module and extract the calls to require from it.
It is more work for the processor, but it leads to simpler module
definitions.
2015-03-18 09:23:37 +01:00
Géry Debongnie 858e46e977 [REF] update various small addons to the new module system 2015-03-18 09:01:52 +01:00