[IMP] hr, mail: use Channel instead of Thread in getChat
Part of task-2948676. closes odoo/odoo#99281 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -99,7 +99,7 @@ registerModel({
|
||||
*
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @returns {Thread|undefined}
|
||||
* @returns {Channel|undefined}
|
||||
*/
|
||||
async getChat() {
|
||||
if (!this.user && !this.hasCheckedUser) {
|
||||
@@ -125,7 +125,6 @@ registerModel({
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @param {Object} [options] forwarded to @see `Thread:open()`
|
||||
* @returns {Thread|undefined}
|
||||
*/
|
||||
async openChat(options) {
|
||||
const chat = await this.getChat();
|
||||
@@ -135,11 +134,10 @@ registerModel({
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
await chat.open(options);
|
||||
await chat.thread.open(options);
|
||||
if (!this.exists()) {
|
||||
return;
|
||||
}
|
||||
return chat;
|
||||
},
|
||||
/**
|
||||
* Opens the most appropriate view that is a profile for this employee.
|
||||
|
||||
@@ -42,11 +42,10 @@ const M2XAvatarMixin = {
|
||||
*
|
||||
* @private
|
||||
* @param {Object} params
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async _openChat(params) {
|
||||
const messaging = await Component.env.services.messaging.get();
|
||||
return messaging.openChat(params);
|
||||
messaging.openChat(params);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,37 @@ import { clear } from '@mail/model/model_field_command';
|
||||
|
||||
registerModel({
|
||||
name: 'Channel',
|
||||
modelMethods: {
|
||||
/**
|
||||
* Performs the `channel_get` RPC on `mail.channel`.
|
||||
*
|
||||
* `openChat` is preferable in business code because it will avoid the
|
||||
* RPC if the chat already exists.
|
||||
*
|
||||
* @param {Object} param0
|
||||
* @param {integer[]} param0.partnerIds
|
||||
* @param {boolean} [param0.pinForCurrentPartner]
|
||||
* @returns {Channel|undefined} the created or existing chat
|
||||
*/
|
||||
async performRpcCreateChat({ partnerIds, pinForCurrentPartner }) {
|
||||
// TODO FIX: potential duplicate chat task-2276490
|
||||
const data = await this.messaging.rpc({
|
||||
model: 'mail.channel',
|
||||
method: 'channel_get',
|
||||
kwargs: {
|
||||
partners_to: partnerIds,
|
||||
pin: pinForCurrentPartner,
|
||||
},
|
||||
});
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
const { channel } = this.messaging.models['Thread'].insert(
|
||||
this.messaging.models['Thread'].convertData(data)
|
||||
);
|
||||
return channel;
|
||||
},
|
||||
},
|
||||
recordMethods: {
|
||||
async fetchChannelMembers() {
|
||||
const channelData = await this.messaging.rpc({
|
||||
|
||||
@@ -118,7 +118,7 @@ registerModel({
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
this.messaging.chatWindowManager.openThread(chat, {
|
||||
this.messaging.chatWindowManager.openThread(chat.thread, {
|
||||
makeActive: true,
|
||||
replaceNewMessage: true,
|
||||
});
|
||||
|
||||
@@ -47,7 +47,7 @@ registerModel({
|
||||
* @param {integer} [param0.partnerId]
|
||||
* @param {integer} [param0.userId]
|
||||
* @param {Object} [options]
|
||||
* @returns {Thread|undefined}
|
||||
* @returns {Channel|undefined}
|
||||
*/
|
||||
async getChat({ partnerId, userId }) {
|
||||
if (userId) {
|
||||
@@ -86,18 +86,16 @@ registerModel({
|
||||
*
|
||||
* @param {Object} person forwarded to @see `getChat()`
|
||||
* @param {Object} [options] forwarded to @see `Thread:open()`
|
||||
* @returns {Thread|undefined}
|
||||
*/
|
||||
async openChat(person, options) {
|
||||
const chat = await this.getChat(person);
|
||||
if (!this.exists() || !chat) {
|
||||
return;
|
||||
}
|
||||
await chat.open(options);
|
||||
await chat.thread.open(options);
|
||||
if (!this.exists()) {
|
||||
return;
|
||||
}
|
||||
return chat;
|
||||
},
|
||||
/**
|
||||
* Opens the form view of the record with provided id and model.
|
||||
|
||||
@@ -617,7 +617,7 @@ registerModel({
|
||||
if (!this.exists() || !chat || this.messaging.device.isSmall) {
|
||||
return;
|
||||
}
|
||||
this.messaging.chatWindowManager.openThread(chat);
|
||||
this.messaging.chatWindowManager.openThread(chat.thread);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -283,7 +283,7 @@ registerModel({
|
||||
*
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @returns {Thread|undefined}
|
||||
* @returns {Channel|undefined}
|
||||
*/
|
||||
async getChat() {
|
||||
if (!this.user && !this.hasCheckedUser) {
|
||||
@@ -309,18 +309,16 @@ registerModel({
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @param {Object} [options] forwarded to @see `Thread:open()`
|
||||
* @returns {Thread|undefined}
|
||||
*/
|
||||
async openChat(options) {
|
||||
const chat = await this.getChat();
|
||||
if (!this.exists() || !chat) {
|
||||
return;
|
||||
}
|
||||
await chat.open(options);
|
||||
await chat.thread.open(options);
|
||||
if (!this.exists()) {
|
||||
return;
|
||||
}
|
||||
return chat;
|
||||
},
|
||||
/**
|
||||
* Opens the most appropriate view that is a profile for this partner.
|
||||
|
||||
@@ -361,34 +361,6 @@ registerModel({
|
||||
this.messaging.models['Thread'].convertData(data)
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Performs the `channel_get` RPC on `mail.channel`.
|
||||
*
|
||||
* `openChat` is preferable in business code because it will avoid the
|
||||
* RPC if the chat already exists.
|
||||
*
|
||||
* @param {Object} param0
|
||||
* @param {integer[]} param0.partnerIds
|
||||
* @param {boolean} [param0.pinForCurrentPartner]
|
||||
* @returns {Thread|undefined} the created or existing chat
|
||||
*/
|
||||
async performRpcCreateChat({ partnerIds, pinForCurrentPartner }) {
|
||||
// TODO FIX: potential duplicate chat task-2276490
|
||||
const data = await this.messaging.rpc({
|
||||
model: 'mail.channel',
|
||||
method: 'channel_get',
|
||||
kwargs: {
|
||||
partners_to: partnerIds,
|
||||
pin: pinForCurrentPartner,
|
||||
},
|
||||
});
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
return this.messaging.models['Thread'].insert(
|
||||
this.messaging.models['Thread'].convertData(data)
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Search for thread matching `searchTerm`.
|
||||
*
|
||||
|
||||
@@ -69,7 +69,7 @@ registerModel({
|
||||
*
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @returns {Thread|undefined}
|
||||
* @returns {Channel|undefined}
|
||||
*/
|
||||
async getChat() {
|
||||
if (!this.partner) {
|
||||
@@ -90,11 +90,11 @@ registerModel({
|
||||
return;
|
||||
}
|
||||
// in other cases a chat would be valid, find it or try to create it
|
||||
let chat = this.partner.dmChatWithCurrentPartner && this.partner.dmChatWithCurrentPartner.thread;
|
||||
if (!chat || !chat.isPinned) {
|
||||
let chat = this.partner.dmChatWithCurrentPartner;
|
||||
if (!chat || !chat.thread.isPinned) {
|
||||
// if chat is not pinned then it has to be pinned client-side
|
||||
// and server-side, which is a side effect of following rpc
|
||||
chat = await this.messaging.models['Thread'].performRpcCreateChat({
|
||||
chat = await this.messaging.models['Channel'].performRpcCreateChat({
|
||||
partnerIds: [this.partner.id],
|
||||
});
|
||||
if (!this.exists()) {
|
||||
@@ -116,18 +116,16 @@ registerModel({
|
||||
* If a chat is not appropriate, a notification is displayed instead.
|
||||
*
|
||||
* @param {Object} [options] forwarded to @see `Thread:open()`
|
||||
* @returns {Thread|undefined}
|
||||
*/
|
||||
async openChat(options) {
|
||||
const chat = await this.getChat();
|
||||
if (!this.exists() || !chat) {
|
||||
return;
|
||||
}
|
||||
await chat.open(options);
|
||||
await chat.thread.open(options);
|
||||
if (!this.exists() || !chat.exists()) {
|
||||
return;
|
||||
}
|
||||
return chat;
|
||||
},
|
||||
/**
|
||||
* Opens the most appropriate view that is a profile for this user.
|
||||
|
||||
Reference in New Issue
Block a user