Simplify XEP-0203 (Delayed Delivery) code a bit
Now that XEP-0091 support is removed, the XEP-0203 code can be simplified a little further. This doesn't change the behavior.
This commit is contained in:
parent
8bb994dbca
commit
fba13a0b93
21
src/jlib.erl
21
src/jlib.erl
|
@ -609,16 +609,10 @@ add_delay_info(El, From, Time) ->
|
|||
binary()) -> xmlel().
|
||||
|
||||
add_delay_info(El, From, Time, Desc) ->
|
||||
add_delay_info(El, From, Time, Desc, <<"delay">>, ?NS_DELAY).
|
||||
|
||||
-spec add_delay_info(xmlel(), jid() | ljid() | binary(), erlang:timestamp(),
|
||||
binary(), binary(), binary()) -> xmlel().
|
||||
|
||||
add_delay_info(El, From, Time, Desc, Name, XMLNS) ->
|
||||
case xml:get_subtag_with_xmlns(El, Name, XMLNS) of
|
||||
case xml:get_subtag_with_xmlns(El, <<"delay">>, ?NS_DELAY) of
|
||||
false ->
|
||||
%% Add new tag
|
||||
DelayTag = create_delay_tag(Time, From, Desc, XMLNS),
|
||||
DelayTag = create_delay_tag(Time, From, Desc),
|
||||
xml:append_subtags(El, [DelayTag]);
|
||||
DelayTag ->
|
||||
%% Update existing tag
|
||||
|
@ -639,15 +633,14 @@ add_delay_info(El, From, Time, Desc, Name, XMLNS) ->
|
|||
DelayTag#xmlel{children = [{xmlcdata, OldDesc}]}
|
||||
end
|
||||
end,
|
||||
NewEl = xml:remove_subtags(El, Name, {<<"xmlns">>, XMLNS}),
|
||||
NewEl = xml:remove_subtags(El, <<"delay">>, {<<"xmlns">>, ?NS_DELAY}),
|
||||
xml:append_subtags(NewEl, [NewDelayTag])
|
||||
end.
|
||||
|
||||
-spec create_delay_tag(erlang:timestamp(), jid() | ljid() | binary(), binary(),
|
||||
binary()) -> xmlel() | error.
|
||||
|
||||
create_delay_tag(TimeStamp, FromJID, Desc, XMLNS) when is_tuple(FromJID)
|
||||
and (XMLNS == ?NS_DELAY) ->
|
||||
create_delay_tag(TimeStamp, FromJID, Desc) when is_tuple(FromJID) ->
|
||||
From = jlib:jid_to_string(FromJID),
|
||||
Stamp = now_to_utc_string(TimeStamp, 3),
|
||||
Children = case Desc of
|
||||
|
@ -656,12 +649,12 @@ create_delay_tag(TimeStamp, FromJID, Desc, XMLNS) when is_tuple(FromJID)
|
|||
end,
|
||||
#xmlel{name = <<"delay">>,
|
||||
attrs =
|
||||
[{<<"xmlns">>, XMLNS}, {<<"from">>, From},
|
||||
[{<<"xmlns">>, ?NS_DELAY}, {<<"from">>, From},
|
||||
{<<"stamp">>, Stamp}],
|
||||
children = Children};
|
||||
create_delay_tag(DateTime, Host, Desc, XMLNS) when is_binary(Host) ->
|
||||
create_delay_tag(DateTime, Host, Desc) when is_binary(Host) ->
|
||||
FromJID = jlib:make_jid(<<"">>, Host, <<"">>),
|
||||
create_delay_tag(DateTime, FromJID, Desc, XMLNS).
|
||||
create_delay_tag(DateTime, FromJID, Desc).
|
||||
|
||||
-type tz() :: {binary(), {integer(), integer()}} | {integer(), integer()} | utc.
|
||||
|
||||
|
|
Loading…
Reference in New Issue