Skip to content

Commit

Permalink
Simplify check for carbon-copied chat states
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weiss committed Jun 5, 2016
1 parent 5c3074c commit 60803f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/jlib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
2 changes: 1 addition & 1 deletion src/mod_client_state.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions src/mod_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 60803f5

Please sign in to comment.