*** empty log message ***

SVN Revision: 21
This commit is contained in:
Alexey Shchepin 2002-12-22 20:56:29 +00:00
parent ae30798efd
commit 6cf63ab17f
3 changed files with 88 additions and 30 deletions

View File

@ -279,6 +279,16 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
_ ->
{true, Attrs, StateData}
end;
"broadcast" ->
?DEBUG("broadcast!!!!!!!!!!!~n~p~n", [Els]),
NewSt = case Els of
[{item, IJID, ISubscription}] ->
roster_change(IJID, ISubscription,
StateData);
_ ->
StateData
end,
{false, Attrs, NewSt};
_ ->
{true, Attrs, StateData}
end,
@ -560,5 +570,38 @@ remove_element(E, Set) ->
end.
roster_change(IJID, ISubscription, StateData) ->
LIJID = jlib:jid_tolower(IJID),
case StateData#state.pres_last of
unknown ->
StateData;
P ->
?DEBUG("roster changed for ~p~n", [StateData#state.user]),
From = {StateData#state.user, StateData#state.server, ""},
Cond1 = (not StateData#state.pres_invis)
and ((ISubscription == both) or (ISubscription == from)),
Cond2 = ((ISubscription == none) or (ISubscription == to))
and (?SETS:is_element(From, StateData#state.pres_a) or
?SETS:is_element(From, StateData#state.pres_i)),
if
Cond1 ->
?DEBUG("C1: ~p~n", [LIJID]),
ejabberd_router:route(From, IJID, P),
A = ?SETS:add_element(LIJID,
StateData#state.pres_a),
StateData#state{pres_a = A};
Cond2 ->
?DEBUG("C2: ~p~n", [LIJID]),
ejabberd_router:route(From, IJID, P),
I = remove_element(LIJID,
StateData#state.pres_i),
A = remove_element(LIJID,
StateData#state.pres_a),
StateData#state{pres_i = I,
pres_a = A};
true ->
StateData
end
end.

View File

@ -214,6 +214,14 @@ do_route(From, To, Packet) ->
"iq" ->
% TODO
ok;
"broadcast" ->
lists:foreach(
fun(R) ->
ejabberd_sm ! {route,
From,
{User, Server, R},
Packet}
end, get_user_resources(User));
_ ->
ok
end;
@ -221,15 +229,7 @@ do_route(From, To, Packet) ->
case mnesia:transaction(F) of
{atomic, {local, Pid}} ->
?DEBUG("sending to process ~p~n", [Pid]),
% TODO
Pid ! {route, From, To, Packet},
%NewAttrs =
% jlib:replace_from_to_attrs(jlib:jid_to_string(From),
% jlib:jid_to_string(To),
% Attrs),
%ejabberd_c2s:send_element(
% Pid, {xmlelement, Name, NewAttrs, Els}),
%?DEBUG("sended~n", []),
ok;
{atomic, {remote, Node}} ->
?DEBUG("sending to node ~p~n", [Node]),

View File

@ -310,12 +310,10 @@ in_subscription(User, From, Type) ->
S = I#roster.subscription,
if
(S == both) or (S == from) ->
ejabberd_router:route(
{User, ?MYNAME, ""}, {FU, FS, ""},
{xmlelement, "presence",
[{"type", "subscribed"}], []}),
% TODO: update presence
false;
{update,
{xmlelement, "presence",
[{"type", "subscribed"}], []},
I};
true ->
true
end;
@ -323,12 +321,10 @@ in_subscription(User, From, Type) ->
S = I#roster.subscription,
if
(S == none) or (S == to) ->
ejabberd_router:route(
{User, ?MYNAME, ""}, {FU, FS, ""},
{xmlelement, "presence",
[{"type", "unsubscribed"}], []}),
% TODO: update presence
false;
{update,
{xmlelement, "presence",
[{"type", "unsubscribed"}], []},
I};
true ->
true
end;
@ -360,6 +356,14 @@ in_subscription(User, From, Type) ->
true;
{atomic, false} ->
false;
{atomic, {update, Presence, Item}} ->
ejabberd_router:route({User, ?MYNAME, ""}, {FU, FS, ""}, Presence),
ejabberd_sm ! {route, {"", "", ""}, {User, "", ""},
{xmlelement, "broadcast", [],
[{item,
Item#roster.jid,
Item#roster.subscription}]}},
false;
{atomic, {push, Item}} ->
push_item(User, {"", ?MYNAME, ""}, Item),
true;
@ -387,12 +391,12 @@ out_subscription(User, JID, Type) ->
if Item == false ->
ok;
true ->
NewItem =
{NewItem, Update} =
case Type of
subscribe ->
Item#roster{ask = subscribe};
{Item#roster{ask = subscribe}, false};
unsubscribe ->
Item#roster{ask = unsubscribe};
{Item#roster{ask = unsubscribe}, false};
subscribed ->
S = Item#roster.subscription,
NS = case S of
@ -401,8 +405,9 @@ out_subscription(User, JID, Type) ->
_ -> S
end,
% TODO: update presence
Item#roster{subscription = NS,
ask = none};
{Item#roster{subscription = NS,
ask = none},
true};
unsubscribed ->
S = Item#roster.subscription,
NS = case S of
@ -411,19 +416,29 @@ out_subscription(User, JID, Type) ->
_ -> S
end,
% TODO: update presence
Item#roster{subscription = NS,
ask = none}
{Item#roster{subscription = NS,
ask = none},
true}
end,
mnesia:write(NewItem),
{push, NewItem}
{push, NewItem, Update}
end
end,
case mnesia:transaction(F) of
{atomic, ok} ->
ok;
{atomic, {push, Item}} ->
{atomic, {push, Item, Update}} ->
push_item(User, {"", ?MYNAME, ""}, Item),
true;
if
Update ->
ejabberd_sm ! {route, {"", "", ""}, {User, "", ""},
{xmlelement, "broadcast", [],
[{item,
Item#roster.jid,
Item#roster.subscription}]}};
true ->
ok
end;
_ ->
false
end.