Skip to content

Commit

Permalink
Merge pull request #596 from sinisterstuf/join-part-timestamps
Browse files Browse the repository at this point in the history
Add timestamps for enter and leave messages
  • Loading branch information
seratch authored May 18, 2020
2 parents 8ff495d + 115a9a0 commit 9db6a0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,17 @@ class SlackBot extends Adapter
# this event type always has a channel
user.room = channel
@robot.logger.debug "Received enter message for user: #{user.id}, joining: #{channel}"
@receive new EnterMessage user
msg = new EnterMessage user
msg.ts = event.ts
@receive msg

else if event.type is "member_left_channel"
# this event type always has a channel
user.room = channel
@robot.logger.debug "Received leave message for user: #{user.id}, joining: #{channel}"
@receive new LeaveMessage user
msg = new LeaveMessage user
msg.ts = event.ts
@receive msg

else if event.type is "reaction_added" or event.type is "reaction_removed"

Expand Down
14 changes: 12 additions & 2 deletions test/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,23 @@ describe 'Handling incoming messages', ->
return

it 'Should handle member_joined_channel events as envisioned', ->
@slackbot.eventHandler {type: 'member_joined_channel', user: @stubs.user, channel: @stubs.channel.id}
@slackbot.eventHandler
type: 'member_joined_channel'
user: @stubs.user
channel: @stubs.channel.id
ts: @stubs.event_timestamp
should.equal @stubs._received.constructor.name, "EnterMessage"
should.equal @stubs._received.ts, @stubs.event_timestamp
@stubs._received.user.id.should.equal @stubs.user.id

it 'Should handle member_left_channel events as envisioned', ->
@slackbot.eventHandler {type: 'member_left_channel', user: @stubs.user, channel: @stubs.channel.id}
@slackbot.eventHandler
type: 'member_left_channel'
user: @stubs.user
channel: @stubs.channel.id
ts: @stubs.event_timestamp
should.equal @stubs._received.constructor.name, "LeaveMessage"
should.equal @stubs._received.ts, @stubs.event_timestamp
@stubs._received.user.id.should.equal @stubs.user.id

it 'Should handle channel_topic events as envisioned', ->
Expand Down
1 change: 1 addition & 0 deletions test/stubs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ beforeEach ->
name: 'Example Team'
id: 'T123'
@stubs.expired_timestamp = 1528238205453
@stubs.event_timestamp = '1360782804.083113'

# Slack client
@stubs.client =
Expand Down

0 comments on commit 9db6a0c

Please sign in to comment.