Skip to content
Permalink
Browse files

[WIP] mail: chat window manager

  • Loading branch information...
alexkuhn committed May 13, 2019
1 parent 8f55a9e commit b4bb86b00611e596e84aaa0e687c61e5426702e3
@@ -64,6 +64,9 @@
'static/src/xml/wip/old_widget/discuss.xml',
'static/src/xml/wip/old_widget/discuss_invite_partner_dialog.xml',
'static/src/xml/wip/widget/autocomplete_input.xml',
'static/src/xml/wip/widget/chat_window.xml',
'static/src/xml/wip/widget/chat_window_hidden_menu.xml',
'static/src/xml/wip/widget/chat_window_manager.xml',
'static/src/xml/wip/widget/composer.xml',
'static/src/xml/wip/widget/discuss_mobile_mailbox_selection.xml',
'static/src/xml/wip/widget/discuss_mobile_navbar.xml',
@@ -6,7 +6,6 @@ const StoreMixin = require('mail.wip.old_widget.StoreMixin');
const Root = require('mail.wip.widget.DiscussRoot');

const AbstractAction = require('web.AbstractAction');
const config = require('web.config');
const core = require('web.core');
const session = require('web.session');

@@ -1,41 +1,47 @@
odoo.define('mail.wip.service.ChatWindowService', function (require) {
"use strict";

var StoreMixin = require('mail.wip.old_widget.StoreMixin');
var Root = require('mail.wip.widget.ChatWindowManager');
const StoreMixin = require('mail.wip.old_widget.StoreMixin');
const Root = require('mail.wip.widget.ChatWindowManager');

var AbstractService = require('web.AbstractService');
var core = require('web.core');
const AbstractService = require('web.AbstractService');
const core = require('web.core');
const session = require('web.session');

var _t = core._t;
const _t = core._t;

var ChatWindowService = AbstractService.extend(StoreMixin, {
const ChatWindowService = AbstractService.extend(StoreMixin, {
DEBUG: true,
dependencies: ['store'],
/**
* @override {web.AbstractService}
*/
init: function () {
init() {
this._super.apply(this, arguments);
if (this.DEBUG) {
window.chat_window_manager = this;
}
},
/**
* @override {web.AbstractService}
*/
async start() {
start() {
this._super.apply(this, arguments);
await this.awaitStore();
const env = {
store: this.store,
call: (...args) => this.call(...args),
do_action: (...args) => this.do_action(...args),
rpc: (...args) => this._rpc(...args),
_t,
};
this._root = new Root(env);
this._root.mount(this.$el[0]); // aku todo
core.bus.on('web_client_ready', this, async () => {
await this.awaitStore();
const env = {
_t,
qweb: core.qwebOwl,
session,
store: this.store,
call: (...args) => this.call(...args),
do_action: (...args) => this.do_action(...args),
rpc: (...args) => this._rpc(...args),
};
this.root = new Root(env);
this.root.mount(document.querySelector('body'));
});
},
});

// core.serviceRegistry.add('chat_window', ChatWindowService);
core.serviceRegistry.add('chat_window', ChatWindowService);

return ChatWindowService;

@@ -19,6 +19,7 @@ function initializeState() {
const odoobot = new Partner({ id: 'odoobot', name: _t("OdooBot") });

return {
$detachedThreads: [],
$pinnedThreads: [],
FETCH_LIMIT: 30, // max number of fetched messages from the server
cannedResponses: {},
@@ -39,7 +40,10 @@ function initializeState() {
partners: { odoobot }, // all partner infos
pinnedDmPartnerIDs: [], // partner_ids we have a pinned DM chat with
threadCaches: {},
threads: {} // all threads, including channels, DM, mailboxes, document threads, ...
threads: {}, // all threads, including channels, DM, mailboxes, document threads, ...
window: {
innerWidth: window.innerWidth,
},
};
}

@@ -72,10 +76,15 @@ const StoreService = AbstractService.extend({
*/
start() {
this.ready = new Promise(resolve =>
this.store.dispatch('init', { ready: resolve })
this.store.dispatch('init', {
ready: () => {
this.store.commit('window/resize');
resolve();
}
})
);
window.addEventListener('resize', _.throttle(() => {
this.store.commit('update', { isMobile: config.device.isMobile });
window.addEventListener('resize', _.debounce(() => {
this.store.commit('window/resize');
}), 100);
},

@@ -7,6 +7,7 @@ const Partner = require('mail.wip.model.Partner');
const Thread = require('mail.wip.model.Thread');
const ThreadCache = require('mail.wip.model.ThreadCache');

const config = require('web.config');
const core = require('web.core');
const session = require('web.session');

@@ -925,6 +926,26 @@ const mutations = {
'update'({ state }, changes) {
Object.assign(state, changes);
},
/**
* @param {Object} param0
* @param {Object} param0.state
*/
'window/resize'({ state }) {
state.window.innerWidth = window.innerWidth;
state.isMobile = config.device.isMobile;
},
/**
* @param {Object} param0
* @param {Object} param0.state
* @param {Object} param1
* @param {string} param1.$thread
*/
'wip/thread/detach'({ state }, { $thread }) {
if (state.$detachedThreads.includes($thread)) {
return;
}
state.$detachedThreads.push($thread);
},
};

return mutations;
@@ -0,0 +1,74 @@
odoo.define('mail.wip.widget.ChatWindow', function () {
"use strict";

const { Component, connect } = owl;

/**
* @param {Object} state
* @param {Object} ownProps
* @param {string} ownProps.$thread
* @return {Object}
*/
function mapStateToProps(state, ownProps) {
return {
thread: state.threads[ownProps.$thread],
};
}

class ChatWindow extends Component {
/**
* @param {...any} args
*/
constructor(...args) {
super(...args);
this.template = 'mail.wip.widget.ChatWindow';
}

mounted() {
this._applyOffset();
}

patched() {
this._applyOffset();
}

//--------------------------------------------------------------------------
// Getter / Setter
//--------------------------------------------------------------------------

/**
* @return {string}
*/
get $thread() {
return this.props.$thread;
}

/**
* @return {integer}
*/
get offset() {
return this.props.offset;
}

/**
* @return {mail.wip.model.Thread}
*/
get thread() {
return this.props.thread;
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* @private
*/
_applyOffset() {
this.el.style.right = this.offset + 'px';
}
}

return connect(mapStateToProps, { deep: false })(ChatWindow);

});
@@ -0,0 +1,76 @@
odoo.define('mail.wip.widget.ChatWindowHiddenMenu', function () {
"use strict";

const { Component, connect } = owl;

/**
* @param {Object} state
* @param {Object} ownProps
* @param {string[]} ownProps.$threads
* @return {Object}
*/
function mapStateToProps(state, ownProps) {
return {
threads: Object.values(state.threads).map(thread =>
ownProps.$threads.includes(thread.localID)),
};
}

class HiddenMenu extends Component {
/**
* @param {...any} args
*/
constructor(...args) {
super(...args);
this.template = 'mail.wip.widget.ChatWindowHiddenMenu';
}

mounted() {
this._applyOffset();
}

patched() {
this._applyOffset();
}

//--------------------------------------------------------------------------
// Getter / Setter
//--------------------------------------------------------------------------

/**
* @return {string[]}
*/
get $threads() {
return this.props.$threads;
}

/**
* @return {integer}
*/
get offset() {
return this.props.offset;
}

/**
* @return {mail.wip.model.Thread[]}
*/
get threads() {
return this.props.threads;
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* @private
*/
_applyOffset() {
this.el.style.right = this.offset + 'px';
}

}

return connect(mapStateToProps, { deep: false })(HiddenMenu);

});

0 comments on commit b4bb86b

Please sign in to comment.
You can’t perform that action at this time.