Created
February 7, 2022 03:45
-
-
Save foxted/172d7a18b9188a2a3d21f975aac452f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async subscribe() { | |
this.error = false; | |
if(!this.isLoggedIn || !this.user) { | |
return ; | |
} | |
const onCallCreateNotificationToken = httpsCallable(this.$functions, ON_CALL_CREATE_NOTIFICATION_TOKEN); | |
const { data } = await onCallCreateNotificationToken(); | |
if(typeof data === 'object') { | |
this.error = true; | |
return; | |
} | |
const client = connect( | |
process.env.STREAM_API_KEY, | |
data, | |
process.env.STREAM_APP_ID | |
); | |
this.feed = client.feed('notifications', this.user.uid); | |
this.feed.get({ limit: 10 }).then((data) => { | |
Object.assign(this.notifications, data); | |
}); | |
this.subscription = await this.feed.subscribe((data) => { | |
if (data.new && data.new.length > 0) { | |
this.feed.get({ limit: 10 }).then((data) => { | |
Object.assign(this.notifications, data); | |
}); | |
} | |
}).then(() => { | |
console.debug('Notification feed subscription successful'); | |
}).catch((error) => { | |
console.error('Notification feed subscription failed', error); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment