From 82573a52b36040a78f404a4f9d050041d3dc5049 Mon Sep 17 00:00:00 2001 From: ajaleelp Date: Wed, 20 Jan 2016 12:37:14 +0530 Subject: [PATCH 1/3] Store timestamp of message in Message.extensions --- lib/lita/adapters/slack/message_handler.rb | 1 + lita-slack.gemspec | 2 +- spec/lita/adapters/slack/message_handler_spec.rb | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/lita/adapters/slack/message_handler.rb b/lib/lita/adapters/slack/message_handler.rb index 9737176..d5b6aca 100644 --- a/lib/lita/adapters/slack/message_handler.rb +++ b/lib/lita/adapters/slack/message_handler.rb @@ -115,6 +115,7 @@ def dispatch_message(user) source.private_message! if channel && channel[0] == "D" message = Message.new(robot, body, source) message.command! if source.private_message? + message.extensions['timestamp'] = data['ts'] log.debug("Dispatching message to Lita from #{user.id}.") robot.receive(message) end diff --git a/lita-slack.gemspec b/lita-slack.gemspec index 5cd52cd..e00ee44 100644 --- a/lita-slack.gemspec +++ b/lita-slack.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "eventmachine" spec.add_runtime_dependency "faraday" spec.add_runtime_dependency "faye-websocket", ">= 0.8.0" - spec.add_runtime_dependency "lita", ">= 4.6.0" + spec.add_runtime_dependency "lita", ">= 4.7.0" spec.add_runtime_dependency "multi_json" spec.add_development_dependency "bundler", "~> 1.3" diff --git a/spec/lita/adapters/slack/message_handler_spec.rb b/spec/lita/adapters/slack/message_handler_spec.rb index 2fe7e41..1287de0 100644 --- a/spec/lita/adapters/slack/message_handler_spec.rb +++ b/spec/lita/adapters/slack/message_handler_spec.rb @@ -30,10 +30,11 @@ "type" => "message", "channel" => "C2147483705", "user" => "U023BECGF", - "text" => "Hello" + "text" => "Hello", + "ts" => "1234.5678" } end - let(:message) { instance_double('Lita::Message', command!: false) } + let(:message) { instance_double('Lita::Message', command!: false, extensions: {}) } let(:source) { instance_double('Lita::Source', private_message?: false) } let(:user) { instance_double('Lita::User', id: 'U023BECGF') } @@ -49,8 +50,12 @@ it "dispatches the message to Lita" do expect(robot).to receive(:receive).with(message) + subject.handle + end + it "saves the timestamp in extensions" do subject.handle + expect(message.extensions["timestamp"]).to eq("1234.5678") end context "when the message is a direct message" do From 37a44d037272c213c6f972e80d5ccf444e0e8fda Mon Sep 17 00:00:00 2001 From: ajaleelp Date: Thu, 28 Jan 2016 17:07:50 +0530 Subject: [PATCH 2/3] Add a `slack` hash to extensions to accommodate the timestamp within --- lib/lita/adapters/slack/message_handler.rb | 2 +- spec/lita/adapters/slack/message_handler_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lita/adapters/slack/message_handler.rb b/lib/lita/adapters/slack/message_handler.rb index d5b6aca..d227275 100644 --- a/lib/lita/adapters/slack/message_handler.rb +++ b/lib/lita/adapters/slack/message_handler.rb @@ -115,7 +115,7 @@ def dispatch_message(user) source.private_message! if channel && channel[0] == "D" message = Message.new(robot, body, source) message.command! if source.private_message? - message.extensions['timestamp'] = data['ts'] + message.extensions = { 'slack': { 'timestamp': data['ts'] } } log.debug("Dispatching message to Lita from #{user.id}.") robot.receive(message) end diff --git a/spec/lita/adapters/slack/message_handler_spec.rb b/spec/lita/adapters/slack/message_handler_spec.rb index 1287de0..c66eaee 100644 --- a/spec/lita/adapters/slack/message_handler_spec.rb +++ b/spec/lita/adapters/slack/message_handler_spec.rb @@ -55,7 +55,7 @@ it "saves the timestamp in extensions" do subject.handle - expect(message.extensions["timestamp"]).to eq("1234.5678") + expect(message.extensions["slack"]["timestamp"]).to eq("1234.5678") end context "when the message is a direct message" do From cfba261aac85bc74be777376dc6f3c4bc50b711a Mon Sep 17 00:00:00 2001 From: ajaleelp Date: Thu, 28 Jan 2016 21:11:20 +0530 Subject: [PATCH 3/3] Use symbols as keys, not strings --- lib/lita/adapters/slack/message_handler.rb | 2 +- spec/lita/adapters/slack/message_handler_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lita/adapters/slack/message_handler.rb b/lib/lita/adapters/slack/message_handler.rb index d227275..45997fa 100644 --- a/lib/lita/adapters/slack/message_handler.rb +++ b/lib/lita/adapters/slack/message_handler.rb @@ -115,7 +115,7 @@ def dispatch_message(user) source.private_message! if channel && channel[0] == "D" message = Message.new(robot, body, source) message.command! if source.private_message? - message.extensions = { 'slack': { 'timestamp': data['ts'] } } + message.extensions[:slack] = { timestamp: data["ts"] } log.debug("Dispatching message to Lita from #{user.id}.") robot.receive(message) end diff --git a/spec/lita/adapters/slack/message_handler_spec.rb b/spec/lita/adapters/slack/message_handler_spec.rb index c66eaee..1be64d4 100644 --- a/spec/lita/adapters/slack/message_handler_spec.rb +++ b/spec/lita/adapters/slack/message_handler_spec.rb @@ -55,7 +55,7 @@ it "saves the timestamp in extensions" do subject.handle - expect(message.extensions["slack"]["timestamp"]).to eq("1234.5678") + expect(message.extensions[:slack][:timestamp]).to eq("1234.5678") end context "when the message is a direct message" do