25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Guard agains sm:get_user_info returning offline

This fixes issue #2765
This commit is contained in:
Paweł Chmielowski 2019-01-15 10:04:15 +01:00
parent 63259f5cc9
commit 7183fe6b80

View File

@ -987,11 +987,15 @@ get_status_list(Host, Status_required) ->
apply(Fstatus, [Status, Status_required])].
connected_users_info() ->
lists:map(
lists:filtermap(
fun({U, S, R}) ->
Info = user_session_info(U, S, R),
case user_session_info(U, S, R) of
offline ->
false;
Info ->
Jid = jid:encode(jid:make(U, S, R)),
erlang:insert_element(1, Info, Jid)
{true, erlang:insert_element(1, Info, Jid)}
end
end,
ejabberd_sm:dirty_get_sessions_list()).
@ -1054,12 +1058,19 @@ set_presence(User, Host, Resource, Type, Show, Status, Priority0) ->
ejabberd_c2s:set_presence(Ref, Pres).
user_sessions_info(User, Host) ->
[user_session_info(User, Host, Resource) ||
Resource <- ejabberd_sm:get_user_resources(User, Host)].
lists:filtermap(fun(Resource) ->
case user_session_info(User, Host, Resource) of
offline -> false;
Info -> {true, Info}
end
end, ejabberd_sm:get_user_resources(User, Host)).
user_session_info(User, Host, Resource) ->
CurrentSec = calendar:datetime_to_gregorian_seconds({date(), time()}),
Info = ejabberd_sm:get_user_info(User, Host, Resource),
case ejabberd_sm:get_user_info(User, Host, Resource) of
offline ->
offline;
Info ->
Now = proplists:get_value(ts, Info),
Pid = proplists:get_value(pid, Info),
{_U, _Resource, Status, StatusText} = get_presence(Pid),
@ -1070,7 +1081,8 @@ user_session_info(User, Host, Resource) ->
NodeS = atom_to_list(node(Pid)),
Uptime = CurrentSec - calendar:datetime_to_gregorian_seconds(
calendar:now_to_local_time(Now)),
{atom_to_list(Conn), IPS, Port, num_prio(Priority), NodeS, Uptime, Status, Resource, StatusText}.
{atom_to_list(Conn), IPS, Port, num_prio(Priority), NodeS, Uptime, Status, Resource, StatusText}
end.
%%%