When joining a channel, send the most recent history found in the database

This commit is contained in:
louiz’
2016-08-22 00:44:17 +02:00
parent 593b326827
commit d1626c929f
7 changed files with 72 additions and 1 deletions
+28
View File
@@ -16,6 +16,9 @@
#include <uuid.h>
#include <cstdlib>
#include <iomanip>
#include <louloulibs.h>
#ifdef SYSTEMD_FOUND
# include <systemd/sd-daemon.h>
@@ -426,6 +429,31 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str
this->send_stanza(message);
}
void XmppComponent::send_history_message(const std::string& muc_name, const std::string& nick, const std::string& body_txt, const std::string& jid_to, std::time_t timestamp)
{
Stanza message("message");
message["to"] = jid_to;
if (!nick.empty())
message["from"] = muc_name + "@" + this->served_hostname + "/" + nick;
else
message["from"] = muc_name + "@" + this->served_hostname;
message["type"] = "groupchat";
XmlNode body("body");
body.set_inner(body_txt);
message.add_child(std::move(body));
XmlNode delay("delay");
delay["xmlns"] = "urn:xmpp:delay";
delay["from"] = muc_name + "@" + this->served_hostname;
std::stringstream date_ss;
date_ss << std::put_time(std::gmtime(&timestamp), "%FT%Tz") << std::endl;
delay["stamp"] = date_ss.str();
message.add_child(std::move(delay));
this->send_stanza(message);
}
void XmppComponent::send_muc_leave(const std::string& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self)
{
Stanza presence("presence");
+5
View File
@@ -134,6 +134,11 @@ public:
* Send a (non-private) message to the MUC
*/
void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to);
/**
* Send a message, with a <delay/> element, part of a MUC history
*/
void send_history_message(const std::string& muc_name, const std::string& nick, const std::string& body,
const std::string& jid_to, const std::time_t timestamp);
/**
* Send an unavailable presence for this nick
*/