summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-02-10 19:51:59 +0100
committerlouiz’ <louiz@louiz.org>2018-02-10 19:51:59 +0100
commit0280343ced6c520700c3ca508e2d04c6b512d319 (patch)
treec495521dbc46dc931acc2f48d23f1aed33d8387f /src/database
parentce1b6583e82cc03130700222e64796bacd704463 (diff)
downloadbiboumi-0280343ced6c520700c3ca508e2d04c6b512d319.tar.gz
biboumi-0280343ced6c520700c3ca508e2d04c6b512d319.tar.bz2
biboumi-0280343ced6c520700c3ca508e2d04c6b512d319.tar.xz
biboumi-0280343ced6c520700c3ca508e2d04c6b512d319.zip
Handle the “after” RSM value to page through results
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp35
-rw-r--r--src/database/database.hpp9
2 files changed, 42 insertions, 2 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index c43ace4..2d6fbbd 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -165,7 +165,7 @@ std::string Database::store_muc_message(const std::string& owner, const std::str
}
std::vector<Database::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)
+ int limit, const std::string& start, const std::string& end, const Id::real_type after_id)
{
auto request = Database::muc_log_lines.select();
request.where() << Database::Owner{} << "=" << owner << \
@@ -184,6 +184,10 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne
if (end_time != -1)
request << " and " << Database::Date{} << "<=" << end_time;
}
+ if (after_id != Id::unset_value)
+ {
+ request << " and " << Id{} << ">" << after_id;
+ }
if (limit >= 0)
request.limit() << limit;
@@ -218,6 +222,35 @@ std::vector<Database::MucLogLine> Database::get_muc_most_recent_logs(const std::
return {result.crbegin(), result.crend()};
}
+Database::MucLogLine Database::get_muc_log(const std::string& owner, const std::string& chan_name, const std::string& server,
+ const std::string& uuid, const std::string& start, const std::string& end)
+{
+ auto request = Database::muc_log_lines.select();
+ request.where() << Database::Owner{} << "=" << owner << \
+ " and " << Database::IrcChanName{} << "=" << chan_name << \
+ " and " << Database::IrcServerName{} << "=" << server << \
+ " and " << Database::Uuid{} << "=" << uuid;
+
+ if (!start.empty())
+ {
+ const auto start_time = utils::parse_datetime(start);
+ if (start_time != -1)
+ request << " and " << Database::Date{} << ">=" << start_time;
+ }
+ if (!end.empty())
+ {
+ const auto end_time = utils::parse_datetime(end);
+ if (end_time != -1)
+ request << " and " << Database::Date{} << "<=" << end_time;
+ }
+
+ auto result = request.execute(*Database::db);
+
+ if (result.empty())
+ throw Database::RecordNotFound{};
+ return result.front();
+}
+
void Database::add_roster_item(const std::string& local, const std::string& remote)
{
auto roster_item = Database::roster.row();
diff --git a/src/database/database.hpp b/src/database/database.hpp
index f9aed2b..810af16 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -120,15 +120,22 @@ class Database
const std::string& channel);
/**
* Get all the lines between (optional) start and end dates, with a (optional) limit.
+ * If after_id is set, only the records after it will be returned.
*/
static std::vector<MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
- int limit=-1, const std::string& start="", const std::string& end="");
+ int limit=-1, const std::string& start="", const std::string& end="",
+ const Id::real_type after_id=Id::unset_value);
/**
* Get the most recent messages from the archive, with optional limit and start date
*/
static std::vector<MucLogLine> get_muc_most_recent_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
int limit=-1, const std::string& start="");
+ /**
+ * Get just one single record matching the given uuid, between (optional) end and start.
+ * If it does not exist (or is not between end and start), throw a RecordNotFound exception.
+ */
+ static MucLogLine get_muc_log(const std::string& owner, const std::string& chan_name, const std::string& server, const std::string& uuid, const std::string& start="", const std::string& end="");
static std::string store_muc_message(const std::string& owner, const std::string& chan_name, const std::string& server_name,
time_point date, const std::string& body, const std::string& nick);