You've already forked matrix-react-sdk
							
							
				mirror of
				https://github.com/matrix-org/matrix-react-sdk.git
				synced 2025-11-04 11:51:45 +03:00 
			
		
		
		
	Pass MatrixEvent to displayNotification method (#7355)
This commit is contained in:
		@@ -170,7 +170,36 @@ export default abstract class BasePlatform {
 | 
			
		||||
     */
 | 
			
		||||
    abstract requestNotificationPermission(): Promise<string>;
 | 
			
		||||
 | 
			
		||||
    abstract displayNotification(title: string, msg: string, avatarUrl: string, room: Room);
 | 
			
		||||
    public displayNotification(
 | 
			
		||||
        title: string,
 | 
			
		||||
        msg: string,
 | 
			
		||||
        avatarUrl: string,
 | 
			
		||||
        room: Room,
 | 
			
		||||
        ev?: MatrixEvent,
 | 
			
		||||
    ): Notification {
 | 
			
		||||
        const notifBody = {
 | 
			
		||||
            body: msg,
 | 
			
		||||
            silent: true, // we play our own sounds
 | 
			
		||||
        };
 | 
			
		||||
        if (avatarUrl) notifBody['icon'] = avatarUrl;
 | 
			
		||||
        const notification = new window.Notification(title, notifBody);
 | 
			
		||||
 | 
			
		||||
        notification.onclick = () => {
 | 
			
		||||
            const payload: ActionPayload = {
 | 
			
		||||
                action: Action.ViewRoom,
 | 
			
		||||
                room_id: room.roomId,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            if (ev.getThread()) {
 | 
			
		||||
                payload.event_id = ev.getId();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            dis.dispatch(payload);
 | 
			
		||||
            window.focus();
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        return notification;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    loudNotification(ev: MatrixEvent, room: Room) {
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -122,7 +122,7 @@ export const Notifier = {
 | 
			
		||||
            avatarUrl = Avatar.avatarUrlForMember(ev.sender, 40, 40, 'crop');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const notif = plaf.displayNotification(title, msg, avatarUrl, room);
 | 
			
		||||
        const notif = plaf.displayNotification(title, msg, avatarUrl, room, ev);
 | 
			
		||||
 | 
			
		||||
        // if displayNotification returns non-null,  the platform supports
 | 
			
		||||
        // clearing notifications later, so keep track of this.
 | 
			
		||||
@@ -381,7 +381,7 @@ export const Notifier = {
 | 
			
		||||
    _evaluateEvent: function(ev: MatrixEvent) {
 | 
			
		||||
        const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
 | 
			
		||||
        const actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
 | 
			
		||||
        if (actions && actions.notify) {
 | 
			
		||||
        if (actions?.notify) {
 | 
			
		||||
            if (RoomViewStore.getRoomId() === room.roomId &&
 | 
			
		||||
                UserActivity.sharedInstance().userActiveRecently() &&
 | 
			
		||||
                !Modal.hasDialogs()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user