diff options
author | Pablo Polvorin <pablo.polvorin@process-one.net> | 2009-01-12 21:15:44 +0300 |
---|---|---|
committer | Pablo Polvorin <pablo.polvorin@process-one.net> | 2009-01-12 21:15:44 +0300 |
commit | 49210e3099ce0d2cc95b77d065eee09fee2bec2f (patch) | |
tree | dc93560b3656df04a153acedacbd87c91f0e99e7 /src/ejabberd_c2s.erl | |
parent | 96c0ff44f957b5cc839ea907f1673c12a0a7c60a (diff) |
Apply commit 1212 (caps handling fix), was incorrectly overwritten on 1770.
SVN Revision: 1807
Diffstat (limited to 'src/ejabberd_c2s.erl')
-rw-r--r-- | src/ejabberd_c2s.erl | 76 |
1 files changed, 23 insertions, 53 deletions
diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 266130320..7e3be2d8e 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -37,8 +37,7 @@ send_element/2, socket_type/0, get_presence/1, - get_subscribed/1, - get_subscribed_and_online/1]). + get_subscribed/1]). %% gen_fsm callbacks -export([init/1, @@ -88,7 +87,6 @@ pres_f = ?SETS:new(), pres_a = ?SETS:new(), pres_i = ?SETS:new(), - pres_available = ?DICT:new(), pres_last, pres_pri, pres_timestamp, pres_invis = false, @@ -212,13 +210,8 @@ init([{SockMod, Socket}, Opts]) -> end. %% Return list of all available resources of contacts, -%% in form [{JID, Caps}]. get_subscribed(FsmRef) -> - gen_fsm:sync_send_all_state_event( - FsmRef, get_subscribed, 1000). -get_subscribed_and_online(FsmRef) -> - gen_fsm:sync_send_all_state_event( - FsmRef, get_subscribed_and_online, 1000). + gen_fsm:sync_send_all_state_event(FsmRef, get_subscribed, 1000). %%---------------------------------------------------------------------- @@ -969,29 +962,9 @@ handle_sync_event({get_presence}, _From, StateName, StateData) -> fsm_reply(Reply, StateName, StateData); handle_sync_event(get_subscribed, _From, StateName, StateData) -> - Subscribed = StateData#state.pres_f, - Online = StateData#state.pres_available, - Pred = fun({U, S, _} = User, _Caps) -> - ?SETS:is_element({U, S, undefined}, - Subscribed) orelse - ?SETS:is_element(User, Subscribed) - end, - SubscribedAndOnline = ?DICT:filter(Pred, Online), - SubscribedWithCaps = ?SETS:fold(fun(User, Acc) -> - [{User, undefined}|Acc] - end, ?DICT:to_list(SubscribedAndOnline), Subscribed), - {reply, SubscribedWithCaps, StateName, StateData}; - -handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) -> - Subscribed = StateData#state.pres_f, - Online = StateData#state.pres_available, - Pred = fun({U, S, _R} = User, _Caps) -> - ?SETS:is_element({U, S, undefined}, - Subscribed) orelse - ?SETS:is_element(User, Subscribed) - end, - SubscribedAndOnline = ?DICT:filter(Pred, Online), - {reply, ?DICT:to_list(SubscribedAndOnline), StateName, StateData}; + Subscribed = ?SETS:to_list(StateData#state.pres_f), + {reply, Subscribed, StateName, StateData}; + handle_sync_event(_Event, _From, StateName, StateData) -> Reply = ok, @@ -1084,43 +1057,40 @@ handle_info({route, From, To, Packet}, StateName, StateData) -> LBFrom = jlib:short_prepd_bare_jid(From), %% Note contact availability Els = Packet#xmlel.children, - Caps = mod_caps:read_caps(Els), - ServerString = binary_to_list(StateData#state.server), - mod_caps:note_caps(ServerString, From, Caps), - NewAvailable = case exmpp_presence:get_type(Packet) of - 'unavailable' -> - ?DICT:erase(LFrom, StateData#state.pres_available); - _ -> - %?DICT:store(LFrom, Caps, StateData#state.pres_available) - StateData#state.pres_available - end, - NewStateData = StateData#state{pres_available = NewAvailable}, + case exmpp_presence:get_type(Packet) of + 'unavailable' -> + mod_caps:clear_caps(From); + _ -> + ServerString = binary_to_list(StateData#state.server), + Caps = mod_caps:read_caps(Els), + mod_caps:note_caps(ServerString, From, Caps) + end, case ?SETS:is_element( - LFrom, NewStateData#state.pres_a) orelse + LFrom, StateData#state.pres_a) orelse ?SETS:is_element( - LBFrom, NewStateData#state.pres_a) of + LBFrom, StateData#state.pres_a) of true -> - {true, Attrs, NewStateData}; + {true, Attrs, StateData}; false -> case ?SETS:is_element( - LFrom, NewStateData#state.pres_f) of + LFrom, StateData#state.pres_f) of true -> A = ?SETS:add_element( LFrom, - NewStateData#state.pres_a), + StateData#state.pres_a), {true, Attrs, - NewStateData#state{pres_a = A}}; + StateData#state{pres_a = A}}; false -> case ?SETS:is_element( - LBFrom, NewStateData#state.pres_f) of + LBFrom, StateData#state.pres_f) of true -> A = ?SETS:add_element( LBFrom, - NewStateData#state.pres_a), + StateData#state.pres_a), {true, Attrs, - NewStateData#state{pres_a = A}}; + StateData#state{pres_a = A}}; false -> - {true, Attrs, NewStateData} + {true, Attrs, StateData} end end end; |