]> granicus.if.org Git - ejabberd/commitdiff
Write in room log when a room is created, destroyed, started, stopped (EJAB-1144)
authorBadlop <badlop@process-one.net>
Tue, 29 Dec 2009 14:43:24 +0000 (14:43 +0000)
committerBadlop <badlop@process-one.net>
Tue, 29 Dec 2009 14:43:24 +0000 (14:43 +0000)
SVN Revision: 2836

src/mod_muc/mod_muc_log.erl
src/mod_muc/mod_muc_room.erl

index d1942f4bb02fe08d84ba52c8f467af27e04e4e31..4b644a631737a82b322f59547ff4dc733f42374d 100644 (file)
@@ -225,6 +225,9 @@ add_to_log2(roomconfig_change, _Occupants, Room, Opts, State) ->
 add_to_log2(roomconfig_change_enabledlogging, Occupants, Room, Opts, State) ->
     add_message_to_log("", {roomconfig_change, Occupants}, Room, Opts, State);
 
+add_to_log2(room_existence, NewStatus, Room, Opts, State) ->
+    add_message_to_log("", {room_existence, NewStatus}, Room, Opts, State);
+
 add_to_log2(nickchange, {OldNick, NewNick}, Room, Opts, State) ->
     add_message_to_log(NewNick, {nickchange, OldNick}, Room, Opts, State);
 
@@ -423,7 +426,10 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
                       {nomatch, _} ->
                           io_lib:format("<font class=\"mn\">~s</font> ~s<br/>",
                                         [Nick2, htmlize(T,NoFollow,FileFormat)])
-                  end
+                  end;
+              {room_existence, RoomNewExistence} ->
+                  io_lib:format("<font class=\"mrcm\">~s</font><br/>",
+                                [get_room_existence_string(RoomNewExistence, Lang)])
           end,
     {Hour, Minute, Second} = Time,
     STime = lists:flatten(
@@ -443,6 +449,11 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
 %%----------------------------------------------------------------------
 %% Utilities
 
+get_room_existence_string(created, Lang) -> ?T("Chatroom is created");
+get_room_existence_string(destroyed, Lang) -> ?T("Chatroom is destroyed");
+get_room_existence_string(started, Lang) -> ?T("Chatroom is started");
+get_room_existence_string(stopped, Lang) -> ?T("Chatroom is stopped").
+
 get_dateweek(Date, Lang) ->
     Weekday = case calendar:day_of_the_week(Date) of
                  1 -> ?T("Monday");
index f63fdd81e045a10902babfc3d7dd68c8d8d38030..54199ff2a222363c005ccba2cdcd1843695877ad 100644 (file)
@@ -125,6 +125,8 @@ init([Host, ServerHost, Access, Room, HistorySize, RoomShaper, Creator, _Nick, D
     State1 = set_opts(DefRoomOpts, State),
     ?INFO_MSG("Created MUC room ~s@~s by ~s", 
              [Room, Host, jlib:jid_to_string(Creator)]),
+    add_to_log(room_existence, created, State1),
+    add_to_log(room_existence, started, State1),
     {ok, normal_state, State1};
 init([Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts]) ->
     process_flag(trap_exit, true),
@@ -136,6 +138,7 @@ init([Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts]) ->
                                  history = lqueue_new(HistorySize),
                                  jid = jlib:make_jid(Room, Host, ""),
                                  room_shaper = Shaper}),
+    add_to_log(room_existence, started, State),
     {ok, normal_state, State}.
 
 %%----------------------------------------------------------------------
@@ -567,6 +570,7 @@ handle_event({destroy, Reason}, _StateName, StateData) ->
            end}, StateData),
     ?INFO_MSG("Destroyed MUC room ~s with reason: ~p", 
              [jlib:jid_to_string(StateData#state.jid), Reason]),
+    add_to_log(room_existence, destroyed, StateData),
     {stop, normal, StateData};
 handle_event(destroy, StateName, StateData) ->
     ?INFO_MSG("Destroyed MUC room ~s", 
@@ -725,10 +729,13 @@ handle_info(_Info, StateName, StateData) ->
 %% Returns: any
 %%----------------------------------------------------------------------
 terminate(_Reason, _StateName, StateData) ->
+    ?INFO_MSG("Stopping MUC room ~s@~s",
+             [StateData#state.room, StateData#state.host]),
     ?DICT:fold(
        fun(J, _, _) ->
               tab_remove_online_user(J, StateData)
        end, [], StateData#state.users),
+    add_to_log(room_existence, stopped, StateData),
     mod_muc:room_destroyed(StateData#state.host, StateData#state.room, self(),
                           StateData#state.server_host),
     ok.
@@ -962,6 +969,7 @@ process_presence(From, Nick, {xmlelement, "presence", Attrs, _Els} = Packet,
        true ->
            ?INFO_MSG("Destroyed MUC room ~s because it's temporary and empty", 
                      [jlib:jid_to_string(StateData#state.jid)]),
+           add_to_log(room_existence, destroyed, StateData),
            {stop, normal, StateData1};
        _ ->
            {next_state, normal_state, StateData1}
@@ -2698,6 +2706,7 @@ process_iq_owner(From, set, Lang, SubEl, StateData) ->
                [{xmlelement, "destroy", _Attrs1, _Els1} = SubEl1] ->
                    ?INFO_MSG("Destroyed MUC room ~s by the owner ~s", 
                              [jlib:jid_to_string(StateData#state.jid), jlib:jid_to_string(From)]),
+                   add_to_log(room_existence, destroyed, StateData),
                    destroy_room(SubEl1, StateData);
                Items ->
                    process_admin_items_set(From, Items, Lang, StateData)