Skip to content

Commit

Permalink
Include the message_id with flowdock_message
Browse files Browse the repository at this point in the history
  • Loading branch information
apanzerj committed Nov 9, 2015
1 parent 9e6316e commit 2aae7c8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
cache:
- bundler
language: ruby
rvm:
- 2.2.0
script: bundle exec rake
before_install:
- gem update --system
services:
- redis-server
6 changes: 5 additions & 1 deletion lib/lita/adapters/flowdock/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def tags
data['tags']
end

def thread_id
data['thread_id']
end

def dispatch_message(user)
source = FlowdockSource.new(
user: user,
room: flow,
private_message: private_message?,
message_id: private_message? ? data['id'] : data['thread']['initial_message']
)
message = FlowdockMessage.new(robot, body, source, tags)
message = FlowdockMessage.new(robot, body, source, tags, thread_id)
robot.receive(message)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/lita/message/flowdock_message.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Lita
class FlowdockMessage < Message
attr_reader :tags
def initialize(robot, body, source, tags)
attr_reader :tags, :thread_id
def initialize(robot, body, source, tags, thread_id)
@tags = tags
@thread_id = thread_id
super(robot, body, source)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lita-flowdock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "coveralls"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "bump"
spec.add_development_dependency "pry"
spec.add_development_dependency "pry-byebug"
end
7 changes: 4 additions & 3 deletions spec/lita/adapters/flowdock/message_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
message_id: id
).and_return(source)
allow(Lita::FlowdockMessage).to receive(:new).with(
robot, 'Hello World!', source, []).and_return(message)
robot, 'Hello World!', source, [], nil).and_return(message)
allow(robot).to receive(:receive).with(message)
end

Expand Down Expand Up @@ -81,7 +81,8 @@
robot,
"",
source,
[]
[],
nil
).and_return(message)

subject.handle
Expand Down Expand Up @@ -221,7 +222,7 @@
message_id: parent_id
).and_return(source)
allow(Lita::FlowdockMessage).to receive(:new).with(
robot, 'Lita: help', source, tags).and_return(message)
robot, 'Lita: help', source, tags, nil).and_return(message)
allow(robot).to receive(:receive).with(message)
end

Expand Down
40 changes: 38 additions & 2 deletions spec/lita/message/flowdock_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,42 @@
robot,
body,
source,
tags
tags,
nil
)

message_handler.handle
end
end

context "a message in a thread" do
let(:tags) { ['down'] }
let(:body) { 'the system is #down' }
let(:data) do
{
'content' => {
'title' => 'Thread title',
'text' => body
},
'event' => 'comment',
'flow' => test_flow,
'id' => 2345,
'thread_id' => 'deadbeef',
'thread' => {
'initial_message' => 1234
},
'tags' => tags,
'user' => 3
}
end

it 'stores the message_id on the flowdock_message' do
expect(Lita::FlowdockMessage).to receive(:new).with(
robot,
body,
source,
tags,
'deadbeef'
)

message_handler.handle
Expand Down Expand Up @@ -84,7 +119,8 @@
robot,
body,
source,
tags
tags,
nil
)

message_handler.handle
Expand Down

0 comments on commit 2aae7c8

Please sign in to comment.