summaryrefslogtreecommitdiff
path: root/src/xmpp
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/xmpp
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/xmpp')
-rw-r--r--src/xmpp/biboumi_component.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp
index a49f52e..a2fda60 100644
--- a/src/xmpp/biboumi_component.cpp
+++ b/src/xmpp/biboumi_component.cpp
@@ -550,13 +550,36 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
Iid iid(to.local, {'#', '&'});
if (iid.type == Iid::Type::Channel && to.resource.empty())
{
- const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), -1);
- for (const db::MucLogLine& line: lines)
- {
- const auto queryid = query->get_tag("queryid");
- if (!line.nick.value().empty())
- this->send_archived_message(line, to.full(), from.full(), queryid);
- }
+ std::string start;
+ std::string end;
+ const XmlNode* x = query->get_child("x", DATAFORM_NS);
+ if (x)
+ {
+ const XmlNode* value;
+ const auto fields = x->get_children("field", DATAFORM_NS);
+ for (const auto& field: fields)
+ {
+ if (field->get_tag("var") == "start")
+ {
+ value = field->get_child("value", DATAFORM_NS);
+ if (value)
+ start = value->get_inner();
+ }
+ else if (field->get_tag("var") == "end")
+ {
+ value = field->get_child("value", DATAFORM_NS);
+ if (value)
+ end = value->get_inner();
+ }
+ }
+ }
+ const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), -1, start, end);
+ for (const db::MucLogLine& line: lines)
+ {
+ const auto queryid = query->get_tag("queryid");
+ if (!line.nick.value().empty())
+ this->send_archived_message(line, to.full(), from.full(), queryid);
+ }
this->send_iq_result_full_jid(id, from.full(), to.full());
return true;
}