Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 53081f5

Browse files
author
Germain
authored
Pass MatrixEvent to displayNotification method (#7355)
1 parent 42b14bf commit 53081f5

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/BasePlatform.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,36 @@ export default abstract class BasePlatform {
170170
*/
171171
abstract requestNotificationPermission(): Promise<string>;
172172

173-
abstract displayNotification(title: string, msg: string, avatarUrl: string, room: Room);
173+
public displayNotification(
174+
title: string,
175+
msg: string,
176+
avatarUrl: string,
177+
room: Room,
178+
ev?: MatrixEvent,
179+
): Notification {
180+
const notifBody = {
181+
body: msg,
182+
silent: true, // we play our own sounds
183+
};
184+
if (avatarUrl) notifBody['icon'] = avatarUrl;
185+
const notification = new window.Notification(title, notifBody);
186+
187+
notification.onclick = () => {
188+
const payload: ActionPayload = {
189+
action: Action.ViewRoom,
190+
room_id: room.roomId,
191+
};
192+
193+
if (ev.getThread()) {
194+
payload.event_id = ev.getId();
195+
}
196+
197+
dis.dispatch(payload);
198+
window.focus();
199+
};
200+
201+
return notification;
202+
}
174203

175204
loudNotification(ev: MatrixEvent, room: Room) {
176205
}

src/Notifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const Notifier = {
122122
avatarUrl = Avatar.avatarUrlForMember(ev.sender, 40, 40, 'crop');
123123
}
124124

125-
const notif = plaf.displayNotification(title, msg, avatarUrl, room);
125+
const notif = plaf.displayNotification(title, msg, avatarUrl, room, ev);
126126

127127
// if displayNotification returns non-null, the platform supports
128128
// clearing notifications later, so keep track of this.
@@ -381,7 +381,7 @@ export const Notifier = {
381381
_evaluateEvent: function(ev: MatrixEvent) {
382382
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
383383
const actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
384-
if (actions && actions.notify) {
384+
if (actions?.notify) {
385385
if (RoomViewStore.getRoomId() === room.roomId &&
386386
UserActivity.sharedInstance().userActiveRecently() &&
387387
!Modal.hasDialogs()

0 commit comments

Comments
 (0)