diff options
author | louiz’ <louiz@louiz.org> | 2018-06-17 15:16:49 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-06-17 15:16:49 +0200 |
commit | 2f0e26db4cd91037463e5aa45c7538a942a9eee2 (patch) | |
tree | a06a8d0876f70fc9dc388fc7c3a81f5e434aeccd | |
parent | 354c738dc3cacd302d6961617fbc69e128572470 (diff) | |
download | biboumi-2f0e26db4cd91037463e5aa45c7538a942a9eee2.tar.gz biboumi-2f0e26db4cd91037463e5aa45c7538a942a9eee2.tar.bz2 biboumi-2f0e26db4cd91037463e5aa45c7538a942a9eee2.tar.xz biboumi-2f0e26db4cd91037463e5aa45c7538a942a9eee2.zip |
Channels’ disco#info includes the number of participants
fix #3311
-rw-r--r-- | src/irc/irc_client.cpp | 14 | ||||
-rw-r--r-- | src/irc/irc_client.hpp | 4 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.cpp | 29 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.hpp | 3 | ||||
-rw-r--r-- | tests/end_to_end/__main__.py | 21 |
5 files changed, 67 insertions, 4 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index d7fa2cd..0f3d43c 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -317,9 +317,21 @@ IrcChannel* IrcClient::get_channel(const std::string& n) } catch (const std::out_of_range& exception) { - this->channels.emplace(name, std::make_unique<IrcChannel>()); + return this->channels.emplace(name, std::make_unique<IrcChannel>()).first->second.get(); + } +} + +const IrcChannel* IrcClient::find_channel(const std::string& n) const +{ + const std::string name = utils::tolower(n); + try + { return this->channels.at(name).get(); } + catch (const std::out_of_range& exception) + { + return nullptr; + } } bool IrcClient::is_channel_joined(const std::string& name) diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index fd97fe6..70046be 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -68,6 +68,10 @@ public: */ IrcChannel* get_channel(const std::string& name); /** + * Return the channel with this name. Nullptr if it is not found + */ + const IrcChannel* find_channel(const std::string& name) const; + /** * Returns true if the channel is joined */ bool is_channel_joined(const std::string& name); diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index be34873..852b13f 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -514,7 +514,11 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) { if (node.empty()) { - this->send_irc_channel_disco_info(id, from, to_str); + const IrcClient* irc_client = bridge->find_irc_client(iid.get_server()); + const IrcChannel* irc_channel{}; + if (irc_client) + irc_channel = irc_client->find_channel(iid.get_local()); + this->send_irc_channel_disco_info(id, from, to_str, irc_channel); stanza_error.disable(); } else if (node == MUC_TRAFFIC_NS) @@ -964,7 +968,8 @@ void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string& id, this->send_stanza(iq); } -void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from) +void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, + const std::string& jid_from, const IrcChannel* irc_channel) { Jid from(jid_from); Iid iid(from.local, {}); @@ -985,6 +990,26 @@ void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const XmlSubNode feature(query, "feature"); feature["var"] = ns; } + + XmlSubNode x(query, "x"); + x["xmlns"] = DATAFORM_NS; + x["type"] = "result"; + { + XmlSubNode field(x, "field"); + field["var"] = "FORM_TYPE"; + field["type"] = "hidden"; + XmlSubNode value(field, "value"); + value.set_inner("http://jabber.org/protocol/muc#roominfo"); + } + + if (irc_channel && irc_channel->joined) + { + XmlSubNode field(x, "field"); + field["var"] = "muc#roominfo_occupants"; + field["label"] = "Number of occupants"; + XmlSubNode value(field, "value"); + value.set_inner(std::to_string(irc_channel->get_users().size())); + } } this->send_stanza(iq); } diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp index caf990e..f59ed9b 100644 --- a/src/xmpp/biboumi_component.hpp +++ b/src/xmpp/biboumi_component.hpp @@ -73,7 +73,8 @@ public: * http://xmpp.org/extensions/xep-0045.html#impl-service-traffic */ void send_irc_channel_muc_traffic_info(const std::string& id, const std::string& jid_to, const std::string& jid_from); - void send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from); + void send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from, + const IrcChannel* irc_channel); /** * Send a ping request */ diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index a9909f5..5611e8d 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -2693,6 +2693,27 @@ if __name__ == '__main__': "/iq/disco_info:query/disco_info:feature[@var='urn:xmpp:ping']", "/iq/disco_info:query/disco_info:feature[@var='urn:xmpp:mam:2']", "/iq/disco_info:query/disco_info:feature[@var='jabber:iq:version']", + "!/iq/disco_info:query/dataform:x/dataform:field[@var='muc#roominfo_occupants']" + )), + + # Join the channel, and re-do the same query + partial(send_stanza, + "<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + "/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + partial(send_stanza, + "<iq from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' id='2' type='get'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>"), + partial(expect_stanza, + ("/iq[@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}'][@type='result']/disco_info:query", + "/iq/disco_info:query/dataform:x/dataform:field[@var='muc#roominfo_occupants']/dataform:value[text()='1']", + "/iq/disco_info:query/dataform:x/dataform:field[@var='FORM_TYPE'][@type='hidden']/dataform:value[text()='http://jabber.org/protocol/muc#roominfo']" )), ]), Scenario("fixed_muc_disco_info", |