summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-12-05 14:35:19 +0000
committerAlexandre Kühn <aku@odoo.com>2018-12-06 14:51:28 +0000
commitf372ac541f6a90a741253acdfd35cf5f2cc97696 (patch)
tree7a92955ca50427020c6e7d1625d860595437952c /addons/mail/static/src
parentef1c342b7c827a4f9822d499beb31f439e967017 (diff)
[IMP] mail: rename DM conversation
This commit adds the possibility to customize the name of a DM conversation. To do so, click on the gear icon when hovering on a DM in the discuss sidebar. This feature intentionally removes the access to the settings of a DM, because the settings view only makes sense for non-DM conversations. Task-ID 1881001
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/discuss.js74
-rw-r--r--addons/mail/static/src/js/models/threads/dm_chat.js4
-rw-r--r--addons/mail/static/src/js/models/threads/document_thread.js11
-rw-r--r--addons/mail/static/src/js/models/threads/thread.js8
-rw-r--r--addons/mail/static/src/xml/discuss.xml5
5 files changed, 89 insertions, 13 deletions
diff --git a/addons/mail/static/src/js/discuss.js b/addons/mail/static/src/js/discuss.js
index a3dd72b4923..5a5bc9e106e 100644
--- a/addons/mail/static/src/js/discuss.js
+++ b/addons/mail/static/src/js/discuss.js
@@ -112,6 +112,72 @@ var PartnerInviteDialog = Dialog.extend({
});
/**
+ * Widget : Rename Conversation Dialog
+ */
+var RenameConversationDialog = Dialog.extend({
+ dialog_title: _t("Rename conversation"),
+ template: 'mail.RenameConversationDialog',
+ /**
+ * @override
+ * @param {integer|string} channelID id of the channel
+ * @param {function} callback to call when successfully renaming
+ * conversation.
+ */
+ init: function (parent, channelID, callback) {
+ this._channelID = channelID;
+ this._callback = callback;
+
+ this._super(parent, {
+ title: 'Rename conversation',
+ size: 'medium',
+ buttons: [{
+ text: _t("Rename"),
+ close: true,
+ classes: 'btn-primary o_mail_conversation_rename',
+ click: this._rename.bind(this),
+ }, {
+ text: _t("Discard"),
+ close: true,
+ }],
+ });
+ },
+ /**
+ * @override
+ * @returns {$.Promise}
+ */
+ start: function () {
+ var channel = this.call('mail_service', 'getChannel', this._channelID);
+ this.$('input').val(channel.getName());
+ return this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @returns {$.Promise}
+ */
+ _rename: function () {
+ var self = this;
+ var name = this.$('input').val();
+ return this._rpc({
+ model: 'mail.channel',
+ method: 'channel_set_custom_name',
+ args: [this._channelID],
+ kwargs: {
+ name: name,
+ }
+ }).then(function (updatedName) {
+ var channel = self.call('mail_service', 'getThread', self._channelID);
+ channel.setName(updatedName);
+ self._callback();
+ });
+ },
+});
+
+/**
* Widget : Moderator reject message dialog
*
* Popup containing message title and reject message body.
@@ -1223,7 +1289,13 @@ var Discuss = AbstractAction.extend(ControlPanelMixin, {
* @param {MouseEvent} ev
*/
_onChannelSettingsClicked: function (ev) {
- var threadID = $(ev.target).data('thread-id');
+ ev.stopPropagation();
+ var threadID = $(ev.currentTarget).data('thread-id');
+ var thread = this.call('mail_service', 'getThread', threadID);
+ if (thread.getType() === 'dm_chat') {
+ new RenameConversationDialog(this, threadID, this._updateThreads.bind(this)).open();
+ return;
+ }
this.do_action({
type: 'ir.actions.act_window',
res_model: 'mail.channel',
diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js
index 767a6e32edd..5e69dbeff8c 100644
--- a/addons/mail/static/src/js/models/threads/dm_chat.js
+++ b/addons/mail/static/src/js/models/threads/dm_chat.js
@@ -12,6 +12,8 @@ var DMChat = TwoUserChannel.extend({
* @override
* @param {Object} params
* @param {Object} params.data
+ * @param {string|undefined} [params.custom_channel_name] if set, use this
+ * custom name for this DM
* @param {Object[]} params.data.direct_partner
* @param {integer} params.data.direct_partner[0].id
* @param {string} params.data.direct_partner[0].im_status
@@ -23,7 +25,7 @@ var DMChat = TwoUserChannel.extend({
var data = params.data;
this._directPartnerID = data.direct_partner[0].id;
- this._name = data.direct_partner[0].name;
+ this._name = data.custom_channel_name || data.direct_partner[0].name;
this._status = data.direct_partner[0].im_status;
this._type = 'dm_chat';
},
diff --git a/addons/mail/static/src/js/models/threads/document_thread.js b/addons/mail/static/src/js/models/threads/document_thread.js
index f90da991960..d902d69765c 100644
--- a/addons/mail/static/src/js/models/threads/document_thread.js
+++ b/addons/mail/static/src/js/models/threads/document_thread.js
@@ -168,17 +168,6 @@ var DocumentThread = Thread.extend({
this._mustFetchMessageIDs = false;
this._messageIDs = messageIDs;
},
- /**
- * Set the name of this document thread
- *
- * This is useful if the name of the document related to the document thread
- * has changed
- *
- * @param {string} newName
- */
- setName: function (newName) {
- this._name = newName;
- },
//--------------------------------------------------------------------------
// Private
diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js
index 8c2beb8bbfa..068e69b9c32 100644
--- a/addons/mail/static/src/js/models/threads/thread.js
+++ b/addons/mail/static/src/js/models/threads/thread.js
@@ -271,6 +271,14 @@ var Thread = AbstractThread.extend(ServicesMixin, {
markAsPreviewed: function () {
this._previewed = true;
},
+ /**
+ * Set the name of this thread
+ *
+ * @param {string} newName
+ */
+ setName: function (newName) {
+ this._name = newName;
+ },
//--------------------------------------------------------------------------
// Private
diff --git a/addons/mail/static/src/xml/discuss.xml b/addons/mail/static/src/xml/discuss.xml
index 90084a886bd..98430c81ce1 100644
--- a/addons/mail/static/src/xml/discuss.xml
+++ b/addons/mail/static/src/xml/discuss.xml
@@ -218,6 +218,11 @@
<input type="text" class="o_input o_mail_discuss_partner_invite_input" id="mail_search_partners"/>
</div>
+ <!-- Rename channel dialog's content -->
+ <div t-name="mail.RenameConversationDialog">
+ <input type="text" class="o_input o_mail_discuss_rename_channel_input"/>
+ </div>
+
<div t-name="mail.ModeratorRejectMessageDialog">
<input class="form-control" type="text" id="message_title" placeholder="Subject" value="Message Rejected"/>
<textarea class="form-control mt16" id="reject_message" placeholder="Mail Body">Your message was rejected by moderator.</textarea>