summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-08-22 00:44:17 +0200
committerlouiz’ <louiz@louiz.org>2016-08-22 00:44:17 +0200
commitd1626c929f1d313c2f0f85b7d8b756a8d488d1dc (patch)
treec3f4e4c18fbd69cf119d09e51f9c43b9da932b87 /src
parent593b3268273cac2fa58257ee8e51ce1a6de30872 (diff)
downloadbiboumi-d1626c929f1d313c2f0f85b7d8b756a8d488d1dc.tar.gz
biboumi-d1626c929f1d313c2f0f85b7d8b756a8d488d1dc.tar.bz2
biboumi-d1626c929f1d313c2f0f85b7d8b756a8d488d1dc.tar.xz
biboumi-d1626c929f1d313c2f0f85b7d8b756a8d488d1dc.zip
When joining a channel, send the most recent history found in the database
Diffstat (limited to 'src')
-rw-r--r--src/bridge/bridge.cpp20
-rw-r--r--src/bridge/bridge.hpp5
-rw-r--r--src/database/database.cpp9
-rw-r--r--src/database/database.hpp2
-rw-r--r--src/irc/irc_client.cpp4
5 files changed, 39 insertions, 1 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index f69da77..11393d4 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -744,6 +744,26 @@ void Bridge::send_topic(const std::string& hostname, const std::string& chan_nam
}
+void Bridge::send_room_history(const std::string& hostname, const std::string& chan_name)
+{
+ for (const auto& resource: this->resources_in_chan[ChannelKey{chan_name, hostname}])
+ this->send_room_history(hostname, chan_name, resource);
+}
+
+void Bridge::send_room_history(const std::string& hostname, const std::string& chan_name, const std::string& resource)
+{
+#ifdef USE_DATABASE
+ const auto coptions = Database::get_irc_channel_options_with_server_and_global_default(this->user_jid, hostname, chan_name);
+ const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, coptions.maxHistoryLength.value());
+ for (const auto& line: lines)
+ {
+ const auto seconds = line.date.value().timeStamp();
+ this->xmpp.send_history_message(chan_name + "%" + hostname, line.nick.value(), line.body.value(),
+ this->user_jid + "/" + resource, seconds);
+ }
+#endif
+}
+
std::string Bridge::get_own_nick(const Iid& iid)
{
IrcClient* irc = this->find_irc_client(iid.get_server());
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index 6fdbcc9..c26995f 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -138,6 +138,11 @@ public:
void send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic, const std::string& who);
void send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic, const std::string& who, const std::string& resource);
/**
+ * Send the MUC history to the user
+ */
+ void send_room_history(const std::string& hostname, const std::string& chan_name);
+ void send_room_history(const std::string& hostname, const std::string& chan_name, const std::string& resource);
+ /**
* Send a MUC message from some participant
*/
void send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc);
diff --git a/src/database/database.cpp b/src/database/database.cpp
index fce0f45..48cdea8 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -136,6 +136,15 @@ void Database::store_muc_message(const std::string& owner, const Iid& iid,
line.update();
}
+std::vector<db::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, const int limit)
+{
+ auto res = litesql::select<db::MucLogLine>(*Database::db,
+ db::MucLogLine::Owner == owner &&
+ db::MucLogLine::IrcChanName == chan_name &&
+ db::MucLogLine::IrcServerName == server).orderBy(db::MucLogLine::Date, false).limit(limit).all();
+ return {res.rbegin(), res.rend()};
+}
+
void Database::close()
{
Database::db.reset(nullptr);
diff --git a/src/database/database.hpp b/src/database/database.hpp
index d1be2fd..14012ff 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -48,6 +48,8 @@ public:
static db::IrcChannelOptions get_irc_channel_options_with_server_and_global_default(const std::string& owner,
const std::string& server,
const std::string& channel);
+ static std::vector<db::MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ const int limit);
static void store_muc_message(const std::string& owner, const Iid& iid,
time_point date, const std::string& body, const std::string& nick);
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 4cd437d..59da97e 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -755,7 +755,9 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message)
const std::string chan_name = utils::tolower(message.arguments[1]);
IrcChannel* channel = this->get_channel(chan_name);
channel->joined = true;
- this->bridge.send_user_join(this->hostname, chan_name, channel->get_self(), channel->get_self()->get_most_significant_mode(this->sorted_user_modes), true);
+ this->bridge.send_user_join(this->hostname, chan_name, channel->get_self(),
+ channel->get_self()->get_most_significant_mode(this->sorted_user_modes), true);
+ this->bridge.send_room_history(this->hostname, chan_name);
this->bridge.send_topic(this->hostname, chan_name, channel->topic, channel->topic_author);
}