MUC: Include the very last message in serialized form to keep it across eviction...
[prosody.git] / plugins / muc / muc.lib.lua
index 8efa295e31cc241926933422eb1f05f810802f9f..071f1f8b01f05eaf1a90e86233adf20c7052fcd5 100644 (file)
@@ -435,6 +435,12 @@ function room_mt:handle_first_presence(origin, stanza)
                origin = origin;
                jid = real_jid;
        });
+       module:fire_event("muc-room-created", {
+               room = self;
+               creator = dest_occupant;
+               stanza = stanza;
+               origin = origin;
+       });
        return true;
 end
 
@@ -1316,6 +1322,11 @@ function room_mt:freeze(live)
                                frozen[jid] = st.preserialize(presence);
                        end
                end
+               local history = self._history;
+               if history then
+                       frozen._last_message = st.preserialize(history[#history].stanza);
+                       frozen._last_message_at = history[#history].timestamp;
+               end
        end
        return frozen;
 end
@@ -1331,6 +1342,13 @@ function _M.restore_room(frozen)
        local room_jid = frozen._jid;
        local room = _M.new_room(room_jid, frozen._data);
 
+       if frozen._last_message and frozen._last_message_at then
+               room._history = {
+                       { stanza = st.deserialize(frozen._last_message),
+                         timestamp = frozen._last_message_at, },
+               };
+       end
+
        local occupants = {};
        local occupant_sessions = {};
        local room_name, room_host = jid_split(room_jid);