]> granicus.if.org Git - ejabberd/commitdiff
Refactor publish_item conditions (#2267)
authorChristophe Romain <christophe.romain@process-one.net>
Fri, 16 Mar 2018 16:17:53 +0000 (17:17 +0100)
committerChristophe Romain <christophe.romain@process-one.net>
Fri, 16 Mar 2018 16:17:53 +0000 (17:17 +0100)
src/mod_pubsub.erl

index 10c875229d018b6d63e174873dac76bae20dc8ec..49a460a37eb11976709562267f94a2ba9cdab9c9 100644 (file)
@@ -1112,7 +1112,7 @@ iq_pubsub(Host, Access, #iq{from = From, type = IQType, lang = Lang,
                                         Payload, PubOpts, Access)
                    end;
                [] ->
-                   {error, extended_error(xmpp:err_bad_request(), err_item_required())};
+                   publish_item(Host, ServerHost, Node, From, <<>>, [], [], Access);
                _ ->
                    {error, extended_error(xmpp:err_bad_request(), err_invalid_payload())}
            end;
@@ -1785,19 +1785,15 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload, PubOpts, Access
                PayloadSize > PayloadMaxSize ->
                    {error, extended_error(xmpp:err_not_acceptable(),
                                           err_payload_too_big())};
-               (PayloadCount == 0) and (Payload == []) ->
+               (DeliverPayloads or PersistItems) and (PayloadCount == 0) ->
                    {error, extended_error(xmpp:err_bad_request(),
-                                          err_payload_required())};
-               (PayloadCount > 1) or (PayloadCount == 0) ->
+                                          err_item_required())};
+               (DeliverPayloads or PersistItems) and (PayloadCount > 1) ->
                    {error, extended_error(xmpp:err_bad_request(),
                                           err_invalid_payload())};
-               (DeliverPayloads == false) and (PersistItems == false) and
-                       (PayloadSize > 0) ->
+               (not DeliverPayloads) and (PayloadCount > 0) ->
                    {error, extended_error(xmpp:err_bad_request(),
                                           err_item_forbidden())};
-               ((DeliverPayloads == true) or (PersistItems == true)) and (PayloadSize == 0) ->
-                   {error, extended_error(xmpp:err_bad_request(),
-                                          err_item_required())};
                true ->
                    node_call(Host, Type, publish_item,
                        [Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload, PubOpts])