[REF] mail: move startChat to discuss folder
Part of task-3265211 Part-of: odoo/odoo#128799
This commit is contained in:
@@ -662,26 +662,6 @@ export class ThreadService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {[number]} partnerIds
|
||||
* @param {boolean} inChatWindow
|
||||
*/
|
||||
async startChat(partnerIds, inChatWindow) {
|
||||
const partners_to = [...new Set([this.store.self.id, ...partnerIds])];
|
||||
if (partners_to.length === 1) {
|
||||
const chat = await this.joinChat(partners_to[0]);
|
||||
this.open(chat, inChatWindow);
|
||||
} else if (partners_to.length === 2) {
|
||||
const correspondentId = partners_to.find(
|
||||
(partnerId) => partnerId !== this.store.self.id
|
||||
);
|
||||
const chat = await this.joinChat(correspondentId);
|
||||
this.open(chat, inChatWindow);
|
||||
} else {
|
||||
await this.createGroupChat({ partners_to });
|
||||
}
|
||||
}
|
||||
|
||||
async createGroupChat({ default_display_mode, partners_to }) {
|
||||
const data = await this.orm.call("discuss.channel", "create_group", [], {
|
||||
default_display_mode,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { ImStatus } from "@mail/core/common/im_status";
|
||||
import { ActionPanel } from "@mail/discuss/core/common/action_panel";
|
||||
import { useMessaging, useStore } from "@mail/core/common/messaging_hook";
|
||||
import { useDiscussCoreCommon } from "@mail/discuss/core/common/discuss_core_common_service";
|
||||
|
||||
import { Component, onMounted, onWillStart, useRef, useState } from "@odoo/owl";
|
||||
|
||||
@@ -16,6 +17,7 @@ export class ChannelInvitation extends Component {
|
||||
static template = "discuss.ChannelInvitation";
|
||||
|
||||
setup() {
|
||||
this.discussCoreCommonService = useDiscussCoreCommon();
|
||||
this.messaging = useMessaging();
|
||||
this.store = useStore();
|
||||
this.notification = useService("notification");
|
||||
@@ -100,7 +102,7 @@ export class ChannelInvitation extends Component {
|
||||
|
||||
async onClickInvite() {
|
||||
if (this.props.thread.type === "chat") {
|
||||
await this.threadService.startChat([
|
||||
await this.discussCoreCommonService.startChat([
|
||||
this.props.thread.chatPartnerId,
|
||||
...this.state.selectedPartners.map((partner) => partner.id),
|
||||
]);
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
import { removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
|
||||
import { createLocalId } from "@mail/utils/common/misc";
|
||||
|
||||
import { markup, reactive } from "@odoo/owl";
|
||||
import { markup, reactive, useState } from "@odoo/owl";
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
|
||||
export class DiscussCoreCommon {
|
||||
@@ -152,6 +153,26 @@ export class DiscussCoreCommon {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {[number]} partnerIds
|
||||
* @param {boolean} inChatWindow
|
||||
*/
|
||||
async startChat(partnerIds, inChatWindow) {
|
||||
const partners_to = [...new Set([this.store.self.id, ...partnerIds])];
|
||||
if (partners_to.length === 1) {
|
||||
const chat = await this.threadService.joinChat(partners_to[0]);
|
||||
this.threadService.open(chat, inChatWindow);
|
||||
} else if (partners_to.length === 2) {
|
||||
const correspondentId = partners_to.find(
|
||||
(partnerId) => partnerId !== this.store.self.id
|
||||
);
|
||||
const chat = await this.threadService.joinChat(correspondentId);
|
||||
this.threadService.open(chat, inChatWindow);
|
||||
} else {
|
||||
await this.threadService.createGroupChat({ partners_to });
|
||||
}
|
||||
}
|
||||
|
||||
async _handleNotificationNewMessage(notif) {
|
||||
const { id, message: messageData } = notif.payload;
|
||||
let channel = this.store.threads[createLocalId("discuss.channel", id)];
|
||||
@@ -253,4 +274,11 @@ export const discussCoreCommon = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {DiscussCoreCommon}
|
||||
*/
|
||||
export function useDiscussCoreCommon() {
|
||||
return useState(useService("discuss.core.common"));
|
||||
}
|
||||
|
||||
registry.category("services").add("discuss.core.common", discussCoreCommon);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import { useStore } from "@mail/core/common/messaging_hook";
|
||||
import { NavigableList } from "@mail/core/common/navigable_list";
|
||||
import { useDiscussCoreCommon } from "@mail/discuss/core/common/discuss_core_common_service";
|
||||
import { cleanTerm } from "@mail/utils/common/format";
|
||||
import { createLocalId } from "@mail/utils/common/misc";
|
||||
import { isEventHandled, markEventHandled } from "@web/core/utils/misc";
|
||||
|
||||
import { Component, onMounted, useRef, useState } from "@odoo/owl";
|
||||
|
||||
@@ -12,6 +12,7 @@ import { getActiveHotkey } from "@web/core/hotkeys/hotkey_service";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { TagsList } from "@web/core/tags_list/tags_list";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { isEventHandled, markEventHandled } from "@web/core/utils/misc";
|
||||
|
||||
export class ChannelSelector extends Component {
|
||||
static components = { TagsList, NavigableList };
|
||||
@@ -20,6 +21,7 @@ export class ChannelSelector extends Component {
|
||||
static template = "discuss.ChannelSelector";
|
||||
|
||||
setup() {
|
||||
this.discussCoreCommonService = useDiscussCoreCommon();
|
||||
/** @type {import("@mail/core/common/store_service").Store} */
|
||||
this.store = useStore();
|
||||
/** @type {import("@mail/core/common/thread_service").ThreadService} */
|
||||
@@ -137,7 +139,10 @@ export class ChannelSelector extends Component {
|
||||
if (selectedPartnerIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
await this.threadService.startChat(selectedPartnerIds, this.env.inChatWindow);
|
||||
await this.discussCoreCommonService.startChat(
|
||||
selectedPartnerIds,
|
||||
this.env.inChatWindow
|
||||
);
|
||||
}
|
||||
if (this.props.onValidate) {
|
||||
this.props.onValidate();
|
||||
|
||||
Reference in New Issue
Block a user