24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

enable pubsub#deliver_notification checking (thanks to Karim Gemayel)(EJAB-1453)

This commit is contained in:
Christophe Romain 2011-08-31 16:11:01 +02:00
parent 917d1be994
commit 75fc431fb8
3 changed files with 114 additions and 38 deletions

View File

@ -2064,13 +2064,20 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
NodeId = TNode#pubsub_node.id, NodeId = TNode#pubsub_node.id,
Type = TNode#pubsub_node.type, Type = TNode#pubsub_node.type,
Options = TNode#pubsub_node.options, Options = TNode#pubsub_node.options,
BroadcastPayload = case Broadcast of case get_option(Options, deliver_notifications) of
default -> Payload; true ->
broadcast -> Payload; BroadcastPayload = case Broadcast of
PluginPayload -> PluginPayload default -> Payload;
end, broadcast -> Payload;
broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, jlib:jid_tolower(Publisher), BroadcastPayload), PluginPayload -> PluginPayload
set_cached_item(Host, NodeId, ItemId, Publisher, Payload), end,
broadcast_publish_item(Host, Node, NodeId, Type, Options,
Removed, ItemId, jlib:jid_tolower(Publisher),
BroadcastPayload);
false ->
ok
end,
set_cached_item(Host, NodeId, ItemId, Publisher, Payload),
case Result of case Result of
default -> {result, Reply}; default -> {result, Reply};
_ -> {result, Result} _ -> {result, Result}

View File

