Commit f9a6f973 authored by louiz’'s avatar louiz’

Implement the roster presences from IRC servers

parent 368bb828
......@@ -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);
......
......@@ -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
*/
......
......@@ -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)
......
......@@ -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();
......
......@@ -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
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment