From 8238a97f8aac6482b0ffcb0f7682362d1a1ad1d8 Mon Sep 17 00:00:00 2001 From: awang Date: Tue, 17 Jan 2017 15:52:52 -0800 Subject: [PATCH 1/2] The problem is: Lita can not send message to a room. The reason is: Room ID in Lita does not include muc_domain. --- lib/lita/adapters/hipchat.rb | 2 +- lib/lita/adapters/hipchat/connector.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/lita/adapters/hipchat.rb b/lib/lita/adapters/hipchat.rb index 262cd0e..72d3c53 100644 --- a/lib/lita/adapters/hipchat.rb +++ b/lib/lita/adapters/hipchat.rb @@ -52,7 +52,7 @@ def send_messages(target, strings) if target.private_message? connector.message_jid(target.user.id, strings) else - connector.message_muc(target.room, strings) + connector.message_muc(muc_domain, target.room, strings) end end diff --git a/lib/lita/adapters/hipchat/connector.rb b/lib/lita/adapters/hipchat/connector.rb index 4f9a518..3a06450 100644 --- a/lib/lita/adapters/hipchat/connector.rb +++ b/lib/lita/adapters/hipchat/connector.rb @@ -70,7 +70,8 @@ def message_jid(user_jid, strings) end end - def message_muc(room_jid, strings) + def message_muc(muc_domain, room_jid, strings) + room_jid = [room_jid, muc_domain].join('@') muc = mucs[room_jid] strings.each do |s| Lita.logger.debug("Sending message to MUC #{room_jid}: #{s}") From 967cd977c951b1c83e7fe9a48b3cfe92f2cd1192 Mon Sep 17 00:00:00 2001 From: awang Date: Tue, 17 Jan 2017 16:15:37 -0800 Subject: [PATCH 2/2] Fixed unit tests. --- spec/lita/adapters/hipchat/connector_spec.rb | 4 ++-- spec/lita/adapters/hipchat_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lita/adapters/hipchat/connector_spec.rb b/spec/lita/adapters/hipchat/connector_spec.rb index 00baea2..6ce33eb 100644 --- a/spec/lita/adapters/hipchat/connector_spec.rb +++ b/spec/lita/adapters/hipchat/connector_spec.rb @@ -185,10 +185,10 @@ describe "#message_muc" do it "sends the messages to the room" do muc = instance_double("Jabber::MUC::SimpleMUCClient") - allow(subject).to receive(:mucs).and_return("jid" => muc) + allow(subject).to receive(:mucs).and_return("jid@conf.hipchat.com" => muc) expect(muc).to receive(:say).with("foo") expect(muc).to receive(:say).with("bar") - subject.message_muc("jid", ["foo", "bar"]) + subject.message_muc("conf.hipchat.com", "jid", ["foo", "bar"]) end end diff --git a/spec/lita/adapters/hipchat_spec.rb b/spec/lita/adapters/hipchat_spec.rb index 74939e4..1476949 100644 --- a/spec/lita/adapters/hipchat_spec.rb +++ b/spec/lita/adapters/hipchat_spec.rb @@ -154,7 +154,7 @@ describe "#send_messages" do it "sends messages to rooms" do source = instance_double("Lita::Source", room: "room_id", private_message?: false) - expect(subject.connector).to receive(:message_muc).with("room_id", ["Hello!"]) + expect(subject.connector).to receive(:message_muc).with("conf.hipchat.com", "room_id", ["Hello!"]) subject.send_messages(source, ["Hello!"]) end