diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-06-05 22:36:56 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-06-05 22:36:56 +0200 |
commit | 60803f57802ecf460e25ce3a6ef5dc86285ed448 (patch) | |
tree | 8e17aa2b09b2d403087e58565801e599623912ed /src | |
parent | mod_client_state: Fix handling of chat states (diff) |
Simplify check for carbon-copied chat states
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/jlib.erl | 21 | ||||
-rw-r--r-- | src/mod_client_state.erl | 2 | ||||
-rw-r--r-- | src/mod_offline.erl | 3 |
3 files changed, 15 insertions, 11 deletions
diff --git a/src/jlib.erl b/src/jlib.erl index 42ac4bff3..e5cba3180 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -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(). diff --git a/src/mod_client_state.erl b/src/mod_client_state.erl index 68a276ca7..651f15c25 100644 --- a/src/mod_client_state.erl +++ b/src/mod_client_state.erl @@ -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), diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 74fbcd99b..4d8aba762 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -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 |