Software /
code /
prosody
Annotate
plugins/muc/history.lib.lua @ 6231:bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Mon, 21 Apr 2014 17:51:32 -0400 |
parent | 6215:1dd09dc04945 |
child | 6240:641756a6a5f7 |
rev | line source |
---|---|
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
1 -- Prosody IM |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
4 -- Copyright (C) 2014 Daurnimator |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
5 -- |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
8 -- |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
9 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
10 local gettime = os.time; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
11 local datetime = require "util.datetime"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
12 local st = require "util.stanza"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
13 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
14 local default_history_length, max_history_length = 20, math.huge; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
15 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
16 local function set_max_history_length(_max_history_length) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
17 max_history_length = _max_history_length or math.huge; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
18 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
19 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
20 local function get_historylength(room) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
21 return math.min(room._data.history_length or default_history_length, max_history_length); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
22 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
23 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
24 local function set_historylength(room, length) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
25 length = assert(tonumber(length), "Length not a valid number"); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
26 if length == default_history_length then length = nil; end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
27 room._data.history_length = length; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
28 return true; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
29 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
30 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
31 module:hook("muc-config-form", function(event) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
32 table.insert(event.form, { |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
33 name = "muc#roomconfig_historylength"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
34 type = "text-single"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
35 label = "Maximum Number of History Messages Returned by Room"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
36 value = tostring(get_historylength(event.room)); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
37 }); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
38 end); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
39 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
40 module:hook("muc-config-submitted", function(event) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
41 local new = event.fields["muc#roomconfig_historylength"]; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
42 if new ~= nil and set_historylength(event.room, new) then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
43 event.status_codes["104"] = true; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
44 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
45 end); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
46 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
47 local function parse_history(stanza) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
48 local x_tag = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
49 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc"); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
50 if not history_tag then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
51 return nil, default_history_length, nil; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
52 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
53 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
54 local maxchars = tonumber(history_tag.attr.maxchars); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
55 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
56 local maxstanzas = tonumber(history_tag.attr.maxstanzas); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
57 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
58 -- messages received since the UTC datetime specified |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
59 local since = history_tag.attr.since; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
60 if since then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
61 since = datetime.parse(since); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
62 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
63 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
64 -- messages received in the last "X" seconds. |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
65 local seconds = tonumber(history_tag.attr.seconds); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
66 if seconds then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
67 seconds = gettime() - seconds; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
68 if since then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
69 since = math.max(since, seconds); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
70 else |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
71 since = seconds; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
72 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
73 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
74 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
75 return maxchars, maxstanzas, since; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
76 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
77 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
78 module:hook("muc-get-history", function(event) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
79 local room = event.room; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
80 local history = room._data["history"]; -- send discussion history |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
81 if not history then return nil end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
82 local history_len = #history; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
83 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
84 local to = event.to; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
85 local maxchars = event.maxchars; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
86 local maxstanzas = event.maxstanzas or history_len; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
87 local since = event.since; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
88 local n = 0; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
89 local charcount = 0; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
90 for i=history_len,1,-1 do |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
91 local entry = history[i]; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
92 if maxchars then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
93 if not entry.chars then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
94 entry.stanza.attr.to = ""; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
95 entry.chars = #tostring(entry.stanza); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
96 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
97 charcount = charcount + entry.chars + #to; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
98 if charcount > maxchars then break; end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
99 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
100 if since and since > entry.timestamp then break; end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
101 if n + 1 > maxstanzas then break; end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
102 n = n + 1; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
103 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
104 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
105 local i = history_len-n+1 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
106 function event:next_stanza() |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
107 if i > history_len then return nil end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
108 local entry = history[i]; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
109 local msg = entry.stanza; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
110 msg.attr.to = to; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
111 i = i + 1; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
112 return msg; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
113 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
114 return true; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
115 end); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
116 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
117 local function send_history(room, stanza) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
118 local maxchars, maxstanzas, since = parse_history(stanza); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
119 local event = { |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
120 room = room; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
121 to = stanza.attr.from; -- `to` is required to calculate the character count for `maxchars` |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
122 maxchars = maxchars, maxstanzas = maxstanzas, since = since; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
123 next_stanza = function() end; -- events should define this iterator |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
124 }; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
125 module:fire_event("muc-get-history", event); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
126 for msg in event.next_stanza, event do |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
127 room:route_stanza(msg); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
128 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
129 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
130 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
131 -- Send history on join |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
132 module:hook("muc-occupant-joined", function(event) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
133 send_history(event.room, event.stanza); |
6231
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
134 end, 50); -- Before subject(20) |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
135 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
136 -- add to history |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
137 module:hook("muc-broadcast-message", function(event) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
138 local historic = event.stanza:get_child("body"); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
139 if historic then |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
140 local room = event.room |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
141 local history = room._data["history"]; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
142 if not history then history = {}; room._data["history"] = history; end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
143 local stanza = st.clone(event.stanza); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
144 stanza.attr.to = ""; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
145 local ts = gettime(); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
146 local stamp = datetime.datetime(ts); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
147 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
148 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
149 local entry = { stanza = stanza, timestamp = ts }; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
150 table.insert(history, entry); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
151 while #history > get_historylength(room) do table.remove(history, 1) end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
152 end |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
153 end); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
154 |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
155 return { |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
156 set_max_length = set_max_history_length; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
157 parse_history = parse_history; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
158 send = send_history; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
159 get_length = get_historylength; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
160 set_length = set_historylength; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
161 }; |