Software / code / prosody
Comparison
plugins/muc/history.lib.lua @ 6535:0f940a7ba489
mod_muc: Add muc-add-history event to allow modules to override default history storage
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 06 Jan 2015 19:33:25 +0000 |
| parent | 6277:f2c9c36979b3 |
| child | 6991:84e01dbb739e |
comparison
equal
deleted
inserted
replaced
| 6534:b89406fa076c | 6535:0f940a7ba489 |
|---|---|
| 133 module:hook("muc-occupant-session-new", function(event) | 133 module:hook("muc-occupant-session-new", function(event) |
| 134 send_history(event.room, event.stanza); | 134 send_history(event.room, event.stanza); |
| 135 end, 50); -- Before subject(20) | 135 end, 50); -- Before subject(20) |
| 136 | 136 |
| 137 -- add to history | 137 -- add to history |
| 138 module:hook("muc-broadcast-message", function(event) | 138 module:hook("muc-add-history", function(event) |
| 139 local historic = event.stanza:get_child("body"); | 139 local historic = event.stanza:get_child("body"); |
| 140 if historic then | 140 if historic then |
| 141 local room = event.room | 141 local room = event.room |
| 142 local history = room._data["history"]; | 142 local history = room._data["history"]; |
| 143 if not history then history = {}; room._data["history"] = history; end | 143 if not history then history = {}; room._data["history"] = history; end |
| 149 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | 149 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
| 150 local entry = { stanza = stanza, timestamp = ts }; | 150 local entry = { stanza = stanza, timestamp = ts }; |
| 151 table.insert(history, entry); | 151 table.insert(history, entry); |
| 152 while #history > get_historylength(room) do table.remove(history, 1) end | 152 while #history > get_historylength(room) do table.remove(history, 1) end |
| 153 end | 153 end |
| 154 return true; | |
| 155 end, -1); | |
| 156 | |
| 157 -- Have a single muc-add-history event, so that plugins can mark it | |
| 158 -- as handled without stopping other muc-broadcast-message handlers | |
| 159 module:hook("muc-broadcast-message", function(event) | |
| 160 module:fire_event("muc-add-history", event); | |
| 154 end); | 161 end); |
| 155 | 162 |
| 156 return { | 163 return { |
| 157 set_max_length = set_max_history_length; | 164 set_max_length = set_max_history_length; |
| 158 parse_history = parse_history; | 165 parse_history = parse_history; |