Support the <before/> element in MAM requests
This commit is contained in:
@@ -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,
|
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, const Id::real_type after_id, Database::Paging paging)
|
int limit, const std::string& start, const std::string& end, const Id::real_type reference_record_id, Database::Paging paging)
|
||||||
{
|
{
|
||||||
if (limit == 0)
|
if (limit == 0)
|
||||||
return {};
|
return {};
|
||||||
@@ -187,15 +187,21 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne
|
|||||||
if (end_time != -1)
|
if (end_time != -1)
|
||||||
request << " and " << Database::Date{} << "<=" << end_time;
|
request << " and " << Database::Date{} << "<=" << end_time;
|
||||||
}
|
}
|
||||||
if (after_id != Id::unset_value)
|
if (reference_record_id != Id::unset_value)
|
||||||
{
|
{
|
||||||
request << " and " << Id{} << ">" << after_id;
|
request << " and " << Id{};
|
||||||
|
if (paging == Database::Paging::first)
|
||||||
|
request << ">";
|
||||||
|
else
|
||||||
|
request << "<";
|
||||||
|
request << reference_record_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.order_by() << Id{};
|
||||||
if (paging == Database::Paging::first)
|
if (paging == Database::Paging::first)
|
||||||
request.order_by() << Id{} << " ASC ";
|
request << " ASC ";
|
||||||
else
|
else
|
||||||
request.order_by() << Id{} << " DESC ";
|
request << " DESC ";
|
||||||
|
|
||||||
if (limit >= 0)
|
if (limit >= 0)
|
||||||
request.limit() << limit;
|
request.limit() << limit;
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Database
|
|||||||
*/
|
*/
|
||||||
static std::vector<MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
|
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, Paging=Paging::first);
|
const Id::real_type reference_record_id=Id::unset_value, Paging=Paging::first);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get just one single record matching the given uuid, between (optional) end and start.
|
* Get just one single record matching the given uuid, between (optional) end and start.
|
||||||
|
|||||||
@@ -720,7 +720,8 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
|
|||||||
}
|
}
|
||||||
const XmlNode* set = query->get_child("set", RSM_NS);
|
const XmlNode* set = query->get_child("set", RSM_NS);
|
||||||
int limit = -1;
|
int limit = -1;
|
||||||
Id::real_type after_id{Id::unset_value};
|
Id::real_type reference_record_id{Id::unset_value};
|
||||||
|
Database::Paging paging_order{Database::Paging::first};
|
||||||
if (set)
|
if (set)
|
||||||
{
|
{
|
||||||
const XmlNode* max = set->get_child("max", RSM_NS);
|
const XmlNode* max = set->get_child("max", RSM_NS);
|
||||||
@@ -731,7 +732,17 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
|
|||||||
{
|
{
|
||||||
auto after_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(),
|
auto after_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(),
|
||||||
after->get_inner(), start, end);
|
after->get_inner(), start, end);
|
||||||
after_id = after_record.col<Id>();
|
reference_record_id = after_record.col<Id>();
|
||||||
|
}
|
||||||
|
const XmlNode* before = set->get_child("before", RSM_NS);
|
||||||
|
if (before)
|
||||||
|
{
|
||||||
|
paging_order = Database::Paging::last;
|
||||||
|
if (!before->get_inner().empty())
|
||||||
|
{
|
||||||
|
auto before_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), before->get_inner(), start, end);
|
||||||
|
reference_record_id = before_record.col<Id>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do not send more than 100 messages, even if the client asked for more,
|
// Do not send more than 100 messages, even if the client asked for more,
|
||||||
@@ -742,7 +753,7 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
|
|||||||
if ((limit == -1 && start.empty() && end.empty())
|
if ((limit == -1 && start.empty() && end.empty())
|
||||||
|| limit > 100)
|
|| limit > 100)
|
||||||
limit = 101;
|
limit = 101;
|
||||||
auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end, after_id);
|
auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end, reference_record_id, paging_order);
|
||||||
bool complete = true;
|
bool complete = true;
|
||||||
if (lines.size() > 100)
|
if (lines.size() > 100)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2190,7 +2190,48 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Send a request with a non-existing ID set as the “after” value.
|
# Send a request with a non-existing ID set as the “after” value.
|
||||||
partial(send_stanza, "<iq to='#foo%{irc_server_one}' from='{jid_one}/{resource_one}' type='set' id='id3'><query xmlns='urn:xmpp:mam:2' queryid='qid3' ><set xmlns='http://jabber.org/protocol/rsm'><after>DUMMY_ID</after></set></query></iq>"),
|
partial(send_stanza, "<iq to='#foo%{irc_server_one}' from='{jid_one}/{resource_one}' type='set' id='id3'><query xmlns='urn:xmpp:mam:2' queryid='qid3' ><set xmlns='http://jabber.org/protocol/rsm'><after>DUMMY_ID</after></set></query></iq>"),
|
||||||
partial(expect_stanza, "/iq[@id='id3'][@type='error']/error[@type='cancel']/stanza:feature-not-implemented")
|
partial(expect_stanza, "/iq[@id='id3'][@type='error']/error[@type='cancel']/stanza:item-not-found"),
|
||||||
|
|
||||||
|
# Request the last page just BEFORE the last message in the archive
|
||||||
|
partial(send_stanza, "<iq to='#foo%{irc_server_one}' from='{jid_one}/{resource_one}' type='set' id='id3'><query xmlns='urn:xmpp:mam:2' queryid='qid3' ><set xmlns='http://jabber.org/protocol/rsm'><before></before></set></query></iq>"),
|
||||||
|
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
|
||||||
|
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='50']")
|
||||||
|
),
|
||||||
|
] + 98 * [
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
|
||||||
|
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body")
|
||||||
|
),
|
||||||
|
] + [
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/message/mam:result[@queryid='qid3']/forward:forwarded/delay:delay",
|
||||||
|
"/message/mam:result[@queryid='qid3']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='149']"),
|
||||||
|
after = partial(save_value, "last_uuid", partial(extract_attribute, "/message/mam:result", "id"))
|
||||||
|
),
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/iq[@type='result'][@id='id3'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
|
||||||
|
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
|
||||||
|
"!/iq//mam:fin[@complete='true']",
|
||||||
|
"/iq//mam:fin")),
|
||||||
|
|
||||||
|
# Do the same thing, but with a limit value.
|
||||||
|
partial(send_stanza, "<iq to='#foo%{irc_server_one}' from='{jid_one}/{resource_one}' type='set' id='id4'><query xmlns='urn:xmpp:mam:2' queryid='qid4' ><set xmlns='http://jabber.org/protocol/rsm'><before>{last_uuid}</before><max>2</max></set></query></iq>"),
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/message/mam:result[@queryid='qid4']/forward:forwarded/delay:delay",
|
||||||
|
"/message/mam:result[@queryid='qid4']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='147']")
|
||||||
|
),
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/message/mam:result[@queryid='qid4']/forward:forwarded/delay:delay",
|
||||||
|
"/message/mam:result[@queryid='qid4']/forward:forwarded/client:message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/client:body[text()='148']"),
|
||||||
|
after = partial(save_value, "last_uuid", partial(extract_attribute, "/message/mam:result", "id"))
|
||||||
|
),
|
||||||
|
partial(expect_stanza,
|
||||||
|
("/iq[@type='result'][@id='id4'][@from='#foo%{irc_server_one}'][@to='{jid_one}/{resource_one}']",
|
||||||
|
"/iq/mam:fin/rsm:set/rsm:last[text()='{last_uuid}']",
|
||||||
|
"/iq/mam:fin[@complete='true']",
|
||||||
|
"/iq/mam:fin")),
|
||||||
]),
|
]),
|
||||||
Scenario("channel_history_on_fixed_server",
|
Scenario("channel_history_on_fixed_server",
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user