Skip to content

Commit

Permalink
fix(real-time): try to subscribe only if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-im committed Aug 13, 2021
1 parent 7509e5b commit 8ff1e28
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/lib/real-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,25 @@ export default class SlackRealTime {
}])
})

// This is added because Slack has changed their policies and now you'll need to subscribe for each user
// @see https://api.slack.com/changelog/2017-10-making-rtm-presence-subscription-only
// @ts-expect-error
await this.rtm.start({ batch_presence_aware: 1 })
try {
// This is added because Slack has changed their policies and now you'll need to subscribe for each user
// @see https://api.slack.com/changelog/2017-10-making-rtm-presence-subscription-only
// @ts-expect-error
await this.rtm.start({ batch_presence_aware: 1 })
} catch (error) {
return console.error(error)
}
}

subscribeToPresence = async (users: string[]): Promise<void> => {
const alreadySubscribed = Object.keys(this.userPresence)
await this.rtm.subscribePresence(users.filter(id => !alreadySubscribed.includes(id)))
try {
if (this.rtm.connected) {
const alreadySubscribed = Object.keys(this.userPresence)
await this.rtm.subscribePresence(users.filter(id => !alreadySubscribed.includes(id)))
}
} catch (error) {
return console.error(error)
}
}

async dispose() {
Expand Down

0 comments on commit 8ff1e28

Please sign in to comment.