Software /
code /
prosody
Comparison
plugins/muc/history.lib.lua @ 8794:0e2c1c4d4f78
Merge 0.10 -> trunk
This commit intentionally drops changes from c2b99fa134b3
and 8da11142fabf which are based on older MUC code.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 16 May 2018 23:50:08 +0100 |
parent | 8780:4cab4ee5dfcc |
child | 9034:1c709e3d2e5e |
comparison
equal
deleted
inserted
replaced
8788:7a9b680a79fb | 8794:0e2c1c4d4f78 |
---|---|
29 if length == default_history_length then length = nil; end | 29 if length == default_history_length then length = nil; end |
30 room._data.history_length = length; | 30 room._data.history_length = length; |
31 return true; | 31 return true; |
32 end | 32 end |
33 | 33 |
34 -- Fix for clients who don't support XEP-0045 correctly | |
35 -- Default number of history messages the room returns | |
36 local function get_defaulthistorymessages(room) | |
37 return room._data.default_history_messages or default_history_length; | |
38 end | |
39 local function set_defaulthistorymessages(room, number) | |
40 number = math.min(tonumber(number) or default_history_length, room._data.history_length or default_history_length); | |
41 if number == default_history_length then | |
42 number = nil; | |
43 end | |
44 room._data.default_history_messages = number; | |
45 end | |
46 | |
34 module:hook("muc-config-form", function(event) | 47 module:hook("muc-config-form", function(event) |
35 table.insert(event.form, { | 48 table.insert(event.form, { |
36 name = "muc#roomconfig_historylength"; | 49 name = "muc#roomconfig_historylength"; |
37 type = "text-single"; | 50 type = "text-single"; |
38 label = "Maximum Number of History Messages Returned by Room"; | 51 label = "Maximum Number of History Messages Returned by Room"; |
39 value = tostring(get_historylength(event.room)); | 52 value = tostring(get_historylength(event.room)); |
40 }); | 53 }); |
54 table.insert(event.form, { | |
55 name = 'muc#roomconfig_defaulthistorymessages', | |
56 type = 'text-single', | |
57 label = 'Default Number of History Messages Returned by Room', | |
58 value = tostring(get_defaulthistorymessages(event.room)) | |
59 }); | |
41 end, 100-10); | 60 end, 100-10); |
42 | 61 |
43 module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event) | 62 module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event) |
44 if set_historylength(event.room, event.value) then | 63 if set_historylength(event.room, event.value) then |
64 event.status_codes["104"] = true; | |
65 end | |
66 end); | |
67 | |
68 module:hook("muc-config-submitted/muc#roomconfig_defaulthistorymessages", function(event) | |
69 if set_defaulthistorymessages(event.room, event.value) then | |
45 event.status_codes["104"] = true; | 70 event.status_codes["104"] = true; |
46 end | 71 end |
47 end); | 72 end); |
48 | 73 |
49 local function parse_history(stanza) | 74 local function parse_history(stanza) |
50 local x_tag = stanza:get_child("x", "http://jabber.org/protocol/muc"); | 75 local x_tag = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
51 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc"); | 76 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc"); |
52 if not history_tag then | 77 if not history_tag then |
53 return nil, default_history_length, nil; | 78 return nil, nil, nil; |
54 end | 79 end |
55 | 80 |
56 local maxchars = tonumber(history_tag.attr.maxchars); | 81 local maxchars = tonumber(history_tag.attr.maxchars); |
57 | 82 |
58 local maxstanzas = tonumber(history_tag.attr.maxstanzas); | 83 local maxstanzas = tonumber(history_tag.attr.maxstanzas); |
116 return true; | 141 return true; |
117 end, -1); | 142 end, -1); |
118 | 143 |
119 local function send_history(room, stanza) | 144 local function send_history(room, stanza) |
120 local maxchars, maxstanzas, since = parse_history(stanza); | 145 local maxchars, maxstanzas, since = parse_history(stanza); |
146 if not(maxchars or maxstanzas or since) then | |
147 maxstanzas = get_defaulthistorymessages(room); | |
148 end | |
121 local event = { | 149 local event = { |
122 room = room; | 150 room = room; |
123 stanza = stanza; | 151 stanza = stanza; |
124 to = stanza.attr.from; -- `to` is required to calculate the character count for `maxchars` | 152 to = stanza.attr.from; -- `to` is required to calculate the character count for `maxchars` |
125 maxchars = maxchars, maxstanzas = maxstanzas, since = since; | 153 maxchars = maxchars, |
154 maxstanzas = maxstanzas, | |
155 since = since; | |
126 next_stanza = function() end; -- events should define this iterator | 156 next_stanza = function() end; -- events should define this iterator |
127 }; | 157 }; |
128 module:fire_event("muc-get-history", event); | 158 module:fire_event("muc-get-history", event); |
129 for msg in event.next_stanza, event do | 159 for msg in event.next_stanza, event do |
130 room:route_stanza(msg); | 160 room:route_stanza(msg); |