diff options
| author | Thibault Delavallée <tde@odoo.com> | 2018-08-10 13:43:47 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-08-10 13:43:47 +0200 |
| commit | 1e7eb76c30c97390a3f71d79ce6bcfef49cceabc (patch) | |
| tree | e3f9a9b98ada989c2d82fb89fb91e5edc79c6bbb /addons/mail/static/src | |
| parent | 7499b47ffab0712e8a03655365b11450716e5717 (diff) | |
| parent | cf505c36985221819139ce30d7f03e6e51ec0298 (diff) | |
[MERGE][IMP] mail, mail_bot: improve Discuss onboarding and add your new best friend
Purpose of this merge is to improve onboarding of Discuss. This is done via
a wow effect and a bot to test the Discuss app; otherwise you have nobody to
talk to. Purpose is also to improve retention as "the best way to increase
retention is this: when the user invites someone, when this guy activates its
account, the user gets a push notification from the invited user that just
logged in; that way he will come back to Odoo and start discussing with its
colleagues.
Concerning your new best friend: it is not a dog but Odoobot.
See sub commits for more details. This merge is linked to task ID 1838588 and
closes PR #25075.
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/img/odoobot.png | bin | 0 -> 2215 bytes | |||
| -rw-r--r-- | addons/mail/static/src/img/smiley/odoobot.png | bin | 0 -> 10948 bytes | |||
| -rw-r--r-- | addons/mail/static/src/js/composers/basic_composer.js | 1 | ||||
| -rw-r--r-- | addons/mail/static/src/js/models/messages/message.js | 2 | ||||
| -rw-r--r-- | addons/mail/static/src/js/models/threads/thread.js | 1 | ||||
| -rw-r--r-- | addons/mail/static/src/js/services/mail_manager.js | 37 | ||||
| -rw-r--r-- | addons/mail/static/src/js/services/mail_notification_manager.js | 29 | ||||
| -rw-r--r-- | addons/mail/static/src/js/systray/systray_messaging_menu.js | 23 |
8 files changed, 83 insertions, 10 deletions
diff --git a/addons/mail/static/src/img/odoobot.png b/addons/mail/static/src/img/odoobot.png Binary files differnew file mode 100644 index 00000000000..b1921736d32 --- /dev/null +++ b/addons/mail/static/src/img/odoobot.png diff --git a/addons/mail/static/src/img/smiley/odoobot.png b/addons/mail/static/src/img/smiley/odoobot.png Binary files differnew file mode 100644 index 00000000000..49513b98ac1 --- /dev/null +++ b/addons/mail/static/src/img/smiley/odoobot.png diff --git a/addons/mail/static/src/js/composers/basic_composer.js b/addons/mail/static/src/js/composers/basic_composer.js index 6d402829563..bba52c3f8b2 100644 --- a/addons/mail/static/src/js/composers/basic_composer.js +++ b/addons/mail/static/src/js/composers/basic_composer.js @@ -361,6 +361,7 @@ var BasicComposer = Widget.extend({ content: this._mentionManager.generateLinks(value), attachment_ids: _.pluck(this.get('attachment_ids'), 'id'), partner_ids: _.uniq(_.pluck(this._mentionManager.getListenerSelection('@'), 'id')), + canned_response_ids: _.uniq(_.pluck(this._mentionManager.getListenerSelections()[':'], 'id')), command: commands.length > 0 ? commands[0].name : undefined, }); }, diff --git a/addons/mail/static/src/js/models/messages/message.js b/addons/mail/static/src/js/models/messages/message.js index 9bf7a79d1b9..0c6480f3264 100644 --- a/addons/mail/static/src/js/models/messages/message.js +++ b/addons/mail/static/src/js/models/messages/message.js @@ -97,7 +97,7 @@ var Message = AbstractMessage.extend(Mixins.EventDispatcherMixin, ServicesMixin */ getAvatarSource: function () { if (this._isOdoobotAuthor()) { - return '/mail/static/src/img/odoo_o.png'; + return '/mail/static/src/img/odoobot.png'; } else if (this.hasAuthor()) { return '/web/image/res.partner/' + this.getAuthorID() + '/image_small'; } else if (this.getType() === 'email') { diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js index f1831cd3aa8..5fcd0285a82 100644 --- a/addons/mail/static/src/js/models/threads/thread.js +++ b/addons/mail/static/src/js/models/threads/thread.js @@ -329,6 +329,7 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, { partner_ids: data.partner_ids, body: body, attachment_ids: data.attachment_ids, + canned_response_ids: data.canned_response_ids, }; if ('subject' in data) { messageData.subject = data.subject; diff --git a/addons/mail/static/src/js/services/mail_manager.js b/addons/mail/static/src/js/services/mail_manager.js index a5eae053a82..23d19caf31f 100644 --- a/addons/mail/static/src/js/services/mail_manager.js +++ b/addons/mail/static/src/js/services/mail_manager.js @@ -46,6 +46,7 @@ var PREVIEW_MSG_MAX_SIZE = 350; // optimal for native english speakers var MailManager = AbstractService.extend({ dependencies: ['ajax', 'bus_service', 'local_storage'], _ODOOBOT_ID: "ODOOBOT", // default authorID for transient messages + IS_STATIC_PREVIEW_ENABLED: true, /** * @override @@ -254,17 +255,23 @@ var MailManager = AbstractService.extend({ */ getSystrayPreviews: function (filter) { var self = this; + var defs = []; + var channelDef = this._getSystrayChannelPreviews(filter); var inboxDef = this._getSystrayInboxPreviews(filter); var failureDef = this._getSystrayMailFailurePreviews(filter); - - return $.when(channelDef, inboxDef, failureDef) - .then(function (previewsChannel, previewsInbox, previewsFailure) { + defs = defs.concat([channelDef, inboxDef, failureDef]); + if (this.IS_STATIC_PREVIEW_ENABLED) { + var staticDef = this._getSystrayStaticPreviews(filter); + defs.push(staticDef); + } + return $.when.apply($, defs) + .then(function (previewsChannel, previewsInbox, previewsFailure, previewsStatic) { // order: failures > inbox > channel, each group must be sorted previewsChannel = self._sortPreviews(previewsChannel); previewsInbox = self._sortPreviews(previewsInbox); previewsFailure = self._sortPreviews(previewsFailure); - return _.union(previewsFailure, previewsInbox, previewsChannel); + return _.union(previewsFailure, previewsInbox, previewsChannel, previewsStatic); }); }, /** @@ -798,6 +805,28 @@ var MailManager = AbstractService.extend({ } }, /** + * Get the previews of static systray elements, adding notification request + * + * @private + * @param {string|undefined} [filter] + */ + _getSystrayStaticPreviews: function (filter) { + var elems = []; + if ( + window.Notification && window.Notification.permission === "default" && + (filter === 'mailbox_inbox' || !filter) + ) { + elems.push({ + title: _t("Odoobot has a request for you"), + imageSRC: "/mail/static/src/img/smiley/odoobot.png", + status: 'bot', + body: _t("Enable desktop notifications to stay up to date"), + id: 'request_notification', + }); + } + return $.when(elems); + }, + /** * Initialize the canned responses from the server data * * @private diff --git a/addons/mail/static/src/js/services/mail_notification_manager.js b/addons/mail/static/src/js/services/mail_notification_manager.js index b3e5239f9ee..475cbd44f90 100644 --- a/addons/mail/static/src/js/services/mail_notification_manager.js +++ b/addons/mail/static/src/js/services/mail_notification_manager.js @@ -165,13 +165,13 @@ MailManager.include({ * Add or remove failure when receiving a failure update message * * @private - * @param {Object} data - * @param {Object[]} data.elements list of mail failure data - * @param {string} data.elements[].message_id ID of related message that + * @param {Object} datas + * @param {Object[]} datas.elements list of mail failure data + * @param {string} datas.elements[].message_id ID of related message that * has a mail failure. - * @param {Array} data.elements[].notifications list of notifications + * @param {Array} datas.elements[].notifications list of notifications * that is related to a mail failure. - * @param {string} data.elements[].notifications[0] sending state of a mail + * @param {string} datas.elements[].notifications[0] sending state of a mail * failure (e.g. 'exception'). */ _handlePartnerMailFailureNotification: function (datas) { @@ -313,6 +313,8 @@ MailManager.include({ this._handlePartnerActivityUpdateNotification(data); } else if (data.type === 'mail_failure') { this._handlePartnerMailFailureNotification(data); + } else if (data.type === 'user_connection') { + this._handlePartnerUserConnectionNotification(data); } else { this._handlePartnerChannelNotification(data); } @@ -403,7 +405,24 @@ MailManager.include({ this.do_notify(_("Unsubscribed"), message); } }, + /** + * Shows a popup to notify a user connection + * + * @private + * @param {Object} data + * @param {Object[]} data.partner_id id of the connected partner + * @param {string} data.title title to display on notification + * @param {Array} data.messages message to display on notification + */ + _handlePartnerUserConnectionNotification: function (data) { + var self=this; + var partner_id = data.partner_id; + this.call('bus_service', 'sendNotification', data.title, data.message, function(){ + self.call('mail_service', 'openDmWindow', partner_id); + }); + }, /** + * * On receiving an update on user status (e.g. becoming 'online', 'offline', * 'idle', etc.). * diff --git a/addons/mail/static/src/js/systray/systray_messaging_menu.js b/addons/mail/static/src/js/systray/systray_messaging_menu.js index 8ab95cc6fab..5552a80393e 100644 --- a/addons/mail/static/src/js/systray/systray_messaging_menu.js +++ b/addons/mail/static/src/js/systray/systray_messaging_menu.js @@ -151,6 +151,27 @@ var MessagingMenu = Widget.extend({ })); }, /** + * Display the browser notification request dialog when the user clicks on systray's corresponding notification + * + * @private + */ + _requestNotificationPermission: function () { + var self = this; + var def = window.Notification && window.Notification.requestPermission(); + if (def) { + def.then(function (value) { + if (value !== 'granted') { + self.call('bus_service', 'sendNotification', self, _t('Permission denied'), + _t('Odoo will not have the permission to send native notifications on this device.')); + } else { + self.call('bus_service', 'sendNotification', self, _t('Permission granted'), + _t('Odoo has now the permission to send you native notifications on this device.')); + } + }); + } + this.$(".o_mail_navbar_request_permission").slideUp(); + }, + /** * Get and render list of previews, based on the selected filter * * preview shows the last message of a channel with inline format. @@ -269,6 +290,8 @@ var MessagingMenu = Widget.extend({ var documentID = $target.data('document-id'); var documentModel = $target.data('document-model'); this._openDocument(documentModel, documentID); + } else if (previewID === 'request_notification') { + this._requestNotificationPermission(); } else { // preview of thread this.call('mail_service', 'openThread', previewID); |
