summaryrefslogtreecommitdiff
path: root/src/database/database.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-09-04 21:04:21 +0200
committerlouiz’ <louiz@louiz.org>2016-09-04 22:58:38 +0200
commit3047bd41b212390da8e3a4dbcf351e79879042dd (patch)
tree3efbf79b20133bed649195e43625d3129ae164d0 /src/database/database.cpp
parent1140db3b88bb70cbcab044efa729707bd5a442f6 (diff)
downloadbiboumi-3047bd41b212390da8e3a4dbcf351e79879042dd.tar.gz
biboumi-3047bd41b212390da8e3a4dbcf351e79879042dd.tar.bz2
biboumi-3047bd41b212390da8e3a4dbcf351e79879042dd.tar.xz
biboumi-3047bd41b212390da8e3a4dbcf351e79879042dd.zip
MAM results can be filtered by start and end dates
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r--src/database/database.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index be0da8e..e995d95 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -6,6 +6,7 @@
#include <irc/iid.hpp>
#include <uuid.h>
#include <utils/get_first_non_empty.hpp>
+#include <utils/time.hpp>
using namespace std::string_literals;
@@ -136,14 +137,30 @@ 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, int limit)
+std::vector<db::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ int limit, const std::string& start, const std::string& end)
{
- if (limit == -1)
- limit = 1024;
- const auto& res = litesql::select<db::MucLogLine>(*Database::db,
- db::MucLogLine::Owner == owner &&
- db::MucLogLine::IrcChanName == chan_name &&
- db::MucLogLine::IrcServerName == server).orderBy(db::MucLogLine::Id, false).limit(limit).all();
+ auto request = litesql::select<db::MucLogLine>(*Database::db,
+ db::MucLogLine::Owner == owner &&
+ db::MucLogLine::IrcChanName == chan_name &&
+ db::MucLogLine::IrcServerName == server);
+ request.orderBy(db::MucLogLine::Id, false);
+
+ if (limit >= 0)
+ request.limit(limit);
+ if (!start.empty())
+ {
+ const auto start_time = utils::parse_datetime(start);
+ if (start_time != -1)
+ request.where(db::MucLogLine::Date >= start_time);
+ }
+ if (!end.empty())
+ {
+ const auto end_time = utils::parse_datetime(end);
+ if (end_time != -1)
+ request.where(db::MucLogLine::Date <= end_time);
+ }
+ const auto& res = request.all();
return {res.crbegin(), res.crend()};
}
@@ -152,7 +169,6 @@ void Database::close()
Database::db.reset(nullptr);
}
-
std::string Database::gen_uuid()
{
char uuid_str[37];