Skip to content

Commit

Permalink
Merge pull request #406 from aoberoi/datastore-failed-user-lookups
Browse files Browse the repository at this point in the history
deals with failed user lookups from the dataStore
  • Loading branch information
aoberoi authored Mar 30, 2017
2 parents bc81f0e + b6ea7b1 commit d2be937
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class SlackBot extends Adapter
message: (message) =>
{text, user, channel, subtype, topic, bot} = message

return if user && (user.id == @self.id) #Ignore anything we sent
return if bot && (bot.id == @self.bot_id) #Ignore anything we sent
return if user && (user.id == @self.id) # Ignore anything we sent, or anything from an unknown user
return if bot && (bot.id == @self.bot_id) # Ignore anything we sent, or anything from an unknown bot

subtype = subtype || 'message'

Expand Down Expand Up @@ -202,8 +202,10 @@ class SlackBot extends Adapter
return if (user == @self.id) || (user == @self.bot_id) #Ignore anything we sent

user = @client.rtm.dataStore.getUserById(user)
user.room = item.channel
item_user = @client.rtm.dataStore.getUserById(item_user)
return unless user && item_user

user.room = item.channel
@receive new ReactionMessage(type, user, reaction, item_user, item, event_ts)

loadUsers: (err, res) =>
Expand Down
15 changes: 15 additions & 0 deletions test/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ describe 'Handling incoming messages', ->
@slackbot.reaction reactionMessage
should.equal @stubs._received, undefined

it 'Should ignore reaction events from users who are not in the dataStore', ->
reactionMessage = { type: 'reaction_added', user: @stubs.org_user_not_in_workspace, reaction: 'thumbsup', event_ts: '1360782804.083113' }
@slackbot.reaction reactionMessage
should.equal @stubs._received, undefined

it 'Should ignore reaction events whose item user is not in the dataStore', ->
reactionMessage = {
type: 'reaction_added', user: @stubs.user.id, item_user: @stubs.org_user_not_in_workspace
item: { type: 'message', channel: @stubs.channel.id, ts: '1360782804.083113'
},
reaction: 'thumbsup', event_ts: '1360782804.083113'
}
@slackbot.reaction reactionMessage
should.equal @stubs._received, undefined

describe 'Robot.react', ->
before ->
user = { id: @stubs.user.id, room: @stubs.channel.id }
Expand Down
5 changes: 5 additions & 0 deletions test/stubs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ beforeEach ->
id: 'B456'
profile:
email: '[email protected]'
@stubs.org_user_not_in_workspace =
name: 'name'
id: 'W123'
profile:
email: '[email protected]'
@stubs.team =
name: 'Example Team'
# Slack client
Expand Down

0 comments on commit d2be937

Please sign in to comment.