diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-11-22 21:00:32 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-11-28 01:18:26 +0100 |
commit | e6f20d3c0fd4ba8696a4410a366741c9b9f3562d (patch) | |
tree | 0b34e42163fcb2b869e74fa11c4fb18cf5226b89 /src/xmpp/xmpp_component.cpp | |
parent | 31e18e49b699f606a8aeb1f529642a004781e704 (diff) | |
download | biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.gz biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.bz2 biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.tar.xz biboumi-e6f20d3c0fd4ba8696a4410a366741c9b9f3562d.zip |
Implement IRC format to xhtml-im conversion
The generated XML is very verbose because each IRC formatting tag makes us
close a <span/> element and reopen it with the new style applied. However,
this works quite well and is easy to implement.
Diffstat (limited to 'src/xmpp/xmpp_component.cpp')
-rw-r--r-- | src/xmpp/xmpp_component.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 2d891bc..9245fde 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -18,7 +18,7 @@ #define DISCO_NS "http://jabber.org/protocol/disco" #define DISCO_ITEMS_NS DISCO_NS"#items" #define DISCO_INFO_NS DISCO_NS"#info" - +#define XHTMLIM_NS "http://jabber.org/protocol/xhtml-im" XmppComponent::XmppComponent(const std::string& hostname, const std::string& secret): served_hostname(hostname), @@ -257,13 +257,13 @@ Bridge* XmppComponent::get_user_bridge(const std::string& user_jid) } } -void XmppComponent::send_message(const std::string& from, const std::string& body, const std::string& to) +void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, const std::string& to) { XmlNode node("message"); node["to"] = to; node["from"] = from + "@" + this->served_hostname; XmlNode body_node("body"); - body_node.set_inner(body); + body_node.set_inner(std::get<0>(body)); body_node.close(); node.add_child(std::move(body_node)); node.close(); @@ -319,21 +319,21 @@ void XmppComponent::send_self_join(const std::string& from, const std::string& n this->send_stanza(node); } -void XmppComponent::send_topic(const std::string& from, const std::string& topic, const std::string& to) +void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, const std::string& to) { XmlNode message("message"); message["to"] = to; message["from"] = from + "@" + this->served_hostname; message["type"] = "groupchat"; XmlNode subject("subject"); - subject.set_inner(topic); + subject.set_inner(std::get<0>(topic)); subject.close(); message.add_child(std::move(subject)); message.close(); this->send_stanza(message); } -void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, const std::string body_str, const std::string& jid_to) +void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to) { Stanza message("message"); message["to"] = jid_to; @@ -343,24 +343,34 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str message["from"] = muc_name + "@" + this->served_hostname; message["type"] = "groupchat"; XmlNode body("body"); - body.set_inner(body_str); + body.set_inner(std::get<0>(xmpp_body)); body.close(); message.add_child(std::move(body)); + if (std::get<1>(xmpp_body)) + { + XmlNode html("html"); + html["xmlns"] = XHTMLIM_NS; + // Pass the ownership of the pointer to this xmlnode + html.add_child(std::get<1>(xmpp_body).release()); + html.close(); + message.add_child(std::move(html)); + } 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) +void XmppComponent::send_muc_leave(std::string&& muc_name, std::string&& nick, Xmpp::body&& 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) + const std::string message_str = std::get<0>(message); + if (message_str.empty() || self) { XmlNode status("status"); - if (!message.empty()) - status.set_inner(std::move(message)); + if (!message_str.empty()) + status.set_inner(message_str); if (self) status["code"] = "110"; status.close(); |