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:
Holger Weiss 2015-05-18 21:26:51 +02:00
parent 8bb994dbca
commit fba13a0b93
1 changed files with 7 additions and 14 deletions

View File

@ -609,16 +609,10 @@ add_delay_info(El, From, Time) ->
binary()) -> xmlel(). binary()) -> xmlel().
add_delay_info(El, From, Time, Desc) -> add_delay_info(El, From, Time, Desc) ->
add_delay_info(El, From, Time, Desc, <<"delay">>, ?NS_DELAY). case xml:get_subtag_with_xmlns(El, <<"delay">>, ?NS_DELAY) of
-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
false -> false ->
%% Add new tag %% Add new tag
DelayTag = create_delay_tag(Time, From, Desc, XMLNS), DelayTag = create_delay_tag(Time, From, Desc),
xml:append_subtags(El, [DelayTag]); xml:append_subtags(El, [DelayTag]);
DelayTag -> DelayTag ->
%% Update existing tag %% Update existing tag
@ -639,15 +633,14 @@ add_delay_info(El, From, Time, Desc, Name, XMLNS) ->
DelayTag#xmlel{children = [{xmlcdata, OldDesc}]} DelayTag#xmlel{children = [{xmlcdata, OldDesc}]}
end end
end, end,
NewEl = xml:remove_subtags(El, Name, {<<"xmlns">>, XMLNS}), NewEl = xml:remove_subtags(El, <<"delay">>, {<<"xmlns">>, ?NS_DELAY}),
xml:append_subtags(NewEl, [NewDelayTag]) xml:append_subtags(NewEl, [NewDelayTag])
end. end.
-spec create_delay_tag(erlang:timestamp(), jid() | ljid() | binary(), binary(), -spec create_delay_tag(erlang:timestamp(), jid() | ljid() | binary(), binary(),
binary()) -> xmlel() | error. binary()) -> xmlel() | error.
create_delay_tag(TimeStamp, FromJID, Desc, XMLNS) when is_tuple(FromJID) create_delay_tag(TimeStamp, FromJID, Desc) when is_tuple(FromJID) ->
and (XMLNS == ?NS_DELAY) ->
From = jlib:jid_to_string(FromJID), From = jlib:jid_to_string(FromJID),
Stamp = now_to_utc_string(TimeStamp, 3), Stamp = now_to_utc_string(TimeStamp, 3),
Children = case Desc of Children = case Desc of
@ -656,12 +649,12 @@ create_delay_tag(TimeStamp, FromJID, Desc, XMLNS) when is_tuple(FromJID)
end, end,
#xmlel{name = <<"delay">>, #xmlel{name = <<"delay">>,
attrs = attrs =
[{<<"xmlns">>, XMLNS}, {<<"from">>, From}, [{<<"xmlns">>, ?NS_DELAY}, {<<"from">>, From},
{<<"stamp">>, Stamp}], {<<"stamp">>, Stamp}],
children = Children}; 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, <<"">>), 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. -type tz() :: {binary(), {integer(), integer()}} | {integer(), integer()} | utc.