[IMP] im_livechat, mail: website livechat model
Make use of a website livechat model, so that im_livechat can make use of this model. This provides an almost similar model for threads in the backend and in the frontend. As a consequence, im_livechat and website livechat windows have been adapted to handle a website livechat model.
This commit is contained in:
@@ -196,19 +196,19 @@ var LivechatButton = Widget.extend({
|
||||
anonymous_name : this.options.default_username,
|
||||
}, {shadow: true});
|
||||
}
|
||||
def.then(function (channel) {
|
||||
if (!channel || !channel.operator_pid) {
|
||||
def.then(function (livechatData) {
|
||||
if (!livechatData || !livechatData.operator_pid) {
|
||||
alert(_t("None of our collaborators seems to be available, please try again later."));
|
||||
} else {
|
||||
self._channel = channel;
|
||||
self._openChatWindow(channel);
|
||||
self._channel = new WebsiteLivechat(livechatData);
|
||||
self._openChatWindow(channel); // AKU: TODO
|
||||
self._sendWelcomeMessage();
|
||||
self._renderMessages();
|
||||
|
||||
self._busBus.add_channel(channel.uuid);
|
||||
self._busBus.add_channel(channel.uuid); // AKU: TODO
|
||||
self._busBus.start_polling();
|
||||
|
||||
utils.set_cookie('im_livechat_session', JSON.stringify(channel), 60*60);
|
||||
utils.set_cookie('im_livechat_session', JSON.stringify(channel), 60*60); // AKU: TODO
|
||||
utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
|
||||
}
|
||||
}).always(function () {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
odoo.define('im_livechat.model.WebsiteLivechat', function (require) {
|
||||
"use strict";
|
||||
|
||||
var AbstractThread = require('mail.AbstractThread');
|
||||
|
||||
/**
|
||||
* Thread model that represents a livechat on the website-side. This livechat
|
||||
* is not linked to the mail service.
|
||||
*/
|
||||
var WebsiteLivechat = AbstractThread.extend({
|
||||
/**
|
||||
* @param {Object} livechatData
|
||||
* @param {integer} livechatData.id the ID of this livechat.
|
||||
* @param {integer} [livechatData.message_unread_counter=0] the unread
|
||||
* counter of this livechat.
|
||||
* @param {string} livechatData.name the name of this livechat.
|
||||
* @param {string} livechatData.state if 'folded', the livechat is folded.
|
||||
*/
|
||||
init: function (livechatData) {
|
||||
var params = { data: livechatData };
|
||||
|
||||
this._super(params);
|
||||
|
||||
this._folded = livechatData.state === 'folded';
|
||||
this._name = livechatData.name;
|
||||
this._unreadCounter = livechatData.message_unread_counter || 0;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @returns {mail.model.AbstractMessage[]}
|
||||
*/
|
||||
getMessages: function () {},
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getTitle: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* @returns {integer}
|
||||
*/
|
||||
getUnreadCounter: function () {
|
||||
return this._unreadCounter;
|
||||
},
|
||||
/**
|
||||
* Increments the unread counter of this livechat by 1 unit.
|
||||
*/
|
||||
incrementUnreadCounter: function () {
|
||||
this._unreadCounter++;
|
||||
},
|
||||
/**
|
||||
* Resets the unread counter of this livechat to 0.
|
||||
*/
|
||||
resetUnreadCounter: function () {
|
||||
this._unreadCounter = 0;
|
||||
},
|
||||
/**
|
||||
* @param {boolean} folded
|
||||
*/
|
||||
updateFoldState: function (folded) {
|
||||
this._folded = folded;
|
||||
},
|
||||
});
|
||||
|
||||
return WebsiteLivechat;
|
||||
|
||||
});
|
||||
@@ -10,21 +10,14 @@ var AbstractThreadWindow = require('mail.AbstractThreadWindow');
|
||||
*/
|
||||
var LivechatWindow = AbstractThreadWindow.extend({
|
||||
/**
|
||||
* The thread of a live chat window is just an object containing some
|
||||
* server data of the livechat
|
||||
*
|
||||
* @override
|
||||
* @param {mail.Manager} parent
|
||||
* @param {Object} data
|
||||
* @param {integer} data.id
|
||||
* @param {string} data.name
|
||||
* @param {string} data.state
|
||||
* @param {integer} [data.message_unread_counter=0]
|
||||
* @param {?} parent
|
||||
* @param {im_livechat.model.WebsiteLivechat} thread
|
||||
*/
|
||||
init: function (parent, data) {
|
||||
init: function (parent, thread) {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
this._data = data;
|
||||
this._thread = thread;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -42,35 +35,35 @@ var LivechatWindow = AbstractThreadWindow.extend({
|
||||
* @returns {string}
|
||||
*/
|
||||
getTitle: function () {
|
||||
return this._data.name;
|
||||
return this._thread.getTitle();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @returns {integer}
|
||||
*/
|
||||
getUnreadCounter: function () {
|
||||
return this._data.message_unread_counter;
|
||||
return this._thread.getUnreadCounter();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasThread: function () {
|
||||
return !!this._data;
|
||||
return !!this._thread;
|
||||
},
|
||||
/**
|
||||
* Increment the unread counter of this thread window, which is equivalent
|
||||
* to incrementing the unread counter of the related channel
|
||||
*/
|
||||
incrementUnreadCounter: function () {
|
||||
this._data.message_unread_counter++;
|
||||
this._thread.incrementUnreadCounter();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isFolded: function () {
|
||||
return (this._data.state === 'folded');
|
||||
return this._thread.isFolded();
|
||||
},
|
||||
/**
|
||||
* Warn the parent widget (LivechatButton)
|
||||
@@ -86,7 +79,7 @@ var LivechatWindow = AbstractThreadWindow.extend({
|
||||
* Reset the unread counter of the livechat window
|
||||
*/
|
||||
resetUnreadCounter: function () {
|
||||
this._data.message_unread_counter = 0;
|
||||
this._thread.resetUnreadCounter();
|
||||
this._renderHeader();
|
||||
},
|
||||
|
||||
@@ -102,7 +95,7 @@ var LivechatWindow = AbstractThreadWindow.extend({
|
||||
* @returns {integer}
|
||||
*/
|
||||
_getThreadID: function () {
|
||||
return this._data.id;
|
||||
return this._thread.getID();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
@@ -118,14 +111,9 @@ var LivechatWindow = AbstractThreadWindow.extend({
|
||||
* @param {boolean} folded
|
||||
*/
|
||||
_updateThreadFoldState: function (folded) {
|
||||
this._data.state = folded ? 'folded' : 'open';
|
||||
this._thread.updateFoldState(folded);
|
||||
this.updateVisualFoldState();
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
});
|
||||
|
||||
return LivechatWindow;
|
||||
|
||||
@@ -13,7 +13,7 @@ var AbstractThread = Class.extend({
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {Object} params.data
|
||||
* @param {Object} params.data.id the ID of this thread
|
||||
* @param {integer|string} params.data.id the ID of this thread
|
||||
*/
|
||||
init: function (params) {
|
||||
this._id = params.data.id;
|
||||
|
||||
@@ -12,7 +12,7 @@ var _t = core._t;
|
||||
/**
|
||||
* Special document thread that is linked to a new document that is in create
|
||||
* mode. This thread only display a single (fake) message which displays the
|
||||
* user avatar and the message 'creating a new record...'.
|
||||
* user avatar and the message 'Creating a new record...'.
|
||||
*
|
||||
* Note: it uses AbstractThread and AbstractMessage, because this is a fake
|
||||
* thread which contains a fake message. We do not want to register both of them
|
||||
|
||||
@@ -122,7 +122,7 @@ var ThreadWidget = Widget.extend({
|
||||
selectedMessageID: this._selectedMessageID,
|
||||
});
|
||||
|
||||
// dict where key is message ID, and value is whether it should hide
|
||||
// dict where key is message ID, and value is whether it should display
|
||||
// the author of message or not visually
|
||||
var displayAuthorMessages = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user