mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Use maps instead of dicts in HTTP upload modules
ejabberd currently depends on Erlang/OTP 17.1 or higher, so we can now use maps.
This commit is contained in:
parent
6ac839dd76
commit
63777f830d
@ -108,7 +108,7 @@
|
||||
get_url :: binary(),
|
||||
service_url :: binary() | undefined,
|
||||
thumbnail :: boolean(),
|
||||
slots = dict:new() :: term()}). % dict:dict() requires Erlang 17.
|
||||
slots = #{} :: map()}).
|
||||
|
||||
-record(media_info,
|
||||
{type :: binary(),
|
||||
@ -676,18 +676,18 @@ create_slot(#state{service_url = ServiceURL},
|
||||
-spec add_slot(slot(), pos_integer(), timer:tref(), state()) -> state().
|
||||
|
||||
add_slot(Slot, Size, Timer, #state{slots = Slots} = State) ->
|
||||
NewSlots = dict:store(Slot, {Size, Timer}, Slots),
|
||||
NewSlots = maps:put(Slot, {Size, Timer}, Slots),
|
||||
State#state{slots = NewSlots}.
|
||||
|
||||
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error.
|
||||
|
||||
get_slot(Slot, #state{slots = Slots}) ->
|
||||
dict:find(Slot, Slots).
|
||||
maps:find(Slot, Slots).
|
||||
|
||||
-spec del_slot(slot(), state()) -> state().
|
||||
|
||||
del_slot(Slot, #state{slots = Slots} = State) ->
|
||||
NewSlots = dict:erase(Slot, Slots),
|
||||
NewSlots = maps:remove(Slot, Slots),
|
||||
State#state{slots = NewSlots}.
|
||||
|
||||
-spec slot_el(slot() | binary(), state() | binary(), binary()) -> xmlel().
|
||||
|
@ -62,7 +62,7 @@
|
||||
access_hard_quota :: atom(),
|
||||
max_days :: pos_integer() | infinity,
|
||||
docroot :: binary(),
|
||||
disk_usage = dict:new() :: term(),
|
||||
disk_usage = #{} :: map(),
|
||||
timers :: [timer:tref()]}).
|
||||
|
||||
-type state() :: #state{}.
|
||||
@ -172,7 +172,7 @@ handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
|
||||
_ ->
|
||||
0
|
||||
end,
|
||||
OldSize = case dict:find({U, S}, DiskUsage) of
|
||||
OldSize = case maps:find({U, S}, DiskUsage) of
|
||||
{ok, Value} ->
|
||||
Value;
|
||||
error ->
|
||||
@ -202,7 +202,7 @@ handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
|
||||
enforce_quota(Path, Size, OldSize, SoftQuota, HardQuota)
|
||||
end,
|
||||
NewDiskUsage = if is_integer(NewSize) ->
|
||||
dict:store({U, S}, NewSize, DiskUsage);
|
||||
maps:put({U, S}, NewSize, DiskUsage);
|
||||
true ->
|
||||
DiskUsage
|
||||
end,
|
||||
|
Loading…
Reference in New Issue
Block a user