-define(NS_DELAY, "urn:xmpp:delay").
-define(NS_EXPIRE, "jabber:x:expire").
-define(NS_EVENT, "jabber:x:event").
+-define(NS_CHATSTATES, "http://jabber.org/protocol/chatstates").
-define(NS_XCONFERENCE, "jabber:x:conference").
-define(NS_STATS, "http://jabber.org/protocol/stats").
-define(NS_MUC, "http://jabber.org/protocol/muc").
if
(Type /= "error") and (Type /= "groupchat") and
(Type /= "headline") ->
- case check_event(From, To, Packet) of
+ case check_event_chatstates(From, To, Packet) of
true ->
#jid{luser = LUser, lserver = LServer} = To,
TimeStamp = now(),
ok
end.
-check_event(From, To, Packet) ->
+%% Check if the packet has any content about XEP-0022 or XEP-0085
+check_event_chatstates(From, To, Packet) ->
{xmlelement, Name, Attrs, Els} = Packet,
- case find_x_event(Els) of
- false ->
+ case find_x_event_chatstates(Els, {false, false, false}) of
+ %% There wasn't any x:event or chatstates subelements
+ {false, false, _} ->
+ true;
+ %% There a chatstates subelement and other stuff, but no x:event
+ {false, CEl, true} when CEl /= false ->
true;
- El ->
+ %% There was only a subelement: a chatstates
+ {false, CEl, false} when CEl /= false ->
+ %% Don't allow offline storage
+ false;
+ %% There was an x:event element, and maybe also other stuff
+ {El, _, _} when El /= false ->
case xml:get_subtag(El, "id") of
false ->
case xml:get_subtag(El, "offline") of
end
end.
-find_x_event([]) ->
- false;
-find_x_event([{xmlcdata, _} | Els]) ->
- find_x_event(Els);
-find_x_event([El | Els]) ->
+%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
+find_x_event_chatstates([], Res) ->
+ Res;
+find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
+ find_x_event_chatstates(Els, Res);
+find_x_event_chatstates([El | Els], {A, B, C}) ->
case xml:get_tag_attr_s("xmlns", El) of
?NS_EVENT ->
- El;
+ find_x_event_chatstates(Els, {El, B, C});
+ ?NS_CHATSTATES ->
+ find_x_event_chatstates(Els, {A, El, C});
_ ->
- find_x_event(Els)
+ find_x_event_chatstates(Els, {A, B, true})
end.
find_x_expire(_, []) ->
if
(Type /= "error") and (Type /= "groupchat") and
(Type /= "headline") ->
- case check_event(From, To, Packet) of
+ case check_event_chatstates(From, To, Packet) of
true ->
#jid{luser = LUser} = To,
TimeStamp = now(),
ok
end.
-check_event(From, To, Packet) ->
+%% Check if the packet has any content about XEP-0022 or XEP-0085
+check_event_chatstates(From, To, Packet) ->
{xmlelement, Name, Attrs, Els} = Packet,
- case find_x_event(Els) of
- false ->
+ case find_x_event_chatstates(Els, {false, false, false}) of
+ %% There wasn't any x:event or chatstates subelements
+ {false, false, _} ->
+ true;
+ %% There a chatstates subelement and other stuff, but no x:event
+ {false, CEl, true} when CEl /= false ->
true;
- El ->
+ %% There was only a subelement: a chatstates
+ {false, CEl, false} when CEl /= false ->
+ %% Don't allow offline storage
+ false;
+ %% There was an x:event element, and maybe also other stuff
+ {El, _, _} when El /= false ->
case xml:get_subtag(El, "id") of
false ->
case xml:get_subtag(El, "offline") of
{xmlelement, "offline", [], []}]}]
}),
true
- end;
+ end;
_ ->
false
end
end.
-find_x_event([]) ->
- false;
-find_x_event([{xmlcdata, _} | Els]) ->
- find_x_event(Els);
-find_x_event([El | Els]) ->
+%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
+find_x_event_chatstates([], Res) ->
+ Res;
+find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
+ find_x_event_chatstates(Els, Res);
+find_x_event_chatstates([El | Els], {A, B, C}) ->
case xml:get_tag_attr_s("xmlns", El) of
?NS_EVENT ->
- El;
+ find_x_event_chatstates(Els, {El, B, C});
+ ?NS_CHATSTATES ->
+ find_x_event_chatstates(Els, {A, El, C});
_ ->
- find_x_event(Els)
+ find_x_event_chatstates(Els, {A, B, true})
end.
find_x_expire(_, []) ->