summaryrefslogtreecommitdiff
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/xmpp_component.cpp38
-rw-r--r--src/xmpp/xmpp_component.hpp4
-rw-r--r--src/xmpp/xmpp_stanza.cpp2
3 files changed, 42 insertions, 2 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp
index cd9cd6f..83091ba 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -149,8 +149,22 @@ void XmppComponent::handle_presence(const Stanza& stanza)
Bridge* bridge = this->get_user_bridge(stanza["from"]);
Jid to(stanza["to"]);
Iid iid(to.local);
- if (!iid.chan.empty() && !iid.server.empty())
- bridge->join_irc_channel(iid, to.resource);
+ std::string type;
+ try {
+ type = stanza["type"];
+ }
+ catch (const AttributeNotFound&) {}
+
+ if (!iid.chan.empty() && !iid.chan.empty())
+ { // presence toward a MUC that corresponds to an irc channel
+ if (type.empty())
+ bridge->join_irc_channel(iid, to.resource);
+ else if (type == "unavailable")
+ {
+ XmlNode* status = stanza.get_child("status");
+ bridge->leave_irc_channel(std::move(iid), status ? std::move(status->get_inner()) : "");
+ }
+ }
}
void XmppComponent::handle_message(const Stanza& stanza)
@@ -269,3 +283,23 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str
message.close();
this->send_stanza(message);
}
+
+void XmppComponent::send_muc_leave(std::string&& muc_name, std::string&& nick, std::string&& message, const std::string& jid_to, const bool self)
+{
+ Stanza presence("presence");
+ presence["to"] = jid_to;
+ presence["from"] = muc_name + "@" + this->served_hostname + "/" + nick;
+ presence["type"] = "unavailable";
+ if (!message.empty() || self)
+ {
+ XmlNode status("status");
+ if (!message.empty())
+ status.set_inner(std::move(message));
+ if (self)
+ status["code"] = "110";
+ status.close();
+ presence.add_child(std::move(status));
+ }
+ presence.close();
+ this->send_stanza(presence);
+}
diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp
index 73eadd2..a5127a9 100644
--- a/src/xmpp/xmpp_component.hpp
+++ b/src/xmpp/xmpp_component.hpp
@@ -76,6 +76,10 @@ public:
*/
void send_muc_message(const std::string& muc_name, const std::string& nick, const std::string body_str, const std::string& jid_to);
/**
+ * Send an unavailable presence for this nick
+ */
+ void send_muc_leave(std::string&& muc_name, std::string&& nick, std::string&& message, const std::string& jid_to, const bool self);
+ /**
* Handle the various stanza types
*/
void handle_handshake(const Stanza& stanza);
diff --git a/src/xmpp/xmpp_stanza.cpp b/src/xmpp/xmpp_stanza.cpp
index d856836..ab26304 100644
--- a/src/xmpp/xmpp_stanza.cpp
+++ b/src/xmpp/xmpp_stanza.cpp
@@ -1,5 +1,7 @@
#include <xmpp/xmpp_stanza.hpp>
+#include <utils/encoding.hpp>
+
#include <iostream>
std::string xml_escape(const std::string& data)