Skip to content

Commit 41527b8

Browse files
res-odoobrboi
authored andcommitted
[IMP] mail: SW: Extract handle notification click inside its own method
1 parent fccac78 commit 41527b8

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

addons/mail/static/src/service_worker.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,40 +156,43 @@ async function openDiscussChannel(channelId, { action, joinCall = false, source
156156
}
157157
}
158158

159-
self.addEventListener("notificationclick", (event) => {
160-
event.notification.close();
161-
if (event.notification.data) {
162-
const { action, model, res_id } = event.notification.data;
163-
if (model === "discuss.channel") {
164-
if (event.action === PUSH_NOTIFICATION_ACTION.DECLINE) {
165-
event.waitUntil(
166-
fetch("/mail/rtc/channel/leave_call", {
167-
headers: { "Content-type": "application/json" },
168-
body: JSON.stringify({
169-
id: 1,
170-
jsonrpc: "2.0",
171-
method: "call",
172-
params: { channel_id: res_id },
173-
}),
174-
method: "POST",
175-
mode: "cors",
176-
credentials: "include",
177-
})
178-
);
179-
return;
180-
}
159+
async function handleNotificationClick(event) {
160+
const { action, model, res_id } = event.notification.data;
161+
if (model === "discuss.channel") {
162+
if (event.action === PUSH_NOTIFICATION_ACTION.DECLINE) {
181163
event.waitUntil(
182-
openDiscussChannel(res_id, {
183-
action,
184-
joinCall: event.action === PUSH_NOTIFICATION_ACTION.ACCEPT,
164+
fetch("/mail/rtc/channel/leave_call", {
165+
headers: { "Content-type": "application/json" },
166+
body: JSON.stringify({
167+
id: 1,
168+
jsonrpc: "2.0",
169+
method: "call",
170+
params: { channel_id: res_id },
171+
}),
172+
method: "POST",
173+
mode: "cors",
174+
credentials: "include",
185175
})
186176
);
187-
} else {
188-
const modelPath = model.includes(".") ? model : `m-${model}`;
189-
event.waitUntil(clients.openWindow(`/odoo/${modelPath}/${res_id}`));
177+
return;
190178
}
179+
return openDiscussChannel(res_id, {
180+
action,
181+
joinCall: event.action === PUSH_NOTIFICATION_ACTION.ACCEPT,
182+
});
183+
} else {
184+
const modelPath = model.includes(".") ? model : `m-${model}`;
185+
return clients.openWindow(`/odoo/${modelPath}/${res_id}`);
186+
}
187+
}
188+
189+
self.addEventListener("notificationclick", async (event) => {
190+
event.notification.close();
191+
if (event.notification.data) {
192+
event.waitUntil(handleNotificationClick(event));
191193
}
192194
});
195+
193196
self.addEventListener("push", async (event) => {
194197
const notification = event.data.json();
195198
switch (notification.options?.data?.type) {

0 commit comments

Comments
 (0)