mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Avoid using broad map() type wherever possible
This commit is contained in:
parent
6b684c866b
commit
39cf8d86d6
@ -105,13 +105,13 @@
|
|||||||
access = {none,none,none,none,none} :: {atom(), atom(), atom(), atom(), atom()},
|
access = {none,none,none,none,none} :: {atom(), atom(), atom(), atom(), atom()},
|
||||||
jid = #jid{} :: jid(),
|
jid = #jid{} :: jid(),
|
||||||
config = #config{} :: config(),
|
config = #config{} :: config(),
|
||||||
users = #{} :: map(),
|
users = #{} :: users(),
|
||||||
subscribers = #{} :: map(),
|
subscribers = #{} :: subscribers(),
|
||||||
subscriber_nicks = #{} :: map(),
|
subscriber_nicks = #{} :: subscriber_nicks(),
|
||||||
last_voice_request_time = treap:empty() :: treap:treap(),
|
last_voice_request_time = treap:empty() :: treap:treap(),
|
||||||
robots = #{} :: map(),
|
robots = #{} :: robots(),
|
||||||
nicks = #{} :: map(),
|
nicks = #{} :: nicks(),
|
||||||
affiliations = #{} :: map(),
|
affiliations = #{} :: affiliations(),
|
||||||
history = #lqueue{} :: lqueue(),
|
history = #lqueue{} :: lqueue(),
|
||||||
subject = [] :: [text()],
|
subject = [] :: [text()],
|
||||||
subject_author = <<"">> :: binary(),
|
subject_author = <<"">> :: binary(),
|
||||||
@ -120,3 +120,10 @@
|
|||||||
room_shaper = none :: ejabberd_shaper:shaper(),
|
room_shaper = none :: ejabberd_shaper:shaper(),
|
||||||
room_queue :: p1_queue:queue() | undefined
|
room_queue :: p1_queue:queue() | undefined
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-type users() :: #{ljid() => #user{}}.
|
||||||
|
-type robots() :: #{jid() => {binary(), stanza()}}.
|
||||||
|
-type nicks() :: #{binary() => [ljid()]}.
|
||||||
|
-type affiliations() :: #{ljid() => affiliation() | {affiliation(), binary()}}.
|
||||||
|
-type subscribers() :: #{ljid() => #subscriber{}}.
|
||||||
|
-type subscriber_nicks() :: #{binary() => [ljid()]}.
|
||||||
|
@ -53,8 +53,9 @@
|
|||||||
|
|
||||||
-define(SALT_LENGTH, 16).
|
-define(SALT_LENGTH, 16).
|
||||||
|
|
||||||
-record(state, {host_modules = #{} :: map()}).
|
-record(state, {host_modules = #{} :: host_modules()}).
|
||||||
|
|
||||||
|
-type host_modules() :: #{binary => [module()]}.
|
||||||
-type password() :: binary() | #scram{}.
|
-type password() :: binary() | #scram{}.
|
||||||
-type digest_fun() :: fun((binary()) -> binary()).
|
-type digest_fun() :: fun((binary()) -> binary()).
|
||||||
-export_type([password/0]).
|
-export_type([password/0]).
|
||||||
@ -751,7 +752,7 @@ password_to_scram(Password, IterationCount) ->
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% Cache stuff
|
%%% Cache stuff
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
-spec init_cache(map()) -> ok.
|
-spec init_cache(host_modules()) -> ok.
|
||||||
init_cache(HostModules) ->
|
init_cache(HostModules) ->
|
||||||
CacheOpts = cache_opts(),
|
CacheOpts = cache_opts(),
|
||||||
{True, False} = use_cache(HostModules),
|
{True, False} = use_cache(HostModules),
|
||||||
@ -771,7 +772,7 @@ cache_opts() ->
|
|||||||
LifeTime = ejabberd_option:auth_cache_life_time(),
|
LifeTime = ejabberd_option:auth_cache_life_time(),
|
||||||
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
|
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
|
||||||
|
|
||||||
-spec use_cache(map()) -> {True :: [module()], False :: [module()]}.
|
-spec use_cache(host_modules()) -> {True :: [module()], False :: [module()]}.
|
||||||
use_cache(HostModules) ->
|
use_cache(HostModules) ->
|
||||||
{Enabled, Disabled} =
|
{Enabled, Disabled} =
|
||||||
maps:fold(
|
maps:fold(
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
{exception, term(), term(), term()}.
|
{exception, term(), term(), term()}.
|
||||||
-type error_return() :: {error, econf:error_reason(), term()} |
|
-type error_return() :: {error, econf:error_reason(), term()} |
|
||||||
{error, error_reason()}.
|
{error, error_reason()}.
|
||||||
|
-type host_config() :: #{{atom(), binary() | global} => term()}.
|
||||||
|
|
||||||
-callback opt_type(atom()) -> econf:validator().
|
-callback opt_type(atom()) -> econf:validator().
|
||||||
-callback options() -> [atom() | {atom(), term()}].
|
-callback options() -> [atom() | {atom(), term()}].
|
||||||
@ -594,7 +595,7 @@ abort(Err) ->
|
|||||||
end,
|
end,
|
||||||
Err.
|
Err.
|
||||||
|
|
||||||
-spec set_host_config([{atom(), term()}]) -> {ok, map()} | error_return().
|
-spec set_host_config([{atom(), term()}]) -> {ok, host_config()} | error_return().
|
||||||
set_host_config(Opts) ->
|
set_host_config(Opts) ->
|
||||||
Map1 = lists:foldl(
|
Map1 = lists:foldl(
|
||||||
fun({Opt, Val}, M) when Opt /= host_config,
|
fun({Opt, Val}, M) when Opt /= host_config,
|
||||||
@ -635,7 +636,7 @@ set_host_config(Opts) ->
|
|||||||
_ -> {ok, Map3}
|
_ -> {ok, Map3}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec apply_defaults(ets:tid(), [binary()], map()) -> ok.
|
-spec apply_defaults(ets:tid(), [binary()], host_config()) -> ok.
|
||||||
apply_defaults(Tab, Hosts, Map) ->
|
apply_defaults(Tab, Hosts, Map) ->
|
||||||
Defaults1 = defaults(),
|
Defaults1 = defaults(),
|
||||||
apply_defaults(Tab, global, Map, Defaults1),
|
apply_defaults(Tab, global, Map, Defaults1),
|
||||||
@ -646,7 +647,8 @@ apply_defaults(Tab, Hosts, Map) ->
|
|||||||
apply_defaults(Tab, Host, Map, Defaults2)
|
apply_defaults(Tab, Host, Map, Defaults2)
|
||||||
end, Hosts).
|
end, Hosts).
|
||||||
|
|
||||||
-spec apply_defaults(ets:tid(), global | binary(), map(),
|
-spec apply_defaults(ets:tid(), global | binary(),
|
||||||
|
host_config(),
|
||||||
[atom() | {atom(), term()}]) -> ok.
|
[atom() | {atom(), term()}]) -> ok.
|
||||||
apply_defaults(Tab, Host, Map, Defaults) ->
|
apply_defaults(Tab, Host, Map, Defaults) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
@ -54,9 +54,10 @@
|
|||||||
|
|
||||||
-record(state, {connection :: pid() | undefined,
|
-record(state, {connection :: pid() | undefined,
|
||||||
num :: pos_integer(),
|
num :: pos_integer(),
|
||||||
subscriptions = #{} :: map(),
|
subscriptions = #{} :: subscriptions(),
|
||||||
pending_q :: p1_queue:queue()}).
|
pending_q :: p1_queue:queue()}).
|
||||||
|
|
||||||
|
-type subscriptions() :: #{binary() => [pid()]}.
|
||||||
-type error_reason() :: binary() | timeout | disconnected | overloaded.
|
-type error_reason() :: binary() | timeout | disconnected | overloaded.
|
||||||
-type redis_error() :: {error, error_reason()}.
|
-type redis_error() :: {error, error_reason()}.
|
||||||
-type redis_reply() :: undefined | binary() | [binary()].
|
-type redis_reply() :: undefined | binary() | [binary()].
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
name :: pid() | atom()}).
|
name :: pid() | atom()}).
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
-type proc_stat() :: #proc_stat{}.
|
-type proc_stat() :: #proc_stat{}.
|
||||||
|
-type app_pids() :: #{pid() => atom()}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
@ -151,7 +152,7 @@ handle_overload(_State, Procs) ->
|
|||||||
end,
|
end,
|
||||||
lists:foreach(fun erlang:garbage_collect/1, Procs).
|
lists:foreach(fun erlang:garbage_collect/1, Procs).
|
||||||
|
|
||||||
-spec get_app_pids() -> map().
|
-spec get_app_pids() -> app_pids().
|
||||||
get_app_pids() ->
|
get_app_pids() ->
|
||||||
try application:info() of
|
try application:info() of
|
||||||
Info ->
|
Info ->
|
||||||
@ -170,7 +171,7 @@ get_app_pids() ->
|
|||||||
#{}
|
#{}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec overloaded_procs(map(), [pid()])
|
-spec overloaded_procs(app_pids(), [pid()])
|
||||||
-> {non_neg_integer(), non_neg_integer(), dict:dict(), [proc_stat()]}.
|
-> {non_neg_integer(), non_neg_integer(), dict:dict(), [proc_stat()]}.
|
||||||
overloaded_procs(AppPids, AllProcs) ->
|
overloaded_procs(AppPids, AllProcs) ->
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
@ -186,7 +187,7 @@ overloaded_procs(AppPids, AllProcs) ->
|
|||||||
end
|
end
|
||||||
end, {0, 0, dict:new(), []}, AllProcs).
|
end, {0, 0, dict:new(), []}, AllProcs).
|
||||||
|
|
||||||
-spec proc_stat(pid(), map()) -> proc_stat() | undefined.
|
-spec proc_stat(pid(), app_pids()) -> proc_stat() | undefined.
|
||||||
proc_stat(Pid, AppPids) ->
|
proc_stat(Pid, AppPids) ->
|
||||||
case process_info(Pid, [message_queue_len,
|
case process_info(Pid, [message_queue_len,
|
||||||
memory,
|
memory,
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include_lib("kernel/include/file.hrl").
|
-include_lib("kernel/include/file.hrl").
|
||||||
|
|
||||||
|
-type distance_cache() :: #{{string(), string()} => non_neg_integer()}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
@ -598,7 +600,7 @@ unique_timestamp() ->
|
|||||||
{MS, S, erlang:unique_integer([positive, monotonic]) rem 1000000}.
|
{MS, S, erlang:unique_integer([positive, monotonic]) rem 1000000}.
|
||||||
|
|
||||||
%% Levenshtein distance
|
%% Levenshtein distance
|
||||||
-spec ld(string(), string(), map()) -> {non_neg_integer(), map()}.
|
-spec ld(string(), string(), distance_cache()) -> {non_neg_integer(), distance_cache()}.
|
||||||
ld([] = S, T, Cache) ->
|
ld([] = S, T, Cache) ->
|
||||||
{length(T), maps:put({S, T}, length(T), Cache)};
|
{length(T), maps:put({S, T}, length(T), Cache)};
|
||||||
ld(S, [] = T, Cache) ->
|
ld(S, [] = T, Cache) ->
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
-include("pubsub.hrl").
|
-include("pubsub.hrl").
|
||||||
|
|
||||||
|
-type avatar_id_meta() :: #{avatar_meta => {binary(), avatar_meta()}}.
|
||||||
-opaque convert_rule() :: {default | eimp:img_type(), eimp:img_type()}.
|
-opaque convert_rule() :: {default | eimp:img_type(), eimp:img_type()}.
|
||||||
-export_type([convert_rule/0]).
|
-export_type([convert_rule/0]).
|
||||||
|
|
||||||
@ -362,7 +363,7 @@ convert_avatar(LUser, LServer, Data, Rules) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec set_vcard_avatar(jid(), vcard_photo() | undefined, map()) -> ok.
|
-spec set_vcard_avatar(jid(), vcard_photo() | undefined, avatar_id_meta()) -> ok.
|
||||||
set_vcard_avatar(JID, VCardPhoto, Meta) ->
|
set_vcard_avatar(JID, VCardPhoto, Meta) ->
|
||||||
case get_vcard(JID) of
|
case get_vcard(JID) of
|
||||||
{ok, #vcard_temp{photo = VCardPhoto}} ->
|
{ok, #vcard_temp{photo = VCardPhoto}} ->
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
-define(CSI_QUEUE_MAX, 100).
|
-define(CSI_QUEUE_MAX, 100).
|
||||||
|
|
||||||
-type csi_type() :: presence | chatstate | {pep, binary()}.
|
-type csi_type() :: presence | chatstate | {pep, binary()}.
|
||||||
-type csi_queue() :: {non_neg_integer(), map()}.
|
-type csi_queue() :: {non_neg_integer(), #{csi_key() => csi_element()}}.
|
||||||
-type csi_timestamp() :: {non_neg_integer(), erlang:timestamp()}.
|
-type csi_timestamp() :: {non_neg_integer(), erlang:timestamp()}.
|
||||||
-type csi_key() :: {ljid(), csi_type()}.
|
-type csi_key() :: {ljid(), csi_type()}.
|
||||||
-type csi_element() :: {csi_timestamp(), stanza()}.
|
-type csi_element() :: {csi_timestamp(), stanza()}.
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
service_url :: binary() | undefined,
|
service_url :: binary() | undefined,
|
||||||
thumbnail :: boolean(),
|
thumbnail :: boolean(),
|
||||||
custom_headers :: [{binary(), binary()}],
|
custom_headers :: [{binary(), binary()}],
|
||||||
slots = #{} :: map(),
|
slots = #{} :: slots(),
|
||||||
external_secret :: binary()}).
|
external_secret :: binary()}).
|
||||||
|
|
||||||
-record(media_info,
|
-record(media_info,
|
||||||
@ -116,6 +116,7 @@
|
|||||||
|
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
-type slot() :: [binary(), ...].
|
-type slot() :: [binary(), ...].
|
||||||
|
-type slots() :: #{slot() => {pos_integer(), reference()}}.
|
||||||
-type media_info() :: #media_info{}.
|
-type media_info() :: #media_info{}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -61,9 +61,10 @@
|
|||||||
access_hard_quota :: atom(),
|
access_hard_quota :: atom(),
|
||||||
max_days :: pos_integer() | infinity,
|
max_days :: pos_integer() | infinity,
|
||||||
docroot :: binary(),
|
docroot :: binary(),
|
||||||
disk_usage = #{} :: map(),
|
disk_usage = #{} :: disk_usage(),
|
||||||
timers :: [timer:tref()]}).
|
timers :: [timer:tref()]}).
|
||||||
|
|
||||||
|
-type disk_usage() :: #{{binary(), binary()} => non_neg_integer()}.
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -40,15 +40,19 @@
|
|||||||
will :: undefined | publish(),
|
will :: undefined | publish(),
|
||||||
will_delay = 0 :: seconds(),
|
will_delay = 0 :: seconds(),
|
||||||
stop_reason :: undefined | error_reason(),
|
stop_reason :: undefined | error_reason(),
|
||||||
acks = #{} :: map(),
|
acks = #{} :: acks(),
|
||||||
subscriptions = #{} :: map(),
|
subscriptions = #{} :: subscriptions(),
|
||||||
topic_aliases = #{} :: map(),
|
topic_aliases = #{} :: topic_aliases(),
|
||||||
id = 0 :: non_neg_integer(),
|
id = 0 :: non_neg_integer(),
|
||||||
in_flight :: undefined | publish() | pubrel(),
|
in_flight :: undefined | publish() | pubrel(),
|
||||||
codec :: mqtt_codec:state(),
|
codec :: mqtt_codec:state(),
|
||||||
queue :: undefined | p1_queue:queue(),
|
queue :: undefined | p1_queue:queue(),
|
||||||
tls :: boolean()}).
|
tls :: boolean()}).
|
||||||
|
|
||||||
|
-type acks() :: #{non_neg_integer() => pubrec()}.
|
||||||
|
-type subscriptions() :: #{binary() => {sub_opts(), non_neg_integer()}}.
|
||||||
|
-type topic_aliases() :: #{non_neg_integer() => binary()}.
|
||||||
|
|
||||||
-type error_reason() :: {auth, reason_code()} |
|
-type error_reason() :: {auth, reason_code()} |
|
||||||
{code, reason_code()} |
|
{code, reason_code()} |
|
||||||
{peer_disconnected, reason_code(), binary()} |
|
{peer_disconnected, reason_code(), binary()} |
|
||||||
@ -685,13 +689,13 @@ get_connack_properties(#state{session_expiry = SessExp, jid = JID},
|
|||||||
server_keep_alive => KeepAlive}.
|
server_keep_alive => KeepAlive}.
|
||||||
|
|
||||||
-spec subscribe([{binary(), sub_opts()}], jid:ljid(), non_neg_integer()) ->
|
-spec subscribe([{binary(), sub_opts()}], jid:ljid(), non_neg_integer()) ->
|
||||||
{[reason_code()], map(), properties()}.
|
{[reason_code()], subscriptions(), properties()}.
|
||||||
subscribe(TopicFilters, USR, SubID) ->
|
subscribe(TopicFilters, USR, SubID) ->
|
||||||
subscribe(TopicFilters, USR, SubID, [], #{}, ok).
|
subscribe(TopicFilters, USR, SubID, [], #{}, ok).
|
||||||
|
|
||||||
-spec subscribe([{binary(), sub_opts()}], jid:ljid(), non_neg_integer(),
|
-spec subscribe([{binary(), sub_opts()}], jid:ljid(), non_neg_integer(),
|
||||||
[reason_code()], map(), ok | {error, error_reason()}) ->
|
[reason_code()], subscriptions(), ok | {error, error_reason()}) ->
|
||||||
{[reason_code()], map(), properties()}.
|
{[reason_code()], subscriptions(), properties()}.
|
||||||
subscribe([{TopicFilter, SubOpts}|TopicFilters], USR, SubID, Codes, Subs, Err) ->
|
subscribe([{TopicFilter, SubOpts}|TopicFilters], USR, SubID, Codes, Subs, Err) ->
|
||||||
case mod_mqtt:subscribe(USR, TopicFilter, SubOpts, SubID) of
|
case mod_mqtt:subscribe(USR, TopicFilter, SubOpts, SubID) of
|
||||||
ok ->
|
ok ->
|
||||||
@ -710,15 +714,15 @@ subscribe([], _USR, _SubID, Codes, Subs, Err) ->
|
|||||||
end,
|
end,
|
||||||
{lists:reverse(Codes), Subs, Props}.
|
{lists:reverse(Codes), Subs, Props}.
|
||||||
|
|
||||||
-spec unsubscribe([binary()], jid:ljid(), map()) ->
|
-spec unsubscribe([binary()], jid:ljid(), subscriptions()) ->
|
||||||
{[reason_code()], map(), properties()}.
|
{[reason_code()], subscriptions(), properties()}.
|
||||||
unsubscribe(TopicFilters, USR, Subs) ->
|
unsubscribe(TopicFilters, USR, Subs) ->
|
||||||
unsubscribe(TopicFilters, USR, [], Subs, ok).
|
unsubscribe(TopicFilters, USR, [], Subs, ok).
|
||||||
|
|
||||||
-spec unsubscribe([binary()], jid:ljid(),
|
-spec unsubscribe([binary()], jid:ljid(),
|
||||||
[reason_code()], map(),
|
[reason_code()], subscriptions(),
|
||||||
ok | {error, error_reason()}) ->
|
ok | {error, error_reason()}) ->
|
||||||
{[reason_code()], map(), properties()}.
|
{[reason_code()], subscriptions(), properties()}.
|
||||||
unsubscribe([TopicFilter|TopicFilters], USR, Codes, Subs, Err) ->
|
unsubscribe([TopicFilter|TopicFilters], USR, Codes, Subs, Err) ->
|
||||||
case mod_mqtt:unsubscribe(USR, TopicFilter) of
|
case mod_mqtt:unsubscribe(USR, TopicFilter) of
|
||||||
ok ->
|
ok ->
|
||||||
@ -740,7 +744,7 @@ unsubscribe([], _USR, Codes, Subs, Err) ->
|
|||||||
end,
|
end,
|
||||||
{lists:reverse(Codes), Subs, Props}.
|
{lists:reverse(Codes), Subs, Props}.
|
||||||
|
|
||||||
-spec select_retained(jid:ljid(), map(), map()) -> [{publish(), seconds()}].
|
-spec select_retained(jid:ljid(), subscriptions(), subscriptions()) -> [{publish(), seconds()}].
|
||||||
select_retained(USR, NewSubs, OldSubs) ->
|
select_retained(USR, NewSubs, OldSubs) ->
|
||||||
lists:flatten(
|
lists:flatten(
|
||||||
maps:fold(
|
maps:fold(
|
||||||
@ -1254,7 +1258,7 @@ validate_payload(_, _, _) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Misc
|
%%% Misc
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
-spec resubscribe(jid:ljid(), map()) -> ok | {error, error_reason()}.
|
-spec resubscribe(jid:ljid(), subscriptions()) -> ok | {error, error_reason()}.
|
||||||
resubscribe(USR, Subs) ->
|
resubscribe(USR, Subs) ->
|
||||||
case maps:fold(
|
case maps:fold(
|
||||||
fun(TopicFilter, {SubOpts, ID}, ok) ->
|
fun(TopicFilter, {SubOpts, ID}, ok) ->
|
||||||
|
@ -83,10 +83,10 @@
|
|||||||
-callback set_affiliation(binary(), binary(), binary(), jid(), affiliation(),
|
-callback set_affiliation(binary(), binary(), binary(), jid(), affiliation(),
|
||||||
binary()) -> ok | {error, any()}.
|
binary()) -> ok | {error, any()}.
|
||||||
-callback set_affiliations(binary(), binary(), binary(),
|
-callback set_affiliations(binary(), binary(), binary(),
|
||||||
map()) -> ok | {error, any()}.
|
affiliations()) -> ok | {error, any()}.
|
||||||
-callback get_affiliation(binary(), binary(), binary(),
|
-callback get_affiliation(binary(), binary(), binary(),
|
||||||
binary(), binary()) -> {ok, affiliation()} | {error, any()}.
|
binary(), binary()) -> {ok, affiliation()} | {error, any()}.
|
||||||
-callback get_affiliations(binary(), binary(), binary()) -> {ok, map()} | {error, any()}.
|
-callback get_affiliations(binary(), binary(), binary()) -> {ok, affiliations()} | {error, any()}.
|
||||||
-callback search_affiliation(binary(), binary(), binary(), affiliation()) ->
|
-callback search_affiliation(binary(), binary(), binary(), affiliation()) ->
|
||||||
{ok, [{ljid(), {affiliation(), binary()}}]} | {error, any()}.
|
{ok, [{ljid(), {affiliation(), binary()}}]} | {error, any()}.
|
||||||
|
|
||||||
@ -725,17 +725,16 @@ terminate(Reason, _StateName,
|
|||||||
role = none}],
|
role = none}],
|
||||||
status_codes = [332,110]}]},
|
status_codes = [332,110]}]},
|
||||||
maps:fold(
|
maps:fold(
|
||||||
fun(LJID, Info, _) ->
|
fun(_, #user{nick = Nick, jid = JID}, _) ->
|
||||||
Nick = Info#user.nick,
|
|
||||||
case Reason of
|
case Reason of
|
||||||
shutdown ->
|
shutdown ->
|
||||||
send_wrapped(jid:replace_resource(StateData#state.jid, Nick),
|
send_wrapped(jid:replace_resource(StateData#state.jid, Nick),
|
||||||
Info#user.jid, Packet,
|
JID, Packet,
|
||||||
?NS_MUCSUB_NODES_PARTICIPANTS,
|
?NS_MUCSUB_NODES_PARTICIPANTS,
|
||||||
StateData);
|
StateData);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
tab_remove_online_user(LJID, StateData)
|
tab_remove_online_user(JID, StateData)
|
||||||
end, [], get_users_and_subscribers(StateData)),
|
end, [], get_users_and_subscribers(StateData)),
|
||||||
add_to_log(room_existence, stopped, StateData),
|
add_to_log(room_existence, stopped, StateData),
|
||||||
case (StateData#state.config)#config.persistent of
|
case (StateData#state.config)#config.persistent of
|
||||||
@ -1159,7 +1158,7 @@ close_room_if_temporary_and_empty(StateData1) ->
|
|||||||
_ -> {next_state, normal_state, StateData1}
|
_ -> {next_state, normal_state, StateData1}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_users_and_subscribers(state()) -> map().
|
-spec get_users_and_subscribers(state()) -> users().
|
||||||
get_users_and_subscribers(StateData) ->
|
get_users_and_subscribers(StateData) ->
|
||||||
OnlineSubscribers = maps:fold(
|
OnlineSubscribers = maps:fold(
|
||||||
fun(LJID, _, Acc) ->
|
fun(LJID, _, Acc) ->
|
||||||
@ -1344,7 +1343,7 @@ set_affiliation_fallback(JID, Affiliation, StateData, Reason) ->
|
|||||||
end,
|
end,
|
||||||
StateData#state{affiliations = Affiliations}.
|
StateData#state{affiliations = Affiliations}.
|
||||||
|
|
||||||
-spec set_affiliations(map(), state()) -> state().
|
-spec set_affiliations(affiliations(), state()) -> state().
|
||||||
set_affiliations(Affiliations,
|
set_affiliations(Affiliations,
|
||||||
#state{config = #config{persistent = false}} = StateData) ->
|
#state{config = #config{persistent = false}} = StateData) ->
|
||||||
set_affiliations_fallback(Affiliations, StateData);
|
set_affiliations_fallback(Affiliations, StateData);
|
||||||
@ -1360,7 +1359,7 @@ set_affiliations(Affiliations, StateData) ->
|
|||||||
set_affiliations_fallback(Affiliations, StateData)
|
set_affiliations_fallback(Affiliations, StateData)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec set_affiliations_fallback(map(), state()) -> state().
|
-spec set_affiliations_fallback(affiliations(), state()) -> state().
|
||||||
set_affiliations_fallback(Affiliations, StateData) ->
|
set_affiliations_fallback(Affiliations, StateData) ->
|
||||||
StateData#state{affiliations = Affiliations}.
|
StateData#state{affiliations = Affiliations}.
|
||||||
|
|
||||||
@ -1414,7 +1413,7 @@ do_get_affiliation_fallback(JID, StateData) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_affiliations(state()) -> map().
|
-spec get_affiliations(state()) -> affiliations().
|
||||||
get_affiliations(#state{config = #config{persistent = false}} = StateData) ->
|
get_affiliations(#state{config = #config{persistent = false}} = StateData) ->
|
||||||
get_affiliations_callback(StateData);
|
get_affiliations_callback(StateData);
|
||||||
get_affiliations(StateData) ->
|
get_affiliations(StateData) ->
|
||||||
@ -1429,7 +1428,7 @@ get_affiliations(StateData) ->
|
|||||||
Affiliations
|
Affiliations
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_affiliations_callback(state()) -> map().
|
-spec get_affiliations_callback(state()) -> affiliations().
|
||||||
get_affiliations_callback(StateData) ->
|
get_affiliations_callback(StateData) ->
|
||||||
StateData#state.affiliations.
|
StateData#state.affiliations.
|
||||||
|
|
||||||
@ -3074,8 +3073,8 @@ send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation,
|
|||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
lists:foreach(fun (J) ->
|
lists:foreach(fun (LJ) ->
|
||||||
#user{nick = Nick} = maps:get(J, StateData#state.users),
|
#user{nick = Nick, jid = J} = maps:get(LJ, StateData#state.users),
|
||||||
add_to_log(kickban, {Nick, Reason, Code}, StateData),
|
add_to_log(kickban, {Nick, Reason, Code}, StateData),
|
||||||
tab_remove_online_user(J, StateData),
|
tab_remove_online_user(J, StateData),
|
||||||
send_kickban_presence1(UJID, J, Reason, Code,
|
send_kickban_presence1(UJID, J, Reason, Code,
|
||||||
@ -4506,7 +4505,7 @@ wrap(From, To, Packet, Node, Id) ->
|
|||||||
id = Id,
|
id = Id,
|
||||||
sub_els = [El]}]}}]}.
|
sub_els = [El]}]}}]}.
|
||||||
|
|
||||||
-spec send_wrapped_multiple(jid(), map(), stanza(), binary(), state()) -> ok.
|
-spec send_wrapped_multiple(jid(), users(), stanza(), binary(), state()) -> ok.
|
||||||
send_wrapped_multiple(From, Users, Packet, Node, State) ->
|
send_wrapped_multiple(From, Users, Packet, Node, State) ->
|
||||||
maps:fold(
|
maps:fold(
|
||||||
fun(_, #user{jid = To}, _) ->
|
fun(_, #user{jid = To}, _) ->
|
||||||
|
@ -53,12 +53,14 @@
|
|||||||
user_send/1, mod_opt_type/1, mod_options/1, depends/2]).
|
user_send/1, mod_opt_type/1, mod_options/1, depends/2]).
|
||||||
|
|
||||||
-record(state,
|
-record(state,
|
||||||
{host = <<"">> :: binary(),
|
{host :: binary(),
|
||||||
send_pings :: boolean(),
|
send_pings :: boolean(),
|
||||||
ping_interval :: non_neg_integer(),
|
ping_interval :: non_neg_integer(),
|
||||||
ping_ack_timeout :: undefined | non_neg_integer(),
|
ping_ack_timeout :: undefined | non_neg_integer(),
|
||||||
timeout_action ::none | kill,
|
timeout_action :: none | kill,
|
||||||
timers = maps:new() :: map()}).
|
timers :: timers()}).
|
||||||
|
|
||||||
|
-type timers() :: #{ljid() => reference()}.
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% API
|
%% API
|
||||||
@ -200,7 +202,7 @@ init_state(Host, Opts) ->
|
|||||||
ping_interval = PingInterval,
|
ping_interval = PingInterval,
|
||||||
timeout_action = TimeoutAction,
|
timeout_action = TimeoutAction,
|
||||||
ping_ack_timeout = PingAckTimeout,
|
ping_ack_timeout = PingAckTimeout,
|
||||||
timers = maps:new()}.
|
timers = #{}}.
|
||||||
|
|
||||||
register_hooks(Host) ->
|
register_hooks(Host) ->
|
||||||
ejabberd_hooks:add(sm_register_connection_hook, Host,
|
ejabberd_hooks:add(sm_register_connection_hook, Host,
|
||||||
@ -228,7 +230,7 @@ unregister_iq_handlers(Host) ->
|
|||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_PING),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_PING),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PING).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PING).
|
||||||
|
|
||||||
-spec add_timer(jid(), non_neg_integer(), map()) -> map().
|
-spec add_timer(jid(), non_neg_integer(), timers()) -> timers().
|
||||||
add_timer(JID, Interval, Timers) ->
|
add_timer(JID, Interval, Timers) ->
|
||||||
LJID = jid:tolower(JID),
|
LJID = jid:tolower(JID),
|
||||||
NewTimers = case maps:find(LJID, Timers) of
|
NewTimers = case maps:find(LJID, Timers) of
|
||||||
@ -241,7 +243,7 @@ add_timer(JID, Interval, Timers) ->
|
|||||||
{ping, JID}),
|
{ping, JID}),
|
||||||
maps:put(LJID, TRef, NewTimers).
|
maps:put(LJID, TRef, NewTimers).
|
||||||
|
|
||||||
-spec del_timer(jid(), map()) -> map().
|
-spec del_timer(jid(), timers()) -> timers().
|
||||||
del_timer(JID, Timers) ->
|
del_timer(JID, Timers) ->
|
||||||
LJID = jid:tolower(JID),
|
LJID = jid:tolower(JID),
|
||||||
case maps:find(LJID, Timers) of
|
case maps:find(LJID, Timers) of
|
||||||
|
Loading…
Reference in New Issue
Block a user