]> granicus.if.org Git - ejabberd/commitdiff
enable pubsub#deliver_notification checking (thanks to Karim Gemayel)(EJAB-1453)
authorChristophe Romain <christophe.romain@process-one.net>
Wed, 31 Aug 2011 14:11:01 +0000 (16:11 +0200)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 31 Aug 2011 14:11:01 +0000 (16:11 +0200)
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/pubsub_odbc.patch

index 38d56d17c6f19a6ad9dddf8def618f6bdf474e63..705c6e67a16fc00e56bc77fee49af6cb320c6e19 100644 (file)
@@ -2064,13 +2064,20 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
            NodeId = TNode#pubsub_node.id,
            Type = TNode#pubsub_node.type,
            Options = TNode#pubsub_node.options,
-           BroadcastPayload = case Broadcast of
-               default -> Payload;
-               broadcast -> Payload;
-               PluginPayload -> PluginPayload
-           end,
-           broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, jlib:jid_tolower(Publisher), BroadcastPayload),
-           set_cached_item(Host, NodeId, ItemId, Publisher, Payload),
+           case get_option(Options, deliver_notifications) of
+                       true ->
+                               BroadcastPayload = case Broadcast of
+                                       default -> Payload;
+                                       broadcast -> Payload;
+                                       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),
            case Result of
                default -> {result, Reply};
                _ -> {result, Result}
index 2337c26d382757063664ebd3bc7b0adad7dc7236..9c24456cc9309859c820c3927f991911cab638b4 100644 (file)
@@ -1877,12 +1877,19 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
            NodeId = TNode#pubsub_node.id,
            Type = TNode#pubsub_node.type,
            Options = TNode#pubsub_node.options,
-           BroadcastPayload = case Broadcast of
-               default -> Payload;
-               broadcast -> Payload;
-               PluginPayload -> PluginPayload
-           end,
-           broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, jlib:jid_tolower(Publisher), BroadcastPayload),
+           case get_option(Options, deliver_notifications) of
+                       true ->
+                               BroadcastPayload = case Broadcast of
+                                       default -> Payload;
+                                       broadcast -> Payload;
+                                       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),
            case Result of
                default -> {result, Reply};
index 998132f747eef0f5c366b41bace8c8bed9384b3f..ef2ba0eee1de8718f290bac83bd4ba99662f56cd 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2010-12-07 13:54:26.000000000 +0100
-+++ mod_pubsub_odbc.erl        2010-12-07 13:59:56.000000000 +0100
+--- mod_pubsub.erl     2011-08-31 16:08:42.000000000 +0200
++++ mod_pubsub_odbc.erl        2011-08-31 16:08:42.000000000 +0200
 @@ -42,7 +42,7 @@
  %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
  %%% XEP-0060 section 12.18.
                    {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
                    if
                        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>
  %% @todo We probably need to check that the user doing the query has the right
  %% to read the items.
      MaxItems =
        if
            SMaxItems == "" -> get_max_items_node(Host);
-@@ -2245,12 +2061,13 @@
+@@ -2255,12 +2068,13 @@
        {error, Error} ->
            {error, Error};
        _ ->
                     {PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
                     if
                         not RetreiveFeature ->
-@@ -2263,11 +2080,11 @@
+@@ -2273,11 +2087,11 @@
                             node_call(Type, get_items,
                                       [NodeId, From,
                                        AccessModel, PresenceSubscription, RosterGroup,
                    SendItems = case ItemIDs of
                        [] -> 
                            Items;
-@@ -2280,7 +2097,8 @@
+@@ -2290,7 +2104,8 @@
                    %% number of items sent to MaxItems:
                    {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
                                [{xmlelement, "items", nodeAttr(Node),
                Error ->
                    Error
            end
-@@ -2302,10 +2120,15 @@
+@@ -2312,10 +2127,15 @@
        Error -> Error
      end.
  get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
  
  
  %% @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>
  %% @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
++send_items(Host, Node, NodeId, Type, LJID, last) ->
 +    Stanza = case get_cached_item(Host, NodeId) of
        undefined ->
 -          send_items(Host, Node, NodeId, Type, LJID, 1);
 +          event_stanza_with_delay(
                [{xmlelement, "items", nodeAttr(Node),
 -                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;
+-send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, Number) ->
 +                itemsEls([LastItem])}], ModifNow, ModifUSR)
 +    end,
 +    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
        {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, ?ERR_BAD_REQUEST};
        _ ->
                        case lists:member(Owner, Owners) of
                            true ->
                                OwnerJID = jlib:make_jid(Owner),
-@@ -2463,24 +2298,7 @@
+@@ -2499,24 +2305,7 @@
                                    end,
                                lists:foreach(
                                    fun({JID, Affiliation}) ->
                                    end, FilteredEntities),
                                {result, []};
                            _ ->
-@@ -2533,11 +2351,11 @@
+@@ -2569,11 +2358,11 @@
      end.
  
  read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
            OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
                                                 {"subid", SubID}|nodeAttr(Node)],
                         [XdataEl]},
-@@ -2563,7 +2381,7 @@
+@@ -2599,7 +2388,7 @@
      end.
  
  set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
        {result, GoodSubOpts} -> GoodSubOpts;
        _ -> invalid
      end,
-@@ -2592,7 +2410,7 @@
+@@ -2628,7 +2417,7 @@
  write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
      {error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
  write_sub(Subscriber, NodeID, SubID, Options) ->
        {error, notfound} ->
            {error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
        {result, _} ->
-@@ -2760,8 +2578,8 @@
+@@ -2796,8 +2585,8 @@
                                     {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
                ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
            end,
                                true ->
                                    Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
  
-@@ -3116,7 +2934,7 @@
+@@ -3152,7 +2941,7 @@
                        {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
            end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
        end,
        {result, CollSubs} -> CollSubs;
        _ -> []
      end.
-@@ -3130,9 +2948,9 @@
+@@ -3166,9 +2955,9 @@
  
  get_options_for_subs(NodeID, Subs) ->
      lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
                            _ -> Acc
                        end;
                    (_, Acc) ->
-@@ -3321,6 +3139,30 @@
+@@ -3357,6 +3146,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -3717,7 +3559,13 @@
+@@ -3753,7 +3566,13 @@
  tree_action(Host, Function, Args) ->
      ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
      Fun = fun() -> tree_call(Host, Function, Args) end,
  
  %% @doc <p>node plugin call.</p>
  node_call(Type, Function, Args) ->
-@@ -3737,13 +3585,13 @@
+@@ -3773,13 +3592,13 @@
  
  node_action(Host, Type, Function, Args) ->
      ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
                        case tree_call(Host, get_node, [Host, Node]) of
                            N when is_record(N, pubsub_node) ->
                                case Action(N) of
-@@ -3755,13 +3603,19 @@
+@@ -3791,13 +3610,19 @@
                                Error
                        end
                end, Trans).
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -3769,6 +3623,15 @@
+@@ -3805,6 +3630,15 @@
        {aborted, Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
        {'EXIT', Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
-@@ -3777,6 +3640,17 @@
+@@ -3813,6 +3647,17 @@
            {error, ?ERR_INTERNAL_SERVER_ERROR}
      end.