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

Code cleanup

This commit is contained in:
Evgeniy Khramtsov 2011-09-26 18:44:41 +10:00
parent f17a531e15
commit e7d12f4b9e

View File

@ -306,16 +306,24 @@ 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, NewStateData1} = last_voice_request_time( NowPriority = -now_to_usec(now()),
BareFrom, StateData), CleanPriority =
TimeFromLastRequest = NowPriority + MinInterval*1000000,
(now_to_usec(now()) - LastTime) div 1000000, Times = clean_treap(
if TimeFromLastRequest > MinInterval -> StateData#state.last_voice_request_time,
send_voice_request( CleanPriority),
From, NewStateData1), case treap:lookup(BareFrom, Times) of
update_voice_request_time( error ->
BareFrom, NewStateData1); Times1 = treap:insert(
true -> BareFrom,
NowPriority,
true, Times),
NSD = StateData#state{
last_voice_request_time =
Times1},
send_voice_request(From, NSD),
NSD;
{ok, _, _} ->
ErrText = "Please, wait for " ErrText = "Please, wait for "
"a while before sending " "a while before sending "
"new voice request", "new voice request",
@ -326,7 +334,9 @@ normal_state({route, From, "",
ejabberd_router:route( ejabberd_router:route(
StateData#state.jid, StateData#state.jid,
From, Err), From, Err),
NewStateData1 StateData#state{
last_voice_request_time =
Times}
end; end;
false -> false ->
ErrText = "Voice requests are " ErrText = "Voice requests are "
@ -3843,42 +3853,26 @@ extract_jid_from_voice_approvement(Els) ->
Acc Acc
end, error, Els). end, error, Els).
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
{ok, Value, _} ->
{-Value, NewStateData};
error ->
{0, NewStateData}
end.
update_voice_request_time(BareJID, StateData) ->
Times = treap:insert(BareJID, -now_to_usec(now()), true,
StateData#state.last_voice_request_time),
StateData#state{last_voice_request_time = Times}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Invitation support % Invitation support
is_invitation(Els) -> is_invitation(Els) ->
try lists:foldl(
case xml:remove_cdata(Els) of fun({xmlelement, "x", Attrs, _} = El, false) ->
[{xmlelement, "x", _Attrs1, Els1} = XEl] -> case xml:get_attr_s("xmlns", Attrs) of
case xml:get_tag_attr_s("xmlns", XEl) of ?NS_MUC_USER ->
?NS_MUC_USER -> case xml:get_subtag(El, "invite") of
case xml:remove_cdata(Els1) of false ->
[{xmlelement, "invite", _, _}] -> false;
true _ ->
end true
end end;
end _ ->
catch false
error: _ -> end;
false (_, Acc) ->
end. Acc
end, false, Els).
check_invitation(From, Els, Lang, StateData) -> check_invitation(From, Els, Lang, StateData) ->
FAffiliation = get_affiliation(From, StateData), FAffiliation = get_affiliation(From, StateData),