[REF] mail: turn 'store.ringingThreads' into relational field
Part-of: odoo/odoo#136308
This commit is contained in:
@@ -134,7 +134,6 @@ export class Store {
|
||||
users = {};
|
||||
internalUserGroupId = null;
|
||||
registeredImStatusPartners = null;
|
||||
ringingThreads = null;
|
||||
|
||||
hasLinkPreviewFeature = true;
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
declare module "models" {
|
||||
import { RtcSession as RtcSessionClass } from "@mail/discuss/call/common/rtc_session_model";
|
||||
|
||||
export interface DiscussApp {
|
||||
ringingThreads: Thread[],
|
||||
}
|
||||
export interface RtcSession extends RtcSessionClass {}
|
||||
|
||||
export interface Models {
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
|
||||
<t t-name="discuss.CallInvitations">
|
||||
<div class="o-discuss-CallInvitations position-absolute top-0 end-0 d-flex flex-column p-2">
|
||||
<t t-if="rtc.ringingThreads">
|
||||
<t t-foreach="rtc.ringingThreads" t-as="threadLocalId" t-key="threadLocalId">
|
||||
<t t-set="thread" t-value="store.Thread.records[threadLocalId]"/>
|
||||
<CallInvitation t-if="thread" thread="thread"/>
|
||||
</t>
|
||||
<t t-foreach="store.discuss.ringingThreads" t-as="thread" t-key="thread.localId">
|
||||
<CallInvitation thread="thread"/>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { DiscussApp } from "@mail/core/common/discuss_app_model";
|
||||
import { Record } from "@mail/core/common/record";
|
||||
import { onChange } from "@mail/utils/common/misc";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(DiscussApp, {
|
||||
new(data) {
|
||||
const app = super.new(data);
|
||||
onChange(app, "ringingThreads", () => {
|
||||
if (app.ringingThreads.length > 0) {
|
||||
this.env.services["mail.sound_effects"].play("incoming-call", { loop: true });
|
||||
} else {
|
||||
this.env.services["mail.sound_effects"].stop("incoming-call");
|
||||
}
|
||||
});
|
||||
return app;
|
||||
},
|
||||
});
|
||||
|
||||
patch(DiscussApp.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.ringingThreads = Record.many("Thread");
|
||||
},
|
||||
});
|
||||
@@ -135,9 +135,6 @@ export class Rtc {
|
||||
sourceScreenStream: null,
|
||||
});
|
||||
this.blurManager = undefined;
|
||||
this.ringingThreads = reactive([], () => this.onRingingThreadsChange());
|
||||
void this.ringingThreads.length;
|
||||
this.store.ringingThreads = this.ringingThreads;
|
||||
onChange(this.userSettingsService, "useBlur", () => {
|
||||
if (this.state.sendCamera) {
|
||||
this.toggleVideo("camera", true);
|
||||
@@ -283,14 +280,6 @@ export class Rtc {
|
||||
}
|
||||
}
|
||||
|
||||
onRingingThreadsChange() {
|
||||
if (this.ringingThreads.length > 0) {
|
||||
this.soundEffectsService.play("incoming-call", { loop: true });
|
||||
} else {
|
||||
this.soundEffectsService.stop("incoming-call");
|
||||
}
|
||||
}
|
||||
|
||||
async deafen() {
|
||||
await this.setDeaf(true);
|
||||
this.soundEffectsService.play("deafen");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { Thread } from "@mail/core/common/thread_model";
|
||||
import { removeFromArray } from "@mail/utils/common/arrays";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
@@ -13,8 +12,8 @@ patch(Thread.prototype, {
|
||||
if (session.notIn(this.rtcSessions)) {
|
||||
this.rtcSessions.push(session);
|
||||
}
|
||||
if (!this._store.ringingThreads.includes(this.localId)) {
|
||||
this._store.ringingThreads.push(this.localId);
|
||||
if (this.notIn(this._store.discuss.ringingThreads)) {
|
||||
this._store.discuss.ringingThreads.push(this);
|
||||
}
|
||||
}
|
||||
let rtcContinue = true;
|
||||
@@ -22,15 +21,16 @@ patch(Thread.prototype, {
|
||||
if (Array.isArray(data.rtcInvitingSession)) {
|
||||
if (data.rtcInvitingSession[0][0] === "unlink") {
|
||||
this.rtcInvitingSession = undefined;
|
||||
removeFromArray(this._store.ringingThreads, this.localId);
|
||||
this._store.discuss.ringingThreads.delete(this);
|
||||
}
|
||||
rtcContinue = false;
|
||||
} else {
|
||||
const session = this._store.RtcSession.insert(data.rtcInvitingSession);
|
||||
if (session.notIn(this.rtcSessions)) {
|
||||
this.rtcSessions.push(session);
|
||||
}
|
||||
this._store.discuss.ringingThreads.push(this);
|
||||
}
|
||||
const session = this._store.RtcSession.insert(data.rtcInvitingSession);
|
||||
if (session.notIn(this.rtcSessions)) {
|
||||
this.rtcSessions.push(session);
|
||||
}
|
||||
this._store.ringingThreads.push(this.localId);
|
||||
}
|
||||
if (rtcContinue && "rtcSessions" in data) {
|
||||
for (const command of data.rtcSessions) {
|
||||
|
||||
@@ -41,23 +41,28 @@ export function isDragSourceExternalFile(dataTransfer) {
|
||||
* @param {Function} callback
|
||||
*/
|
||||
export function onChange(target, key, callback) {
|
||||
let proxy;
|
||||
function _observe() {
|
||||
void proxy[key];
|
||||
if (proxy[key] instanceof Object) {
|
||||
void Object.keys(proxy[key]);
|
||||
}
|
||||
if (proxy[key] instanceof Array) {
|
||||
void proxy[key].length;
|
||||
void proxy[key].forEach((i) => i);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(key)) {
|
||||
for (const k of key) {
|
||||
onChange(target, k, callback);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const proxy = reactive(target, () => {
|
||||
void proxy[key];
|
||||
if (proxy[key] instanceof Object) {
|
||||
void Object.keys(proxy[key]);
|
||||
}
|
||||
proxy = reactive(target, () => {
|
||||
_observe();
|
||||
callback();
|
||||
});
|
||||
void proxy[key];
|
||||
if (proxy[key] instanceof Object) {
|
||||
void Object.keys(proxy[key]);
|
||||
}
|
||||
_observe();
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user