From 8a9f50a2ace0cfdacfa7e61095e7eedb9495d55d Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 5 Mar 2020 15:12:01 +0100 Subject: [PATCH 1/2] Don't loop in case of an error --- apps/roster/src/roster.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/roster/src/roster.erl b/apps/roster/src/roster.erl index e3b47bed8..094ff5327 100644 --- a/apps/roster/src/roster.erl +++ b/apps/roster/src/roster.erl @@ -571,7 +571,8 @@ unload() -> on_client_disconnected(_Reason, #mqtt_client{client_id = <<"emqttd_", _/bytes>> = ClientId}, _Env) -> % TODO: mqttc:publish(C, lists:concat(["ses/",Phone])) on_disconnect(ClientId); -on_client_disconnected(_Reason, #mqtt_client{client_id = <<"reg_", _/bytes>> = ClientId}, _) -> final_disconnect(ClientId); +on_client_disconnected(_Reason, #mqtt_client{client_id = <<"reg_", _/bytes>> = ClientId}, _) -> + final_disconnect(ClientId); on_client_disconnected(_Reason, _Client = #mqtt_client{}, _Env) -> ok. on_disconnect(<<"emqttd_", _/binary>> = ClientId) -> info(roster_auth, "~p:CLIENT DISCONNECT",[ClientId]), @@ -2282,5 +2283,13 @@ cache_ses(PhoneId, Term) -> send_cache(#'Auth'{client_id = ClientId, settings = Settings} = Auth, C) -> [send_action(C, ClientId, V) || #'Feature'{key = <<"cache_", _/binary>>, value = V} <- Settings], case [F||#'Feature'{group = Group} = F <- Settings, Group /= <<"CACHE_GROUP">>] of - Settings -> ok; S -> kvs:put(Auth#'Auth'{settings = S}) end; -send_cache(ClientId, C) -> send_cache(element(2, kvs:get('Auth', ClientId)), C). + Settings -> + ok; + S -> + kvs:put(Auth#'Auth'{settings = S}) + end; +send_cache(ClientId, C) -> + case kvs:get('Auth', ClientId) of + {ok, Auth} -> send_cache(Auth, C); + Error -> Error + end. -- GitLab From ed0913094aef9af336654bd922c1d06ffa5fe8a5 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Thu, 5 Mar 2020 15:17:43 +0100 Subject: [PATCH 2/2] Code refactoring --- apps/roster/src/protocol/roster_presence.erl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/roster/src/protocol/roster_presence.erl b/apps/roster/src/protocol/roster_presence.erl index b184d0bb1..68ca6c173 100644 --- a/apps/roster/src/protocol/roster_presence.erl +++ b/apps/roster/src/protocol/roster_presence.erl @@ -22,7 +22,8 @@ on_connect(Phone, ClientId, C, Ver) -> case send_presence(online, Phone, C, ClientId) of {error, profile_not_found} -> roster:info(?MODULE, "~p:~p:Connect:ProfileNotFound", [Phone, ClientId]), roster:delete_sessions(Phone); - #'Profile'{} = P when Ver==?VERSION -> roster:send_cache(ClientId, C); + #'Profile'{} = P when Ver==?VERSION -> + roster:send_cache(ClientId, C); #'Profile'{} = P-> roster:send_profile(P#'Profile'{settings = amazon_settings(P), status = init}, [], 0, ClientId, C), roster:send_cache(ClientId, C) @@ -56,11 +57,15 @@ send_presence(Status, Phone, C, ClientId) when Status == online; Status == offli PhoneId = roster:phone_id(Phone, AccId), [roster:Send(C, PhoneId, #'Contact'{phone_id = PhoneId, presence = Status, update = Now, status = internal}) || Send <- [send_muc, send_ac]]; - #error{} -> skip + {error, _} -> skip end || AccId <- Rosters], P2; - _ -> roster:info(?MODULE, "~p:~p:~p",[Phone, ClientId,P]), P end; - _ -> {error, profile_not_found} end. + _ -> + roster:info(?MODULE, "~p:~p:~p",[Phone, ClientId,P]), + P + end; + _ -> {error, profile_not_found} + end. send_presence(Status, PhoneId, C) -> -- GitLab