@ -1877,12 +1877,19 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
NodeId = TNode#pubsub_node.id, NodeId = TNode#pubsub_node.id,
Type = TNode#pubsub_node.type, Type = TNode#pubsub_node.type,
Options = TNode#pubsub_node.options, Options = TNode#pubsub_node.options,
BroadcastPayload = case Broadcast of case get_option(Options, deliver_notifications) of
default -> Payload; true ->
broadcast -> Payload; BroadcastPayload = case Broadcast of
PluginPayload -> PluginPayload default -> Payload;
end, broadcast -> Payload;
broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, jlib:jid_tolower(Publisher), BroadcastPayload), PluginPayload -> PluginPayload
end,
broadcast_publish_item(Host, Node, NodeId, Type, Options,
Removed, ItemId, jlib:jid_tolower(Publisher),
BroadcastPayload);
false ->
ok
end,
set_cached_item(Host, NodeId, ItemId, Publisher, Payload), set_cached_item(Host, NodeId, ItemId, Publisher, Payload),
case Result of case Result of
default -> {result, Reply}; default -> {result, Reply};

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-12-07 13:54:26.000000000 +0100 --- mod_pubsub.erl 2011-08-31 16:08:42.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-12-07 13:59:56.000000000 +0100 +++ mod_pubsub_odbc.erl 2011-08-31 16:08:42.000000000 +0200
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18. %%% XEP-0060 section 12.18.
@ -531,7 +531,30 @@
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups), {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
if if
not SubscribeFeature -> not SubscribeFeature ->
@@ -2231,7 +2047,7 @@ @@ -2021,12 +1837,9 @@
Features = features(Type),
PublishFeature = lists:member("publish", Features),
PublishModel = get_option(Options, publish_model),
+ MaxItems = max_items(Host, Options),
DeliverPayloads = get_option(Options, deliver_payloads),
PersistItems = get_option(Options, persist_items),
- MaxItems = case PersistItems of
- false -> 0;
- true -> max_items(Host, Options)
- end,
PayloadCount = payload_xmlelements(Payload),
PayloadSize = size(term_to_binary(Payload))-2, % size(term_to_binary([])) == 2
PayloadMaxSize = get_option(Options, max_payload_size),
@@ -2077,7 +1890,7 @@
false ->
ok
end,
- set_cached_item(Host, NodeId, ItemId, Publisher, Payload),
+ set_cached_item(Host, NodeId, ItemId, Publisher, Payload),
case Result of
default -> {result, Reply};
_ -> {result, Result}
@@ -2241,7 +2054,7 @@
%% <p>The permission are not checked in this function.</p> %% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right %% @todo We probably need to check that the user doing the query has the right
%% to read the items. %% to read the items.
@ -540,7 +563,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> get_max_items_node(Host); SMaxItems == "" -> get_max_items_node(Host);
@@ -2245,12 +2061,13 @@ @@ -2255,12 +2068,13 @@
{error, Error} -> {error, Error} ->
{error, Error}; {error, Error};
_ -> _ ->
@ -555,7 +578,7 @@
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups), {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
if if
not RetreiveFeature -> not RetreiveFeature ->
@@ -2263,11 +2080,11 @@ @@ -2273,11 +2087,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -569,7 +592,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2280,7 +2097,8 @@ @@ -2290,7 +2104,8 @@
%% number of items sent to MaxItems: %% number of items sent to MaxItems:
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
[{xmlelement, "items", nodeAttr(Node), [{xmlelement, "items", nodeAttr(Node),
@ -579,7 +602,7 @@
Error -> Error ->
Error Error
end end
@@ -2302,10 +2120,15 @@ @@ -2312,10 +2127,15 @@
Error -> Error Error -> Error
end. end.
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) -> get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
@ -596,11 +619,13 @@
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any() %% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
@@ -2318,16 +2141,27 @@ @@ -2327,31 +2147,29 @@
%% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p> %% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature %% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) -> -send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, last) ->
- case get_cached_item(Host, NodeId) of - case get_cached_item(Host, NodeId) of
+send_items(Host, Node, NodeId, Type, LJID, last) ->
+ Stanza = case get_cached_item(Host, NodeId) of + Stanza = case get_cached_item(Host, NodeId) of
undefined -> undefined ->
- send_items(Host, Node, NodeId, Type, LJID, 1); - send_items(Host, Node, NodeId, Type, LJID, 1);
@ -622,15 +647,52 @@
+ event_stanza_with_delay( + event_stanza_with_delay(
[{xmlelement, "items", nodeAttr(Node), [{xmlelement, "items", nodeAttr(Node),
- itemsEls([LastItem])}], ModifNow, ModifUSR), - itemsEls([LastItem])}], ModifNow, ModifUSR),
- ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza) - case is_tuple(Host) of
- false ->
- ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza);
- true ->
- case ejabberd_sm:get_session_pid(U,S,R) of
- C2SPid when is_pid(C2SPid) ->
- ejabberd_c2s:broadcast(C2SPid,
- {pep_message, binary_to_list(Node)++"+notify"},
- _Sender = service_jid(Host),
- Stanza);
- _ ->
- ok
- end
- end
- end; - end;
-send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, Number) ->
+ itemsEls([LastItem])}], ModifNow, ModifUSR) + itemsEls([LastItem])}], ModifNow, ModifUSR)
+ end, + end,
+ ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza); + ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza);
send_items(Host, Node, NodeId, Type, LJID, Number) -> +send_items(Host, Node, NodeId, Type, LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} -> {result, []} ->
@@ -2453,7 +2287,8 @@ [];
@@ -2374,20 +2192,7 @@
[{xmlelement, "items", nodeAttr(Node),
itemsEls(ToSend)}])
end,
- case is_tuple(Host) of
- false ->
- ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza);
- true ->
- case ejabberd_sm:get_session_pid(U,S,R) of
- C2SPid when is_pid(C2SPid) ->
- ejabberd_c2s:broadcast(C2SPid,
- {pep_message, binary_to_list(Node)++"+notify"},
- _Sender = service_jid(Host),
- Stanza);
- _ ->
- ok
- end
- end.
+ ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza).
%% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response}
%% Host = host()
@@ -2489,7 +2294,8 @@
error -> error ->
{error, ?ERR_BAD_REQUEST}; {error, ?ERR_BAD_REQUEST};
_ -> _ ->
@ -640,7 +702,7 @@
case lists:member(Owner, Owners) of case lists:member(Owner, Owners) of
true -> true ->
OwnerJID = jlib:make_jid(Owner), OwnerJID = jlib:make_jid(Owner),
@@ -2463,24 +2298,7 @@ @@ -2499,24 +2305,7 @@
end, end,
lists:foreach( lists:foreach(
fun({JID, Affiliation}) -> fun({JID, Affiliation}) ->
@ -666,7 +728,7 @@
end, FilteredEntities), end, FilteredEntities),
{result, []}; {result, []};
_ -> _ ->
@@ -2533,11 +2351,11 @@ @@ -2569,11 +2358,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -680,7 +742,7 @@
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)}, OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
{"subid", SubID}|nodeAttr(Node)], {"subid", SubID}|nodeAttr(Node)],
[XdataEl]}, [XdataEl]},
@@ -2563,7 +2381,7 @@ @@ -2599,7 +2388,7 @@
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -689,7 +751,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -2592,7 +2410,7 @@ @@ -2628,7 +2417,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) -> write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error(?ERR_BAD_REQUEST, "invalid-options")}; {error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
@ -698,7 +760,7 @@
{error, notfound} -> {error, notfound} ->
{error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2760,8 +2578,8 @@ @@ -2796,8 +2585,8 @@
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]}, {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza) ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
end, end,
@ -709,7 +771,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3116,7 +2934,7 @@ @@ -3152,7 +2941,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]} {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end, end,
@ -718,7 +780,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3130,9 +2948,9 @@ @@ -3166,9 +2955,9 @@
get_options_for_subs(NodeID, Subs) -> get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -730,7 +792,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3321,6 +3139,30 @@ @@ -3357,6 +3146,30 @@
Result Result
end. end.
@ -761,7 +823,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3717,7 +3559,13 @@ @@ -3753,7 +3566,13 @@
tree_action(Host, Function, Args) -> tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end, Fun = fun() -> tree_call(Host, Function, Args) end,
@ -776,7 +838,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3737,13 +3585,13 @@ @@ -3773,13 +3592,13 @@
node_action(Host, Type, Function, Args) -> node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -792,7 +854,7 @@
case tree_call(Host, get_node, [Host, Node]) of case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) -> N when is_record(N, pubsub_node) ->
case Action(N) of case Action(N) of
@@ -3755,13 +3603,19 @@ @@ -3791,13 +3610,19 @@
Error Error
end end
end, Trans). end, Trans).
@ -816,7 +878,7 @@
{result, Result} -> {result, Result}; {result, Result} -> {result, Result};
{error, Error} -> {error, Error}; {error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result}; {atomic, {result, Result}} -> {result, Result};
@@ -3769,6 +3623,15 @@ @@ -3805,6 +3630,15 @@
{aborted, Reason} -> {aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};
@ -832,7 +894,7 @@
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, ?ERR_INTERNAL_SERVER_ERROR};
@@ -3777,6 +3640,17 @@ @@ -3813,6 +3647,17 @@
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.