Uploaded image for project: 'ejabberd development'
  1. ejabberd development
  2. EJAB-1470

New hooks for creation and deletion of nodes for mod_pubsub.

    Details

      Description

      Here is the tested patch based on code from badlop:

      diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
      index 0b4929d..2c9fc51 100644
      — a/src/mod_pubsub/mod_pubsub.erl
      +++ b/src/mod_pubsub/mod_pubsub.erl
      @@ -2170,13 +2170,16 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
      case transaction(CreateNode, transaction) of
      {result, {NodeId,

      {Result, broadcast}

      }} ->
      broadcast_created_node(Host, Node, NodeId, Type, NodeOptions),
      + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, Node, NodeOptions]),
      case Result of
      default ->

      {result, Reply};
      _ -> {result, Result}
      end;
      - {result, {_NodeId, default}} ->
      + {result, {NodeId, default}} ->
      + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, Node, NodeOptions]),
      {result, Reply}

      ;

      • {result, {_NodeId, Result}} ->
        + {result, {NodeId, Result}} ->
        + ejabberd_hooks:run(pubsub_create_node, ServerHost, [ServerHost, Host, Node, NodeOptions]), {result, Result};
        Error ->
        %% in case we change transaction to sync_dirty...
        @@ -2219,8 +2222,10 @@ delete_node(Host, Node, Owner) ->
        end
        end,
        Reply = [],
        + ServerHost = list_to_binary(get_serverhost(Host)),
        case transaction(Host, Node, Action, transaction) of
        {result, {_, {Result, broadcast, Removed}}} ->
        + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]),
        lists:foreach(fun({RNode, _RSubscriptions}) ->
        {RH, RN} = RNode#pubsub_node.id,
        Nidx = RNode#pubsub_node.idx,
        @@ -2234,18 +2239,27 @@ delete_node(Host, Node, Owner) ->
        _ -> {result, Result}

        end;
        {result, {_,

        {Result, _Removed}

        }} ->
        + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]),
        case Result of
        default ->

        {result, Reply};
        _ -> {result, Result}
        end;
        {result, {_, default}} ->
        + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]),
        {result, Reply}

        ;
        {result, {_, Result}} ->
        + ejabberd_hooks:run(pubsub_delete_node, ServerHost, [ServerHost, Host, Node]),

        {result, Result}

        ;
        Error ->
        Error
        end.

      +%% "pubsub.localhost.pubsub.example.org" --> "localhost.pubsub.example.org"
      +get_serverhost(Host) when is_binary(Host) ->
      + get_serverhost(binary_to_list(Host));
      +get_serverhost(Host) ->
      + string:join(string:substr(string:tokens(Host, "."), 2), ".").
      +
      %% @spec (Host, Node, From, JID, Configuration) ->
      %%

      {error, Reason::stanzaError()}

      |
      %%

      {result, []}

        Expenses

          Activity

          Hide
          vishalxica Vishal Xica added a comment -

          Easier to apply patch as a file.

          Show
          vishalxica Vishal Xica added a comment - Easier to apply patch as a file.
          Hide
          cromain@process-one.net Christophe Romain added a comment -

          change applied, with minor change on delete hook, and use of dictionary to get effective ServerHost (it's not mandadory to have it set to something like something.serverhost)

          Show
          cromain@process-one.net Christophe Romain added a comment - change applied, with minor change on delete hook, and use of dictionary to get effective ServerHost (it's not mandadory to have it set to something like something.serverhost)

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development