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.
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},
{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,
process_sm_iq/3,
on_presence_update/4,
store_last_info/4,
+ get_last_info/2,
remove_user/2]).
-include("ejabberd.hrl").
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} ->
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),
process_sm_iq/3,
on_presence_update/4,
store_last_info/4,
+ get_last_info/2,
remove_user/2]).
-include("ejabberd.hrl").
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
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),