mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
jlib: Don't try to keep just one <delay/> tag
It seems unclear whether XEP-0203 really mandates that stanzas may not have multiple <delay/> tags. Editing/removing existing tags doesn't seem worth the effort, especially as we'd have to take more care which tag to keep if the stanza already has more than one.
This commit is contained in:
parent
749033598d
commit
8bc3dc9c49
29
src/jlib.erl
29
src/jlib.erl
@ -577,33 +577,8 @@ add_delay_info(El, From, Time) ->
|
||||
binary()) -> xmlel().
|
||||
|
||||
add_delay_info(El, From, Time, Desc) ->
|
||||
case fxml:get_subtag_with_xmlns(El, <<"delay">>, ?NS_DELAY) of
|
||||
false ->
|
||||
%% Add new tag
|
||||
DelayTag = create_delay_tag(Time, From, Desc),
|
||||
fxml:append_subtags(El, [DelayTag]);
|
||||
DelayTag ->
|
||||
%% Update existing tag
|
||||
NewDelayTag =
|
||||
case {fxml:get_tag_cdata(DelayTag), Desc} of
|
||||
{<<"">>, <<"">>} ->
|
||||
DelayTag;
|
||||
{OldDesc, <<"">>} ->
|
||||
DelayTag#xmlel{children = [{xmlcdata, OldDesc}]};
|
||||
{<<"">>, NewDesc} ->
|
||||
DelayTag#xmlel{children = [{xmlcdata, NewDesc}]};
|
||||
{OldDesc, NewDesc} ->
|
||||
case binary:match(OldDesc, NewDesc) of
|
||||
nomatch ->
|
||||
FinalDesc = <<OldDesc/binary, ", ", NewDesc/binary>>,
|
||||
DelayTag#xmlel{children = [{xmlcdata, FinalDesc}]};
|
||||
_ ->
|
||||
DelayTag#xmlel{children = [{xmlcdata, OldDesc}]}
|
||||
end
|
||||
end,
|
||||
NewEl = fxml:remove_subtags(El, <<"delay">>, {<<"xmlns">>, ?NS_DELAY}),
|
||||
fxml:append_subtags(NewEl, [NewDelayTag])
|
||||
end.
|
||||
DelayTag = create_delay_tag(Time, From, Desc),
|
||||
fxml:append_subtags(El, [DelayTag]).
|
||||
|
||||
-spec create_delay_tag(erlang:timestamp(), jid() | ljid() | binary(), binary())
|
||||
-> xmlel() | error.
|
||||
|
Loading…
Reference in New Issue
Block a user