]> granicus.if.org Git - ejabberd/commitdiff
* src/mod_configure.erl: The command get-user-lastlogin is now
authorBadlop <badlop@process-one.net>
Tue, 27 Nov 2007 18:54:06 +0000 (18:54 +0000)
committerBadlop <badlop@process-one.net>
Tue, 27 Nov 2007 18:54:06 +0000 (18:54 +0000)
compatible with both Mnesia and ODBC (EJAB-383)
* src/mod_last.erl: Likewise
* src/mod_last_odbc.erl: Likewise

SVN Revision: 995

ChangeLog
src/mod_configure.erl
src/mod_last.erl
src/mod_last_odbc.erl

index 6f1a626231dba4c3b12f700f3cea081311a43e20..0e378a08a03e07a6723b6fc8eb7d2ca46f607e50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-11-27  Badlop  <badlop@process-one.net>
 
+       * src/mod_configure.erl: The command get-user-lastlogin is now
+       compatible with both Mnesia and ODBC (EJAB-383)
+       * src/mod_last.erl: Likewise
+       * src/mod_last_odbc.erl: Likewise
+
        * doc/guide.tex: Document ejabberd_http's
        request_handlers (EJAB-372). Fixed small Latex problems.
        Sort options of listening sockets.
index 24f40b33c7434079da1b98c0c91c86a677d76a84..e49dc7007bb26538a6ec6cc7eebcbacec6b959ae 100644 (file)
@@ -1606,11 +1606,11 @@ set_form(_From, _Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) ->
        case ejabberd_sm:get_user_resources(User, Server) of
            [] ->
                US = {User, Server},
-               case mnesia:dirty_read({last_activity, US}) of
-                   [] ->
+               case get_last_info(User, Server) of
+                   not_found ->
                        ?T(Lang, "Never");
-                   [E] ->
-                       Shift = element(3, E),
+                   {ok, Timestamp, _Status} ->
+                       Shift = Timestamp,
                        TimeStamp = {Shift div 1000000,
                                     Shift rem 1000000,
                                     0},
@@ -1711,6 +1711,16 @@ stop_node(From, Host, ENode, Action, XData) ->
     {result, []}.
 
 
+get_last_info(User, Server) ->
+    ML = lists:member(mod_last, gen_mod:loaded_modules(Server)),
+    MLO = lists:member(mod_last_odbc, gen_mod:loaded_modules(Server)),
+    case {ML, MLO} of
+       {true, _} -> mod_last:get_last_info(User, Server);
+       {false, true} -> mod_last_odbc:get_last_info(User, Server);
+       {false, false} -> not_found
+    end.
+
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 adhoc_sm_commands(_Acc, From,
index 4a61f3b5339bb410cceb5727c49d78bae1fbe1a4..d5ee25fb747737c6531770968c2ef517fca06ac2 100644 (file)
@@ -18,6 +18,7 @@
         process_sm_iq/3,
         on_presence_update/4,
         store_last_info/4,
+        get_last_info/2,
         remove_user/2]).
 
 -include("ejabberd.hrl").
@@ -100,6 +101,7 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
            end
     end.
 
+%% TODO: This function could use get_last_info/2
 get_last(IQ, SubEl, LUser, LServer) ->
     case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
        {'EXIT', _Reason} ->
@@ -135,6 +137,16 @@ store_last_info(User, Server, TimeStamp, Status) ->
        end,
     mnesia:transaction(F).
     
+%% Returns: {ok, Timestamp, Status} | not_found
+get_last_info(LUser, LServer) ->
+    case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
+       {'EXIT', _Reason} ->
+           not_found;
+       [] ->
+           not_found;
+       [#last_activity{timestamp = TimeStamp, status = Status}] ->
+           {ok, TimeStamp, Status}
+    end.
 
 remove_user(User, Server) ->
     LUser = jlib:nodeprep(User),
index 0b01191269741b3a19f453a510fe98b679378b62..3c2ab21baae23e58760135bf133003a77feef2d8 100644 (file)
@@ -18,6 +18,7 @@
         process_sm_iq/3,
         on_presence_update/4,
         store_last_info/4,
+        get_last_info/2,
         remove_user/2]).
 
 -include("ejabberd.hrl").
@@ -92,6 +93,7 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
            end
     end.
 
+%% TODO: This function could use get_last_info/2
 get_last(IQ, SubEl, LUser, LServer) ->
     Username = ejabberd_odbc:escape(LUser),
     case catch odbc_queries:get_last(LServer, Username) of
@@ -129,6 +131,22 @@ store_last_info(User, Server, TimeStamp, Status) ->
     State = ejabberd_odbc:escape(Status),
     odbc_queries:set_last_t(LServer, Username, Seconds, State).
 
+%% Returns: {ok, Timestamp, Status} | not_found
+get_last_info(LUser, LServer) ->
+    Username = ejabberd_odbc:escape(LUser),
+    case catch odbc_queries:get_last(LServer, Username) of
+       {'EXIT', _Reason} ->
+           not_found;
+       {selected, ["seconds","state"], []} ->
+           not_found;
+       {selected, ["seconds","state"], [{STimeStamp, Status}]} ->
+           case catch list_to_integer(STimeStamp) of
+               TimeStamp when is_integer(TimeStamp) ->
+                   {ok, TimeStamp, Status};
+               _ ->
+                   not_found
+           end
+    end.
 
 remove_user(User, Server) ->
     LUser = jlib:nodeprep(User),