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

Use bare JID as key in state.last_voice_request_time

This commit is contained in:
Maxim Ignatenko 2011-09-20 13:30:00 +03:00
parent c196c1f5e5
commit b1d8168dd3

View File

@ -302,12 +302,13 @@ normal_state({route, From, "",
(StateData#state.config)#config.allow_voice_requests} of (StateData#state.config)#config.allow_voice_requests} of
{true, true} -> {true, true} ->
MinInterval = (StateData#state.config)#config.voice_request_min_interval, MinInterval = (StateData#state.config)#config.voice_request_min_interval,
FromNick = find_nick_by_jid(From, StateData), BareFrom = jlib:jid_remove_resource(jlib:jid_to_lower(From)),
LastTime = last_voice_request_time(FromNick, StateData), LastTime = last_voice_request_time(BareFrom, StateData),
TimeFromLastRequest = timer:now_diff(LastTime, erlang:now()),
if if
timer:now_diff(LastTime, erlang:now()) > MinInterval*1000000 -> TimeFromLastRequest > MinInterval*1000000 ->
send_voice_request(From, StateData), send_voice_request(From, StateData),
update_voice_request_time(FromNick, StateData); update_voice_request_time(BareFrom, StateData);
true -> true ->
ErrText = "Please, wait for a while before sending new voice request", ErrText = "Please, wait for a while before sending new voice request",
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
@ -1555,7 +1556,8 @@ remove_online_user(JID, StateData, Reason) ->
error -> error ->
StateData#state.nicks StateData#state.nicks
end, end,
LastTimes = ?DICT:erase(Nick, StateData#state.last_voice_request_time), LastTimes = ?DICT:erase(jlib:jid_remove_resource(LJID),
StateData#state.last_voice_request_time),
StateData#state{users = Users, nicks = Nicks, StateData#state{users = Users, nicks = Nicks,
last_voice_request_time = LastTimes}. last_voice_request_time = LastTimes}.
@ -2199,18 +2201,7 @@ change_nick(JID, Nick, StateData) ->
?DICT:store(OldNick, OldNickUsers -- [LJID], ?DICT:store(OldNick, OldNickUsers -- [LJID],
StateData#state.nicks)) StateData#state.nicks))
end, end,
LastTimes = NewStateData = StateData#state{users = Users, nicks = Nicks},
case ?DICT:find(OldNick, StateData#state.last_voice_request_time) of
{ok, Time} ->
?DICT:store(
Nick, Time,
?DICT:erase(OldNick, StateData#state.last_voice_request_time)
);
error ->
StateData#state.last_voice_request_time
end,
NewStateData = StateData#state{users = Users, nicks = Nicks,
last_voice_request_time = LastTimes},
send_nick_changing(JID, OldNick, NewStateData, SendOldUnavailable, SendNewAvailable), send_nick_changing(JID, OldNick, NewStateData, SendOldUnavailable, SendNewAvailable),
add_to_log(nickchange, {OldNick, Nick}, StateData), add_to_log(nickchange, {OldNick, Nick}, StateData),
NewStateData. NewStateData.
@ -3882,16 +3873,16 @@ extract_jid_from_voice_approvement(Els) ->
{error, X} {error, X}
end. end.
last_voice_request_time(Nick, StateData) -> last_voice_request_time(BareJID, StateData) ->
case ?DICT:find(Nick, StateData#state.last_voice_request_time) of case ?DICT:find(BareJID, StateData#state.last_voice_request_time) of
{ok, Value} -> {ok, Value} ->
Value; Value;
error -> error ->
0 0
end. end.
update_voice_request_time(Nick, StateData) -> update_voice_request_time(BareJID, StateData) ->
NewDict = ?DICT:store(Nick, erlang:now(), StateData#state.last_voice_request_time), NewDict = ?DICT:store(BareJID, erlang:now(), StateData#state.last_voice_request_time),
StateData#state{last_voice_request_time = NewDict}. StateData#state{last_voice_request_time = NewDict}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%