Software /
code /
prosody
Comparison
plugins/muc/history.lib.lua @ 8779:11b4ae162db7
MUC: Move condition for what gets added to history so that other modules benefit (thanks jcbrand)
This helps mod_muc_mam avoid logging eg chat-state-only messages without
needing to implement similar logic in many places
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 07 May 2018 22:12:22 +0200 |
parent | 8028:adfc7f3b29ce |
child | 8780:4cab4ee5dfcc |
comparison
equal
deleted
inserted
replaced
8778:0364454bdd77 | 8779:11b4ae162db7 |
---|---|
136 send_history(event.room, event.stanza); | 136 send_history(event.room, event.stanza); |
137 end, 50); -- Before subject(20) | 137 end, 50); -- Before subject(20) |
138 | 138 |
139 -- add to history | 139 -- add to history |
140 module:hook("muc-add-history", function(event) | 140 module:hook("muc-add-history", function(event) |
141 local historic = event.stanza:get_child("body"); | 141 local room = event.room |
142 if historic then | 142 local history = room._history; |
143 local room = event.room | 143 if not history then history = {}; room._history = history; end |
144 local history = room._history; | 144 local stanza = st.clone(event.stanza); |
145 if not history then history = {}; room._history = history; end | 145 stanza.attr.to = ""; |
146 local stanza = st.clone(event.stanza); | 146 local ts = gettime(); |
147 stanza.attr.to = ""; | 147 local stamp = datetime.datetime(ts); |
148 local ts = gettime(); | 148 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 |
149 local stamp = datetime.datetime(ts); | 149 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
150 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 | 150 local entry = { stanza = stanza, timestamp = ts }; |
151 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | 151 table.insert(history, entry); |
152 local entry = { stanza = stanza, timestamp = ts }; | 152 while #history > get_historylength(room) do table.remove(history, 1) end |
153 table.insert(history, entry); | |
154 while #history > get_historylength(room) do table.remove(history, 1) end | |
155 end | |
156 return true; | 153 return true; |
157 end, -1); | 154 end, -1); |
158 | 155 |
159 -- Have a single muc-add-history event, so that plugins can mark it | 156 -- Have a single muc-add-history event, so that plugins can mark it |
160 -- as handled without stopping other muc-broadcast-message handlers | 157 -- as handled without stopping other muc-broadcast-message handlers |
161 module:hook("muc-broadcast-message", function(event) | 158 module:hook("muc-broadcast-message", function(event) |
162 module:fire_event("muc-add-history", event); | 159 local historic = event.stanza:get_child("body"); |
160 if historic then | |
161 module:fire_event("muc-add-history", event); | |
162 end | |
163 end); | 163 end); |
164 | 164 |
165 return { | 165 return { |
166 set_max_length = set_max_history_length; | 166 set_max_length = set_max_history_length; |
167 parse_history = parse_history; | 167 parse_history = parse_history; |