aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2002-12-22 20:56:29 +0000
committerAlexey Shchepin <alexey@process-one.net>2002-12-22 20:56:29 +0000
commit6cf63ab17f967738f85dee51be116ca0840f0320 (patch)
tree37e8e5fe4440e8211942f180e5055a619781995f /src
parent*** empty log message *** (diff)
*** empty log message ***
SVN Revision: 21
Diffstat (limited to 'src')
-rw-r--r--src/ejabberd_c2s.erl43
-rw-r--r--src/ejabberd_sm.erl16
-rw-r--r--src/mod_roster.erl59
3 files changed, 88 insertions, 30 deletions
diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl
index ddce27c5e..5ac2eb863 100644
--- a/src/ejabberd_c2s.erl
+++ b/src/ejabberd_c2s.erl
@@ -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.
diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl
index ea767a39d..753508693 100644
--- a/src/ejabberd_sm.erl
+++ b/src/ejabberd_sm.erl
@@ -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]),
diff --git a/src/mod_roster.erl b/src/mod_roster.erl
index 6c23a0f14..a25f923e5 100644
--- a/src/mod_roster.erl
+++ b/src/mod_roster.erl
@@ -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.