Software /
code /
prosody
Comparison
plugins/muc/history.lib.lua @ 6991:84e01dbb739e
MUC: Update all config form handlers to take advantage of the new per-option events
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 11 Dec 2015 15:33:58 +0000 |
parent | 6535:0f940a7ba489 |
child | 7086:6cc7c9da29ed |
comparison
equal
deleted
inserted
replaced
6990:f476e2497568 | 6991:84e01dbb739e |
---|---|
21 local function get_historylength(room) | 21 local function get_historylength(room) |
22 return math.min(room._data.history_length or default_history_length, max_history_length); | 22 return math.min(room._data.history_length or default_history_length, max_history_length); |
23 end | 23 end |
24 | 24 |
25 local function set_historylength(room, length) | 25 local function set_historylength(room, length) |
26 length = assert(tonumber(length), "Length not a valid number"); | 26 if length then |
27 length = assert(tonumber(length), "Length not a valid number"); | |
28 end | |
27 if length == default_history_length then length = nil; end | 29 if length == default_history_length then length = nil; end |
28 room._data.history_length = length; | 30 room._data.history_length = length; |
29 return true; | 31 return true; |
30 end | 32 end |
31 | 33 |
36 label = "Maximum Number of History Messages Returned by Room"; | 38 label = "Maximum Number of History Messages Returned by Room"; |
37 value = tostring(get_historylength(event.room)); | 39 value = tostring(get_historylength(event.room)); |
38 }); | 40 }); |
39 end); | 41 end); |
40 | 42 |
41 module:hook("muc-config-submitted", function(event) | 43 module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event) |
42 local new = event.fields["muc#roomconfig_historylength"]; | 44 if set_historylength(event.room, event.value) then |
43 if new ~= nil and set_historylength(event.room, new) then | |
44 event.status_codes["104"] = true; | 45 event.status_codes["104"] = true; |
45 end | 46 end |
46 end); | 47 end); |
47 | 48 |
48 local function parse_history(stanza) | 49 local function parse_history(stanza) |