Commit 4c8fb9a0 authored by louiz’'s avatar louiz’

Forward IRC invites to XMPP

parent 5406de35
......@@ -798,6 +798,12 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string&
this->xmpp.send_ping_request(utils::tolower(nick) + "%" + utils::empty_if_fixed_server(hostname), this->user_jid + "/" + *resources.begin(), utils::revstr(id));
}
void Bridge::send_xmpp_invitation(const Iid& iid, const std::string& author)
{
for (const auto& resource: this->resources_in_server[iid.get_server()])
this->xmpp.send_invitation(std::to_string(iid), this->user_jid + "/" + resource, author);
}
void Bridge::set_preferred_from_jid(const std::string& nick, const std::string& full_jid)
{
auto it = this->preferred_user_from.find(nick);
......
......@@ -175,6 +175,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);
/**
* Misc
*/
......
......@@ -75,6 +75,7 @@ static const std::unordered_map<std::string,
{"PING", {&IrcClient::send_pong_command, {1, 0}}},
{"PONG", {&IrcClient::on_pong, {0, 0}}},
{"KICK", {&IrcClient::on_kick, {3, 0}}},
{"INVITE", {&IrcClient::on_invite, {2, 0}}},
{"401", {&IrcClient::on_generic_error, {2, 0}}},
{"402", {&IrcClient::on_generic_error, {2, 0}}},
......@@ -971,6 +972,17 @@ void IrcClient::on_kick(const IrcMessage& message)
this->bridge.kick_muc_user(std::move(iid), target, reason, author.nick);
}
void IrcClient::on_invite(const IrcMessage& message)
{
const std::string& author = message.arguments[0];
Iid iid;
iid.set_local(message.arguments[1]);
iid.set_server(this->hostname);
iid.type = Iid::Type::Channel;
this->bridge.send_xmpp_invitation(iid, author);
}
void IrcClient::on_mode(const IrcMessage& message)
{
const std::string target = message.arguments[0];
......
......@@ -249,6 +249,7 @@ public:
void on_welcome_message(const IrcMessage& message);
void on_part(const IrcMessage& message);
void on_error(const IrcMessage& message);
void on_invite(const IrcMessage& message);
void on_nick(const IrcMessage& message);
void on_kick(const IrcMessage& message);
void on_mode(const IrcMessage& message);
......
......@@ -645,3 +645,19 @@ void BiboumiComponent::send_iq_room_list_result(const std::string& id,
iq.add_child(std::move(query));
this->send_stanza(iq);
}
void BiboumiComponent::send_invitation(const std::string& room_target,
const std::string& jid_to,
const std::string& author_nick)
{
Stanza message("message");
message["from"] = room_target + "@" + this->served_hostname;
message["to"] = jid_to;
XmlNode x("x");
x["xmlns"] = MUC_USER_NS;
XmlNode invite("invite");
invite["from"] = room_target + "@" + this->served_hostname + "/" + author_nick;
x.add_child(std::move(invite));
message.add_child(std::move(x));
this->send_stanza(message);
}
......@@ -74,6 +74,7 @@ public:
void send_iq_room_list_result(const std::string& id, const std::string& to_jid,
const std::string& from,
const std::vector<ListElement>& rooms_list);
void send_invitation(const std::string& room_target, const std::string& jid_to, const std::string& author_nick);
/**
* 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