get_last now always returns tuple with UTC XEP-0082 and status (#1565)

This commit is contained in:
Badlop 2017-02-23 23:27:57 +01:00
parent 6314a96b05
commit 57181c0a76
1 changed files with 14 additions and 18 deletions

View File

@ -538,12 +538,15 @@ get_commands_spec() ->
result = {res, rescode}}, result = {res, rescode}},
#ejabberd_commands{name = get_last, tags = [last], #ejabberd_commands{name = get_last, tags = [last],
desc = "Get last activity information (timestamp and status)", desc = "Get last activity information",
longdesc = "Timestamp is the seconds since" longdesc = "Timestamp is UTC and XEP-0082 format, for example: "
"1970-01-01 00:00:00 UTC, for example: date +%s", "2017-02-23T22:25:28.063062Z ONLINE",
module = ?MODULE, function = get_last, module = ?MODULE, function = get_last,
args = [{user, binary}, {host, binary}], args = [{user, binary}, {host, binary}],
result = {last_activity, string}}, result = {last_activity,
{tuple, [{timestamp, string},
{status, string}
]}}},
#ejabberd_commands{name = set_last, tags = [last], #ejabberd_commands{name = set_last, tags = [last],
desc = "Set last activity information", desc = "Set last activity information",
longdesc = "Timestamp is the seconds since" longdesc = "Timestamp is the seconds since"
@ -1337,25 +1340,18 @@ build_broadcast(U, S, SubsAtom) when is_atom(SubsAtom) ->
%%% %%%
get_last(User, Server) -> get_last(User, Server) ->
case ejabberd_sm:get_user_resources(User, Server) of {Now, Status} = case ejabberd_sm:get_user_resources(User, Server) of
[] -> [] ->
case mod_last:get_last_info(User, Server) of case mod_last:get_last_info(User, Server) of
not_found -> not_found ->
"Never"; {now(), "NOT FOUND"};
{ok, Shift, Status} -> {ok, Shift, Status1} ->
TimeStamp = {Shift div 1000000, {{Shift div 1000000, Shift rem 1000000, 0}, Status1}
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 ~s",
[Year, Month, Day, Hour, Minute, Second, Status]))
end; end;
_ -> _ ->
"Online" {now(), "ONLINE"}
end. end,
{xmpp_util:encode_timestamp(Now), Status}.
%%% %%%
%%% Private Storage %%% Private Storage