summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/threads/dm_chat.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js')
-rw-r--r--addons/mail/static/src/js/models/threads/dm_chat.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js
new file mode 100644
index 00000000000..767a6e32edd
--- /dev/null
+++ b/addons/mail/static/src/js/models/threads/dm_chat.js
@@ -0,0 +1,63 @@
+odoo.define('mail.model.DMChat', function (require) {
+"use strict";
+
+var TwoUserChannel = require('mail.model.TwoUserChannel');
+
+/**
+ * Any piece of code in JS that make use of DMs must ideally interact with
+ * such objects, instead of direct data from the server.
+ */
+var DMChat = TwoUserChannel.extend({
+ /**
+ * @override
+ * @param {Object} params
+ * @param {Object} params.data
+ * @param {Object[]} params.data.direct_partner
+ * @param {integer} params.data.direct_partner[0].id
+ * @param {string} params.data.direct_partner[0].im_status
+ * @param {string} params.data.direct_partner[0].name
+ */
+ init: function (params) {
+ this._super.apply(this, arguments);
+
+ var data = params.data;
+
+ this._directPartnerID = data.direct_partner[0].id;
+ this._name = data.direct_partner[0].name;
+ this._status = data.direct_partner[0].im_status;
+ this._type = 'dm_chat';
+ },
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * Get the direct partner ID linked to the DM, i.e. the partner ID of the
+ * user at the other end of the DM conversation. All DM chats do have a
+ * direct partner iD.
+ *
+ * @returns {integer}
+ */
+ getDirectPartnerID: function () {
+ return this._directPartnerID;
+ },
+ /**
+ * @override
+ */
+ getPreview: function () {
+ var result = this._super.apply(this, arguments);
+ result.imageSRC = '/web/image/res.partner/' + this.getDirectPartnerID() + '/image_small';
+ return result;
+ },
+ /**
+ * @param {string} newStatus
+ */
+ setStatus: function (newStatus) {
+ this._status = newStatus;
+ },
+});
+
+return DMChat;
+
+});