Ejabberd roster关系改变,发送type=unavailable 的presence

在ejabberd 2.1.3版本中的ejabberd_c2s.erl中,有这么一段代码:

 

 

roster_change(IJID, ISubscription, StateData) ->
    LIJID = jlib:jid_tolower(IJID),
    IsFrom = (ISubscription == both) or (ISubscription == from),
    IsTo   = (ISubscription == both) or (ISubscription == to),
    OldIsFrom = ?SETS:is_element(LIJID, StateData#state.pres_f),
    FSet = if IsFrom ->
      ?SETS:add_element(LIJID, StateData#state.pres_f);
     true ->
      remove_element(LIJID, StateData#state.pres_f)
     end,
 TSet = if IsTo ->
      ?SETS:add_element(LIJID, StateData#state.pres_t);
     true ->
      remove_element(LIJID, StateData#state.pres_t)
     end,
    case StateData#state.pres_last of
  undefined -> StateData#state{pres_f = FSet, pres_t = TSet};
  P ->
   ?DEBUG("roster changed for ~p~n", [StateData#state.user]),
   From = StateData#state.jid,
   To = jlib:make_jid(IJID),
   Cond1 = (not StateData#state.pres_invis) and IsFrom and (not OldIsFrom),
   Cond2 = (not IsFrom) and OldIsFrom and
      (?SETS:is_element(LIJID, StateData#state.pres_a) or
        ?SETS:is_element(LIJID, StateData#state.pres_i)),
   if Cond1 ->
       ?DEBUG("C1: ~p~n", [LIJID]),
       case ejabberd_hooks:run_fold(privacy_check_packet,
            StateData#state.server,
            allow,
            [StateData#state.user,
             StateData#state.server,
             StateData#state.privacy_list,
             {From, To, P},
             out]) of
        deny ->
         ok;
        allow ->
         ejabberd_router:route(From, To, P)
       end,
       A = ?SETS:add_element(LIJID, StateData#state.pres_a),
       StateData#state{pres_a = A, pres_f = FSet, pres_t = TSet};
      Cond2 ->
       ?DEBUG("C2: ~p~n", [LIJID]),
       PU = {xmlelement, "presence", [{"type", "unavailable"}], []},
       case ejabberd_hooks:run_fold(privacy_check_packet,
            StateData#state.server,
            allow,
            [StateData#state.user,
             StateData#state.server,
             StateData#state.privacy_list,
             {From, To, PU},
             out]) of
        deny ->
         ok;
        allow ->
         ejabberd_router:route(From, To, PU)
       end,
       I = remove_element(LIJID, StateData#state.pres_i),
       A = remove_element(LIJID, StateData#state.pres_a),
       StateData#state{pres_i = I, pres_a = A, pres_f = FSet, pres_t = TSet};
      true ->
       StateData#state{pres_f = FSet, pres_t = TSet}
     end
    end.

 

此代码的功能是当用户的roster发生变化时,会发送一些package给用户.

 

前几日在测时发现,删除好友时,这个unavailable类的presence 发送的类乎有点问题:

1.当A删除好友B时,B总是收到A发送过来的 <presence type="unavailable"/>,结果导致,A在B这边下线了.这样是不对的.

2.所以个人觉得,将发送unavailable的这一行去掉,就是说无论好友关系发生什么变化,都不发送unavaible,至于客户端要怎么样展示的效果,可以由客户端自已去操作.

 

 

你可能感兴趣的:(ejabberd)