Mercurial > prosody-hg
comparison plugins/mod_mam/mod_mam.lua @ 11272:44c9cb4094bb
mod_mam: Add support for before-id and after-id fields
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 09 Jan 2021 21:31:45 +0100 |
| parents | eaaa8ca742a7 |
| children | e35e98541ca0 |
comparison
equal
deleted
inserted
replaced
| 11271:41a962b72a6e | 11272:44c9cb4094bb |
|---|---|
| 1 -- Prosody IM | 1 -- Prosody IM |
| 2 -- Copyright (C) 2008-2017 Matthew Wild | 2 -- Copyright (C) 2008-2017 Matthew Wild |
| 3 -- Copyright (C) 2008-2017 Waqas Hussain | 3 -- Copyright (C) 2008-2017 Waqas Hussain |
| 4 -- Copyright (C) 2011-2020 Kim Alvefur | 4 -- Copyright (C) 2011-2021 Kim Alvefur |
| 5 -- | 5 -- |
| 6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
| 7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
| 8 -- | 8 -- |
| 9 -- XEP-0313: Message Archive Management for Prosody | 9 -- XEP-0313: Message Archive Management for Prosody |
| 81 { name = "with"; type = "jid-single"; }; | 81 { name = "with"; type = "jid-single"; }; |
| 82 { name = "start"; type = "text-single" }; | 82 { name = "start"; type = "text-single" }; |
| 83 { name = "end"; type = "text-single"; }; | 83 { name = "end"; type = "text-single"; }; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 if archive.caps and archive.caps.full_id_range then | |
| 87 table.insert(query_form, { name = "before-id"; type = "text-single"; }); | |
| 88 table.insert(query_form, { name = "after-id"; type = "text-single"; }); | |
| 89 end | |
| 90 | |
| 86 -- Serve form | 91 -- Serve form |
| 87 module:hook("iq-get/self/"..xmlns_mam..":query", function(event) | 92 module:hook("iq-get/self/"..xmlns_mam..":query", function(event) |
| 88 local origin, stanza = event.origin, event.stanza; | 93 local origin, stanza = event.origin, event.stanza; |
| 89 get_prefs(origin.username, true); | 94 get_prefs(origin.username, true); |
| 90 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); | 95 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); |
| 100 origin.mam_requested = true; | 105 origin.mam_requested = true; |
| 101 | 106 |
| 102 get_prefs(origin.username, true); | 107 get_prefs(origin.username, true); |
| 103 | 108 |
| 104 -- Search query parameters | 109 -- Search query parameters |
| 105 local qwith, qstart, qend; | 110 local qwith, qstart, qend, qbefore, qafter; |
| 106 local form = query:get_child("x", "jabber:x:data"); | 111 local form = query:get_child("x", "jabber:x:data"); |
| 107 if form then | 112 if form then |
| 108 local form_type, err = get_form_type(form); | 113 local form_type, err = get_form_type(form); |
| 109 if not form_type then | 114 if not form_type then |
| 110 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid dataform: "..err)); | 115 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid dataform: "..err)); |
| 117 if err then | 122 if err then |
| 118 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); | 123 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); |
| 119 return true; | 124 return true; |
| 120 end | 125 end |
| 121 qwith, qstart, qend = form["with"], form["start"], form["end"]; | 126 qwith, qstart, qend = form["with"], form["start"], form["end"]; |
| 127 qbefore, qafter = form["before-id"], form["after-id"]; | |
| 122 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep | 128 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep |
| 123 end | 129 end |
| 124 | 130 |
| 125 if qstart or qend then -- Validate timestamps | 131 if qstart or qend then -- Validate timestamps |
| 126 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)); | 132 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)); |
| 140 | 146 |
| 141 -- RSM stuff | 147 -- RSM stuff |
| 142 local qset = rsm.get(query); | 148 local qset = rsm.get(query); |
| 143 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); | 149 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); |
| 144 local reverse = qset and qset.before or false; | 150 local reverse = qset and qset.before or false; |
| 145 local before, after = qset and qset.before, qset and qset.after; | 151 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; |
| 146 if type(before) ~= "string" then before = nil; end | 152 if type(before) ~= "string" then before = nil; end |
| 147 if qset then | 153 if qset then |
| 148 module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset); | 154 module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset); |
| 149 end | 155 end |
| 150 -- A reverse query needs to be flipped | 156 -- A reverse query needs to be flipped |
| 553 -- Stanzas to local clients | 559 -- Stanzas to local clients |
| 554 module:hook("message/bare", message_handler, 0); | 560 module:hook("message/bare", message_handler, 0); |
| 555 module:hook("message/full", message_handler, 0); | 561 module:hook("message/full", message_handler, 0); |
| 556 | 562 |
| 557 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); | 563 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); |
| 558 -- TODO before-id, after-id | |
| 559 -- TODO ids | 564 -- TODO ids |
| 560 -- TODO delete feature flag option | 565 -- TODO delete feature flag option |
| 561 | 566 |
| 562 module:hook("account-disco-info", function(event) | 567 module:hook("account-disco-info", function(event) |
| 563 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); | 568 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); |
