Software /
code /
prosody
Comparison
plugins/muc/history.lib.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 05 Nov 2020 22:31:25 +0100 |
parent | 11180:ab820b2ad199 |
child | 11711:6fbbfa4a1178 |
comparison
equal
deleted
inserted
replaced
11199:6c7c50a4de32 | 11200:bf8f2da84007 |
---|---|
46 | 46 |
47 module:hook("muc-config-form", function(event) | 47 module:hook("muc-config-form", function(event) |
48 table.insert(event.form, { | 48 table.insert(event.form, { |
49 name = "muc#roomconfig_historylength"; | 49 name = "muc#roomconfig_historylength"; |
50 type = "text-single"; | 50 type = "text-single"; |
51 datatype = "xs:integer"; | |
51 label = "Maximum number of history messages returned by room"; | 52 label = "Maximum number of history messages returned by room"; |
52 desc = "Specify the maximum number of previous messages that should be sent to users when they join the room"; | 53 desc = "Specify the maximum number of previous messages that should be sent to users when they join the room"; |
53 value = tostring(get_historylength(event.room)); | 54 value = get_historylength(event.room); |
54 }); | 55 }); |
55 table.insert(event.form, { | 56 table.insert(event.form, { |
56 name = 'muc#roomconfig_defaulthistorymessages', | 57 name = 'muc#roomconfig_defaulthistorymessages', |
57 type = 'text-single', | 58 type = 'text-single', |
59 datatype = "xs:integer"; | |
58 label = 'Default number of history messages returned by room', | 60 label = 'Default number of history messages returned by room', |
59 desc = "Specify the number of previous messages sent to new users when they join the room"; | 61 desc = "Specify the number of previous messages sent to new users when they join the room"; |
60 value = tostring(get_defaulthistorymessages(event.room)) | 62 value = get_defaulthistorymessages(event.room); |
61 }); | 63 }); |
62 end, 70-5); | 64 end, 70-5); |
63 | 65 |
64 module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event) | 66 module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event) |
65 if set_historylength(event.room, event.value) then | 67 if set_historylength(event.room, event.value) then |
178 local ts = gettime(); | 180 local ts = gettime(); |
179 local stamp = datetime.datetime(ts); | 181 local stamp = datetime.datetime(ts); |
180 stanza:tag("delay", { -- XEP-0203 | 182 stanza:tag("delay", { -- XEP-0203 |
181 xmlns = "urn:xmpp:delay", from = room.jid, stamp = stamp | 183 xmlns = "urn:xmpp:delay", from = room.jid, stamp = stamp |
182 }):up(); | 184 }):up(); |
183 stanza:tag("x", { -- XEP-0091 (deprecated) | |
184 xmlns = "jabber:x:delay", from = room.jid, stamp = datetime.legacy() | |
185 }):up(); | |
186 local entry = { stanza = stanza, timestamp = ts }; | 185 local entry = { stanza = stanza, timestamp = ts }; |
187 table.insert(history, entry); | 186 table.insert(history, entry); |
188 while #history > get_historylength(room) do table.remove(history, 1) end | 187 while #history > get_historylength(room) do table.remove(history, 1) end |
189 return true; | 188 return true; |
190 end, -1); | 189 end, -1); |
196 module:fire_event("muc-add-history", event); | 195 module:fire_event("muc-add-history", event); |
197 end | 196 end |
198 end); | 197 end); |
199 | 198 |
200 module:hook("muc-message-is-historic", function (event) | 199 module:hook("muc-message-is-historic", function (event) |
201 return event.stanza:get_child("body"); | 200 local stanza = event.stanza; |
201 if stanza:get_child("no-store", "urn:xmpp:hints") | |
202 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") then | |
203 -- XXX Experimental XEP | |
204 return false, "hint"; | |
205 end | |
206 if stanza:get_child("store", "urn:xmpp:hints") then | |
207 return true, "hint"; | |
208 end | |
209 if stanza:get_child("body") then | |
210 return true; | |
211 end | |
212 if stanza:get_child("encryption", "urn:xmpp:eme:0") then | |
213 -- Since we can't know what an encrypted message contains, we assume it's important | |
214 -- XXX Experimental XEP | |
215 return true, "encrypted"; | |
216 end | |
217 if stanza:get_child(nil, "urn:xmpp:chat-markers:0") then | |
218 -- XXX Experimental XEP | |
219 return true, "marker"; | |
220 end | |
202 end, -1); | 221 end, -1); |
203 | 222 |
204 return { | 223 return { |
205 set_max_length = set_max_history_length; | 224 set_max_length = set_max_history_length; |
206 parse_history = parse_history; | 225 parse_history = parse_history; |