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

Use treap correctly

This commit is contained in:
Maxim Ignatenko 2011-09-26 11:13:40 +03:00
parent ff57c8a58c
commit f17a531e15

View File

@ -306,16 +306,15 @@ normal_state({route, From, "",
#config.voice_request_min_interval, #config.voice_request_min_interval,
BareFrom = jlib:jid_remove_resource( BareFrom = jlib:jid_remove_resource(
jlib:jid_tolower(From)), jlib:jid_tolower(From)),
LastTime = last_voice_request_time( {LastTime, NewStateData1} = last_voice_request_time(
BareFrom, StateData), BareFrom, StateData),
TimeFromLastRequest = TimeFromLastRequest =
timer:now_diff( (now_to_usec(now()) - LastTime) div 1000000,
now(), LastTime) div 1000000,
if TimeFromLastRequest > MinInterval -> if TimeFromLastRequest > MinInterval ->
send_voice_request( send_voice_request(
From, StateData), From, NewStateData1),
update_voice_request_time( update_voice_request_time(
BareFrom, StateData); BareFrom, NewStateData1);
true -> true ->
ErrText = "Please, wait for " ErrText = "Please, wait for "
"a while before sending " "a while before sending "
@ -327,7 +326,7 @@ normal_state({route, From, "",
ejabberd_router:route( ejabberd_router:route(
StateData#state.jid, StateData#state.jid,
From, Err), From, Err),
StateData NewStateData1
end; end;
false -> false ->
ErrText = "Voice requests are " ErrText = "Voice requests are "
@ -1579,10 +1578,7 @@ remove_online_user(JID, StateData, Reason) ->
error -> error ->
StateData#state.nicks StateData#state.nicks
end, end,
LastTimes = treap:delete(jlib:jid_remove_resource(LJID), StateData#state{users = Users, nicks = Nicks}.
StateData#state.last_voice_request_time),
StateData#state{users = Users, nicks = Nicks,
last_voice_request_time = LastTimes}.
filter_presence({xmlelement, "presence", Attrs, Els}) -> filter_presence({xmlelement, "presence", Attrs, Els}) ->
@ -3848,17 +3844,21 @@ extract_jid_from_voice_approvement(Els) ->
end, error, Els). end, error, Els).
last_voice_request_time(BareJID, StateData) -> last_voice_request_time(BareJID, StateData) ->
Timeout = (StateData#state.config)#config.voice_request_min_interval,
Times = clean_treap(StateData#state.last_voice_request_time,
-now_to_usec(now()) + Timeout*1000000),
NewStateData = StateData#state{last_voice_request_time = Times},
case treap:lookup(BareJID, StateData#state.last_voice_request_time) of case treap:lookup(BareJID, StateData#state.last_voice_request_time) of
{ok, _, Value} -> {ok, Value, _} ->
Value; {-Value, NewStateData};
error -> error ->
{0, 0, 0} {0, NewStateData}
end. end.
update_voice_request_time(BareJID, StateData) -> update_voice_request_time(BareJID, StateData) ->
NewDict = treap:insert(BareJID, {0, 0}, erlang:now(), Times = treap:insert(BareJID, -now_to_usec(now()), true,
StateData#state.last_voice_request_time), StateData#state.last_voice_request_time),
StateData#state{last_voice_request_time = NewDict}. StateData#state{last_voice_request_time = Times}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Invitation support % Invitation support