diff options
author | Kim Alvefur <zash@zash.se> | 2020-11-30 21:12:01 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-11-30 21:12:01 +0100 |
commit | af189d81030a05c4bff49acdd6bd7d0770157c5f (patch) | |
tree | fdb31575660f2a8f260406c6673d4e4aa062659a | |
parent | b96341a58f9bcf8829e34b17d766f55a58c3f82d (diff) | |
download | prosody-af189d81030a05c4bff49acdd6bd7d0770157c5f.tar.gz prosody-af189d81030a05c4bff49acdd6bd7d0770157c5f.zip |
mod_mam: Add support for page flipping
This was easy. Needs tests tho, 100% chance of the logic being
backwards.
-rw-r--r-- | plugins/mod_mam/mod_mam.lua | 11 | ||||
-rw-r--r-- | spec/scansion/mam_extended.scs | 44 |
2 files changed, 52 insertions, 3 deletions
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index cc7b7fba..f252d179 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -147,6 +147,10 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) if qset then module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset); end + -- A reverse query needs to be flipped + local flip = reverse; + -- A flip-page query needs to be the opposite of that. + if query:get_child("flip-page") then flip = not flip end -- Load all the data! local data, err = archive:find(origin.username, { @@ -199,17 +203,19 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) if not first then first = id; end last = id; - if reverse then + if flip then results[count] = fwd_st; else origin.send(fwd_st); end end - if reverse then + if flip then for i = #results, 1, -1 do origin.send(results[i]); end + end + if reverse then first, last = last, first; end @@ -516,7 +522,6 @@ module:hook("message/full", message_handler, 0); local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); -- TODO before-id, after-id -- TODO ids --- TODO page flipping -- TODO archive metadata query -- TODO delete feature flag option diff --git a/spec/scansion/mam_extended.scs b/spec/scansion/mam_extended.scs index 033547dd..7e291510 100644 --- a/spec/scansion/mam_extended.scs +++ b/spec/scansion/mam_extended.scs @@ -76,3 +76,47 @@ Romeo receives: </set> </fin> </iq> + +# Get results in reverse order +Romeo sends: + <iq type="set" id="mamquery2"> + <query xmlns="urn:xmpp:mam:2" queryid="q1"> + <flip-page/> + </query> + </iq> + +Romeo receives: + <message to="${Romeo's full JID}"> + <result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}"> + <forwarded xmlns="urn:xmpp:forward:0"> + <delay stamp="2008-08-22T21:09:04Z" xmlns="urn:xmpp:delay"/> + <message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat02" from="${Romeo's full JID}"> + <body>U there?</body> + </message> + </forwarded> + </result> + </message> + +Romeo receives: + <message to="${Romeo's full JID}"> + <result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}"> + <forwarded xmlns="urn:xmpp:forward:0"> + <delay stamp="2008-08-22T21:09:04Z" xmlns="urn:xmpp:delay"/> + <message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat01" from="${Romeo's full JID}"> + <body>Hello</body> + </message> + </forwarded> + </result> + </message> + +# FIXME unstable tag order from util.rsm +Romeo receives: + <iq type="result" id="mamquery2" to="${Romeo's full JID}"> + <fin xmlns="urn:xmpp:mam:2" complete="true" queryid="q1"> + <set xmlns="http://jabber.org/protocol/rsm" scansion:strict="false"> + <count>2</count> + <first></first> + <last></last> + </set> + </fin> + </iq> |