aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2013-08-07 13:36:42 +0200
committerBadlop <badlop@process-one.net>2015-03-26 13:59:59 +0100
commite6a9c5ccee9336b291a7c5bee3bfefa3d0e9da75 (patch)
tree127c1c80c09330b8ae33db7cc9255e8a78df10a5
parentInitial import from ejabberd-modules SVN (diff)
Add get_last to ejabberdctl for last user activity (thanks to lehrblogger)
The logic for determining the response is borrowed from here: https://github.com/processone/ejabberd/blob/6d811f5178e000def445e12deaa0d587004efc67/src/web/ejabberd_web_admin.erl#L1583-L1601
-rw-r--r--src/mod_admin_extra.erl30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl
index a6354728c..2a7d5929b 100644
--- a/src/mod_admin_extra.erl
+++ b/src/mod_admin_extra.erl
@@ -69,6 +69,7 @@
push_roster_all/1,
push_alltoall/2,
%% mod_last
+ get_last/2,
set_last/4,
%% mod_private
private_get/4,
@@ -436,6 +437,13 @@ commands() ->
args = [{host, string}, {group, string}],
result = {res, rescode}},
+ #ejabberd_commands{name = get_last, tags = [last],
+ desc = "Get last activity information",
+ longdesc = "Timestamp is the seconds since"
+ "1970-01-01 00:00:00 UTC, for example: date +%s",
+ module = ?MODULE, function = get_last,
+ args = [{user, string}, {host, string}],
+ result = {last_activity, string}},
#ejabberd_commands{name = set_last, tags = [last],
desc = "Set last activity information",
longdesc = "Timestamp is the seconds since"
@@ -1233,6 +1241,28 @@ build_broadcast(U, S, SubsAtom) when is_atom(SubsAtom) ->
%%% Last Activity
%%%
+get_last(User, Server) ->
+ Mod = get_lastactivity_module(Server),
+ case ejabberd_sm:get_user_resources(User, Server) of
+ [] ->
+ case Mod:get_last_info(User, Server) of
+ not_found ->
+ "Never";
+ {ok, Shift, _Status} ->
+ TimeStamp = {Shift div 1000000,
+ Shift rem 1000000,
+ 0},
+ {{Year, Month, Day}, {Hour, Minute, Second}} =
+ calendar:now_to_local_time(TimeStamp),
+ lists:flatten(
+ io_lib:format(
+ "~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w",
+ [Year, Month, Day, Hour, Minute, Second]))
+ end;
+ _ ->
+ "Online"
+ end.
+
set_last(User, Server, Timestamp, Status) ->
Mod = get_lastactivity_module(Server),
Mod:store_last_info(User, Server, Timestamp, Status).