]> granicus.if.org Git - ejabberd/commitdiff
Simplify check for carbon-copied chat states
authorHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 5 Jun 2016 20:36:56 +0000 (22:36 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 5 Jun 2016 20:36:56 +0000 (22:36 +0200)
Let jlib:is_standalone_chat_state/1 unwrap carbon copies rather than
leaving this to the caller.  We still export jlib:unwrap_carbon/1, as
this function might also be useful for other purposes.

src/jlib.erl
src/mod_client_state.erl
src/mod_offline.erl

index 42ac4bff31c5015c30a6fc7661e27eacdbe83b02..e5cba3180b6d3f074f3a249cfa7066595504abee 100644 (file)
@@ -574,14 +574,19 @@ unwrap_carbon(Stanza, Direction) ->
 
 -spec is_standalone_chat_state(xmlel()) -> boolean().
 
-is_standalone_chat_state(#xmlel{name = <<"message">>, children = Els}) ->
-    IgnoreNS = [?NS_CHATSTATES, ?NS_DELAY],
-    Stripped = [El || #xmlel{name = Name, attrs = Attrs} = El <- Els,
-                     not lists:member(fxml:get_attr_s(<<"xmlns">>, Attrs),
-                                      IgnoreNS),
-                     Name /= <<"thread">>],
-    Stripped == [];
-is_standalone_chat_state(_El) -> false.
+is_standalone_chat_state(Stanza) ->
+    case unwrap_carbon(Stanza) of
+      #xmlel{name = <<"message">>, children = Els} ->
+         IgnoreNS = [?NS_CHATSTATES, ?NS_DELAY],
+         Stripped = [El || #xmlel{name = Name, attrs = Attrs} = El <- Els,
+                           not lists:member(fxml:get_attr_s(<<"xmlns">>,
+                                                            Attrs),
+                                            IgnoreNS),
+                           Name /= <<"thread">>],
+         Stripped == [];
+      #xmlel{} ->
+         false
+    end.
 
 -spec add_delay_info(xmlel(), jid() | ljid() | binary(), erlang:timestamp())
                     -> xmlel().
index 68a276ca703ba57b151d2134cbb36a57eb5c0ca8..651f15c25d32268cef114c72d0a4f9686e8668cb 100644 (file)
@@ -165,7 +165,7 @@ filter_presence(Acc, _Host, _Stanza) -> Acc.
 
 filter_chat_states({C2SState, _OutStanzas} = Acc, Host,
                   #xmlel{name = <<"message">>} = Stanza) ->
-    case jlib:is_standalone_chat_state(jlib:unwrap_carbon(Stanza)) of
+    case jlib:is_standalone_chat_state(Stanza) of
       true ->
          From = fxml:get_tag_attr_s(<<"from">>, Stanza),
          To = fxml:get_tag_attr_s(<<"to">>, Stanza),
index 74fbcd99bb33e071d4bc0c0185b24b4271fd5fa6..4d8aba76204f8c3548fef27347e547d092bb8d4a 100644 (file)
@@ -455,8 +455,7 @@ need_to_store(LServer, Packet) ->
                                false ->
                                    fxml:get_subtag(Packet, <<"body">>) /= false;
                                unless_chat_state ->
-                                   not jlib:is_standalone_chat_state(
-                                         jlib:unwrap_carbon(Packet));
+                                   not jlib:is_standalone_chat_state(Packet);
                                true ->
                                    true
                            end