diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bridge/bridge.cpp | 10 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 4 | ||||
-rw-r--r-- | src/irc/irc_client.cpp | 2 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.cpp | 18 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.hpp | 3 |
5 files changed, 32 insertions, 5 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 27726e4..33006c3 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1081,6 +1081,16 @@ void Bridge::send_xmpp_invitation(const Iid& iid, const std::string& author) this->xmpp.send_invitation(std::to_string(iid), this->user_jid + "/" + resource, author); } +void Bridge::on_irc_client_connected(const std::string& hostname) +{ + this->xmpp.on_irc_client_connected(hostname, this->user_jid); +} + +void Bridge::on_irc_client_disconnected(const std::string& hostname) +{ + this->xmpp.on_irc_client_disconnected(hostname, this->user_jid); +} + void Bridge::set_preferred_from_jid(const std::string& nick, const std::string& full_jid) { auto it = this->preferred_user_from.find(nick); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 496b439..c10631b 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -201,6 +201,8 @@ public: void send_xmpp_ping_request(const std::string& nick, const std::string& hostname, const std::string& id); void send_xmpp_invitation(const Iid& iid, const std::string& author); + void on_irc_client_connected(const std::string& hostname); + void on_irc_client_disconnected(const std::string& hostname); /** * Misc @@ -301,8 +303,8 @@ private: using ChannelKey = std::tuple<ChannelName, IrcHostname>; public: std::map<ChannelKey, std::set<Resource>> resources_in_chan; -private: std::map<IrcHostname, std::set<Resource>> resources_in_server; +private: /** * Manage which resource is in which channel */ diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 67221c5..46dbdbe 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -297,6 +297,7 @@ void IrcClient::on_connected() #endif this->send_gateway_message("Connected to IRC server"s + (this->use_tls ? " (encrypted)": "") + "."); this->send_pending_data(); + this->bridge.on_irc_client_connected(this->get_hostname()); } void IrcClient::on_connection_close(const std::string& error_msg) @@ -309,6 +310,7 @@ void IrcClient::on_connection_close(const std::string& error_msg) const IrcMessage error{"ERROR", {message}}; this->on_error(error); log_warning(message); + this->bridge.on_irc_client_disconnected(this->get_hostname()); } IrcChannel* IrcClient::get_channel(const std::string& n) diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 91e92aa..71a5f3d 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -84,8 +84,7 @@ void BiboumiComponent::shutdown() for (auto& pair: this->bridges) pair.second->shutdown("Gateway shutdown"); #ifdef USE_DATABASE - const auto full_roster = Database::get_full_roster(); - for (const Database::RosterItem& roster_item: full_roster) + for (const Database::RosterItem& roster_item: Database::get_full_roster()) { this->send_presence_to_contact(roster_item.col<Database::LocalJid>(), roster_item.col<Database::RemoteJid>(), @@ -170,7 +169,7 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) if (type == "subscribe") { // Auto-accept any subscription request for an IRC server this->send_presence_to_contact(to_str, from.bare(), "subscribed", id); - if (iid.type == Iid::Type::None) + if (iid.type == Iid::Type::None || bridge->find_irc_client(iid.get_server())) this->send_presence_to_contact(to_str, from.bare(), ""); this->send_presence_to_contact(to_str, from.bare(), "subscribe"); #ifdef USE_DATABASE @@ -192,7 +191,8 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) else if (type.empty()) { // We just receive a presence from someone (as the result of a probe, // or a directed presence, or a normal presence change) - this->send_presence_to_contact(to_str, from.bare(), ""); + if (iid.type == Iid::Type::None) + this->send_presence_to_contact(to_str, from.bare(), ""); } } else @@ -1023,6 +1023,16 @@ void BiboumiComponent::send_presence_to_contact(const std::string& from, const s this->send_stanza(presence); } +void BiboumiComponent::on_irc_client_connected(const std::string& irc_hostname, const std::string& jid) +{ + this->send_presence_to_contact(irc_hostname + "@" + this->served_hostname, jid, ""); +} + +void BiboumiComponent::on_irc_client_disconnected(const std::string& irc_hostname, const std::string& jid) +{ + this->send_presence_to_contact(irc_hostname + "@" + this->served_hostname, jid, "unavailable"); +} + void BiboumiComponent::after_handshake() { XmppComponent::after_handshake(); diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp index 2d67f8b..e5547f9 100644 --- a/src/xmpp/biboumi_component.hpp +++ b/src/xmpp/biboumi_component.hpp @@ -90,6 +90,9 @@ public: void accept_subscription(const std::string& from, const std::string& to); void ask_subscription(const std::string& from, const std::string& to); void send_presence_to_contact(const std::string& from, const std::string& to, const std::string& type, const std::string& id=""); + void on_irc_client_connected(const std::string& irc_hostname, const std::string& jid); + void on_irc_client_disconnected(const std::string& irc_hostname, const std::string& jid); + /** * Handle the various stanza types */ |