1
0
mirror of https://github.com/hyperspacedev/hyperspace synced 2025-01-31 01:29:37 +01:00

Add streamListener to Notifications page & add new notifs (#19)

This commit is contained in:
Marquis Kurt 2019-04-25 16:44:02 -04:00
parent 5cfcf0e306
commit 2c4975f6be

View File

@ -43,6 +43,7 @@ interface INotificationsPageState {
class NotificationsPage extends Component<any, INotificationsPageState> { class NotificationsPage extends Component<any, INotificationsPageState> {
client: Mastodon; client: Mastodon;
streamListener: any;
constructor(props: any) { constructor(props: any) {
super(props); super(props);
@ -72,6 +73,22 @@ class NotificationsPage extends Component<any, INotificationsPageState> {
}) })
} }
componentDidMount() {
this.streamNotifications();
}
streamNotifications() {
this.streamListener = this.client.stream('/streaming/user');
this.streamListener.on('notification', (notif: Notification) => {
let notifications = this.state.notifications;
if (notifications) {
notifications.unshift(notif);
this.setState({ notifications });
}
})
}
toggleDeleteDialog() { toggleDeleteDialog() {
this.setState({ deleteDialogOpen: !this.state.deleteDialogOpen }); this.setState({ deleteDialogOpen: !this.state.deleteDialogOpen });
} }