arnav-t / riot-embedded

Embedded version of Riot
62 stars 19 forks source link

setting up push notifications #23

Open lemonspb opened 4 years ago

lemonspb commented 4 years ago

Hi, is there a simple way to set up push notification through your app?

arnav-t commented 4 years ago

Hello. Are you talking about desktop notifications?

lemonspb commented 4 years ago

yes, the question is rather what event should I listen to for push

arnav-t commented 4 years ago

There aren't any globally visible events you can listen to yet. I can add something in the future to emit events for notifications.

lemonspb commented 4 years ago

here i found a pretty simple solution

sendingPushNotifications = (event) => {

        if (event.event.type === "m.room.message" 
        && event.event.sender !== this.props.userId 
        && document.hidden) {
            addNotification({
                title: `сообщение от ${event.sender.rawDisplayName}`,
                message: `${event.event.content.body}`,
                theme: 'darkblue',
                native: true
            });
        }
    };