[IMP] mail: add ooo status in chats windows.
In a chat window with a single usert (dm_chat) the ooo status of the other user is displayed on the top when set. Task: 1856205
This commit is contained in:
@@ -579,6 +579,10 @@ class Channel(models.Model):
|
||||
.channel_partner_ids
|
||||
.filtered(lambda p: p.id != self.env.user.partner_id.id)
|
||||
.read(['id', 'name', 'im_status']))
|
||||
for direct_partner in info['direct_partner']:
|
||||
users = self.env['res.partner'].browse(direct_partner['id']).user_ids
|
||||
if users:
|
||||
direct_partner['out_of_office_message'] = users[0].out_of_office_message
|
||||
|
||||
# add last message preview (only used in mobile)
|
||||
if self._context.get('isMobile', False):
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
odoo.define('mail.model.DMChat', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var TwoUserChannel = require('mail.model.TwoUserChannel');
|
||||
var _t = core._t;
|
||||
|
||||
/**
|
||||
* Any piece of code in JS that make use of DMs must ideally interact with
|
||||
@@ -18,6 +20,7 @@ var DMChat = TwoUserChannel.extend({
|
||||
* @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
|
||||
* @param {string} [params.data.direct_partner[0].out_of_office_message='']
|
||||
*/
|
||||
init: function (params) {
|
||||
this._super.apply(this, arguments);
|
||||
@@ -50,6 +53,17 @@ var DMChat = TwoUserChannel.extend({
|
||||
getDirectPartnerID: function () {
|
||||
return this._directPartnerID;
|
||||
},
|
||||
/**
|
||||
* Get the out of office message of the thread
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getOutOfOfficeMessage: function () {
|
||||
if (this._outOfOfficeMessage === '') {
|
||||
return undefined;
|
||||
}
|
||||
return this._outOfOfficeMessage;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -147,6 +147,22 @@ var AbstractThreadWindow = Widget.extend({
|
||||
}
|
||||
return this._thread;
|
||||
},
|
||||
/**
|
||||
* Get out of office user text
|
||||
*
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
getOutOfOfficeMessage: function () {
|
||||
if (
|
||||
!(
|
||||
this.hasThread() &&
|
||||
this._thread.getType() === 'dm_chat'
|
||||
)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return this._thread.getOutOfOfficeMessage();
|
||||
},
|
||||
/**
|
||||
* Get the status of the thread, such as the im status of a DM chat
|
||||
* ('online', 'offline', etc.). If this window has no thread, returns
|
||||
|
||||
@@ -79,6 +79,11 @@ $o-mail-thread-window-zindex: $zindex-modal + 1 !default;
|
||||
|
||||
}
|
||||
|
||||
.o_out_of_office {
|
||||
background-color: #9dd0e8;
|
||||
padding:8px;
|
||||
}
|
||||
|
||||
.o_mail_thread {
|
||||
flex: 1 1 100%;
|
||||
overflow: auto;
|
||||
|
||||
@@ -252,6 +252,11 @@
|
||||
&.o_user_idle {
|
||||
color: theme-color('warning');
|
||||
}
|
||||
&.fa-stack {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
line-height: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,19 @@
|
||||
margin-top: 2px;
|
||||
text-align: center;
|
||||
font-size: smaller;
|
||||
.o_thread_message_sidebar_image {
|
||||
position: relative;
|
||||
height: $o-mail-thread-avatar-size;
|
||||
|
||||
.o_updatable_im_status {
|
||||
width: $o-mail-thread-avatar-size;
|
||||
}
|
||||
.o_mail_user_status {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@include media-breakpoint-down(sm) {
|
||||
margin-top: 4px;
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
-->
|
||||
<t t-name="mail.ThreadWindow" t-extend="mail.AbstractThreadWindow">
|
||||
<t t-jquery=".o_thread_window_header" t-operation="after">
|
||||
<div class="o_out_of_office" t-if="widget.getOutOfOfficeMessage() !== undefined">
|
||||
<div class="o_out_of_office_text" t-esc="widget.getOutOfOfficeMessage()"/>
|
||||
</div>
|
||||
<div t-if="!widget.hasThread()" class="o_thread_search_input">
|
||||
<span> To: </span>
|
||||
<input type="text" placeholder="User name"/>
|
||||
|
||||
@@ -632,6 +632,69 @@ QUnit.test('do not auto-focus chat window on receiving new message from new DM',
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('out-of-office status in thread window', function (assert) {
|
||||
assert.expect(1);
|
||||
this.data = {
|
||||
'mail.message': {
|
||||
fields: {},
|
||||
records: [],
|
||||
},
|
||||
initMessaging: {
|
||||
channel_slots: {
|
||||
channel_channel: [{
|
||||
id: 1,
|
||||
name: "DM",
|
||||
channel_type: "chat",
|
||||
message_unread_counter: 0,
|
||||
direct_partner: [{ id: 666, name: 'DemoUser1', im_status: 'online', out_of_office_message: 'Please don\'t disturb'}],
|
||||
}],
|
||||
},
|
||||
},
|
||||
};
|
||||
var parent = this.createParent({
|
||||
data: this.data,
|
||||
services: this.services,
|
||||
});
|
||||
// detach channel 1, so that it opens corresponding thread window.
|
||||
parent.call('mail_service', 'getChannel', 1).detach();
|
||||
|
||||
var $threadWindow = $('.o_thread_window');
|
||||
assert.containsOnce($threadWindow, '.o_out_of_office_text');
|
||||
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('no out-of-office status in thread window', function (assert) {
|
||||
assert.expect(1);
|
||||
this.data = {
|
||||
'mail.message': {
|
||||
fields: {},
|
||||
records: [],
|
||||
},
|
||||
initMessaging: {
|
||||
channel_slots: {
|
||||
channel_channel: [{
|
||||
id: 1,
|
||||
name: "DM",
|
||||
channel_type: "chat",
|
||||
message_unread_counter: 0,
|
||||
direct_partner: [{ id: 666, name: 'DemoUser1', im_status: 'online'}],
|
||||
}],
|
||||
},
|
||||
},
|
||||
};
|
||||
var parent = this.createParent({
|
||||
data: this.data,
|
||||
services: this.services,
|
||||
});
|
||||
// detach channel 1, so that it opens corresponding thread window.
|
||||
parent.call('mail_service', 'getChannel', 1).detach();
|
||||
|
||||
var $threadWindow = $('.o_thread_window');
|
||||
assert.containsNone($threadWindow, '.o_out_of_office_text');
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -196,6 +196,19 @@ class TestChannelFeatures(common.BaseFunctionalTest, common.MockEmails):
|
||||
email['email_to'][0],
|
||||
[formataddr((self.user_employee.name, self.user_employee.email)), formataddr((self.test_partner.name, self.test_partner.email))])
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_channel_out_of_office(self):
|
||||
self.user_employee.out_of_office_message = 'Out'
|
||||
test_chat = self.env['mail.channel'].with_context(common.BaseFunctionalTest._test_context).create({
|
||||
'channel_partner_ids': [(4, self.user_employee.partner_id.id), (4, self.user_admin.partner_id.id)],
|
||||
'public': 'private',
|
||||
'channel_type': 'chat',
|
||||
'email_send': False,
|
||||
'name': 'test'
|
||||
})
|
||||
infos = test_chat.sudo(self.user_admin).channel_info()
|
||||
self.assertEqual(infos[0]['direct_partner'][0]['out_of_office_message'], 'Out')
|
||||
|
||||
|
||||
@tagged('moderation')
|
||||
class TestChannelModeration(common.Moderation):
|
||||
|
||||
Reference in New Issue
Block a user