summaryrefslogtreecommitdiff
path: root/src/database/database.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-02-10 17:36:33 +0100
committerlouiz’ <louiz@louiz.org>2018-02-10 17:47:42 +0100
commit99389eefba1883753c15c6f411fb8543c93f58a1 (patch)
tree5378f59a336f24f0e37eebf570eb965074aebe57 /src/database/database.cpp
parente0d1a0b44add408504e428d6ce4a8a2121ea7a00 (diff)
downloadbiboumi-99389eefba1883753c15c6f411fb8543c93f58a1.tar.gz
biboumi-99389eefba1883753c15c6f411fb8543c93f58a1.tar.bz2
biboumi-99389eefba1883753c15c6f411fb8543c93f58a1.tar.xz
biboumi-99389eefba1883753c15c6f411fb8543c93f58a1.zip
Always return the oldest matching messages from MAM, even if no date is set
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r--src/database/database.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 3622963..c43ace4 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -185,13 +185,36 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne
request << " and " << Database::Date{} << "<=" << end_time;
}
+ if (limit >= 0)
+ request.limit() << limit;
+
+ auto result = request.execute(*Database::db);
+
+ return {result.cbegin(), result.cend()};
+}
+
+std::vector<Database::MucLogLine> Database::get_muc_most_recent_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ int limit, const std::string& start)
+{
+ auto request = Database::muc_log_lines.select();
+ request.where() << Database::Owner{} << "=" << owner << \
+ " and " << Database::IrcChanName{} << "=" << chan_name << \
+ " and " << Database::IrcServerName{} << "=" << server;
+
+ if (!start.empty())
+ {
+ const auto start_time = utils::parse_datetime(start);
+ if (start_time != -1)
+ request << " and " << Database::Date{} << ">=" << start_time;
+ }
+
request.order_by() << Id{} << " DESC ";
if (limit >= 0)
request.limit() << limit;
auto result = request.execute(*Database::db);
-
+
return {result.crbegin(), result.crend()};
}