mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-22 22:23:42 +02:00
Support XEP-0085 Chat State Notifications (EJAB-961)
SVN Revision: 2350
This commit is contained in:
parent
29ea2738cc
commit
4f0cd053c4
|
@ -39,6 +39,7 @@
|
||||||
-define(NS_DELAY, "urn:xmpp:delay").
|
-define(NS_DELAY, "urn:xmpp:delay").
|
||||||
-define(NS_EXPIRE, "jabber:x:expire").
|
-define(NS_EXPIRE, "jabber:x:expire").
|
||||||
-define(NS_EVENT, "jabber:x:event").
|
-define(NS_EVENT, "jabber:x:event").
|
||||||
|
-define(NS_CHATSTATES, "http://jabber.org/protocol/chatstates").
|
||||||
-define(NS_XCONFERENCE, "jabber:x:conference").
|
-define(NS_XCONFERENCE, "jabber:x:conference").
|
||||||
-define(NS_STATS, "http://jabber.org/protocol/stats").
|
-define(NS_STATS, "http://jabber.org/protocol/stats").
|
||||||
-define(NS_MUC, "http://jabber.org/protocol/muc").
|
-define(NS_MUC, "http://jabber.org/protocol/muc").
|
||||||
|
|
|
@ -181,7 +181,7 @@ store_packet(From, To, Packet) ->
|
||||||
if
|
if
|
||||||
(Type /= "error") and (Type /= "groupchat") and
|
(Type /= "error") and (Type /= "groupchat") and
|
||||||
(Type /= "headline") ->
|
(Type /= "headline") ->
|
||||||
case check_event(From, To, Packet) of
|
case check_event_chatstates(From, To, Packet) of
|
||||||
true ->
|
true ->
|
||||||
#jid{luser = LUser, lserver = LServer} = To,
|
#jid{luser = LUser, lserver = LServer} = To,
|
||||||
TimeStamp = now(),
|
TimeStamp = now(),
|
||||||
|
@ -202,12 +202,22 @@ store_packet(From, To, Packet) ->
|
||||||
ok
|
ok
|
||||||
end.
|
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,
|
{xmlelement, Name, Attrs, Els} = Packet,
|
||||||
case find_x_event(Els) of
|
case find_x_event_chatstates(Els, {false, false, false}) of
|
||||||
false ->
|
%% There wasn't any x:event or chatstates subelements
|
||||||
|
{false, false, _} ->
|
||||||
true;
|
true;
|
||||||
El ->
|
%% There a chatstates subelement and other stuff, but no x:event
|
||||||
|
{false, CEl, true} when CEl /= false ->
|
||||||
|
true;
|
||||||
|
%% 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
|
case xml:get_subtag(El, "id") of
|
||||||
false ->
|
false ->
|
||||||
case xml:get_subtag(El, "offline") of
|
case xml:get_subtag(El, "offline") of
|
||||||
|
@ -235,16 +245,19 @@ check_event(From, To, Packet) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
find_x_event([]) ->
|
%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
|
||||||
false;
|
find_x_event_chatstates([], Res) ->
|
||||||
find_x_event([{xmlcdata, _} | Els]) ->
|
Res;
|
||||||
find_x_event(Els);
|
find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
|
||||||
find_x_event([El | Els]) ->
|
find_x_event_chatstates(Els, Res);
|
||||||
|
find_x_event_chatstates([El | Els], {A, B, C}) ->
|
||||||
case xml:get_tag_attr_s("xmlns", El) of
|
case xml:get_tag_attr_s("xmlns", El) of
|
||||||
?NS_EVENT ->
|
?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.
|
end.
|
||||||
|
|
||||||
find_x_expire(_, []) ->
|
find_x_expire(_, []) ->
|
||||||
|
|
|
@ -199,7 +199,7 @@ store_packet(From, To, Packet) ->
|
||||||
if
|
if
|
||||||
(Type /= "error") and (Type /= "groupchat") and
|
(Type /= "error") and (Type /= "groupchat") and
|
||||||
(Type /= "headline") ->
|
(Type /= "headline") ->
|
||||||
case check_event(From, To, Packet) of
|
case check_event_chatstates(From, To, Packet) of
|
||||||
true ->
|
true ->
|
||||||
#jid{luser = LUser} = To,
|
#jid{luser = LUser} = To,
|
||||||
TimeStamp = now(),
|
TimeStamp = now(),
|
||||||
|
@ -220,12 +220,22 @@ store_packet(From, To, Packet) ->
|
||||||
ok
|
ok
|
||||||
end.
|
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,
|
{xmlelement, Name, Attrs, Els} = Packet,
|
||||||
case find_x_event(Els) of
|
case find_x_event_chatstates(Els, {false, false, false}) of
|
||||||
false ->
|
%% There wasn't any x:event or chatstates subelements
|
||||||
|
{false, false, _} ->
|
||||||
true;
|
true;
|
||||||
El ->
|
%% There a chatstates subelement and other stuff, but no x:event
|
||||||
|
{false, CEl, true} when CEl /= false ->
|
||||||
|
true;
|
||||||
|
%% 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
|
case xml:get_subtag(El, "id") of
|
||||||
false ->
|
false ->
|
||||||
case xml:get_subtag(El, "offline") of
|
case xml:get_subtag(El, "offline") of
|
||||||
|
@ -247,22 +257,25 @@ check_event(From, To, Packet) ->
|
||||||
{xmlelement, "offline", [], []}]}]
|
{xmlelement, "offline", [], []}]}]
|
||||||
}),
|
}),
|
||||||
true
|
true
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
find_x_event([]) ->
|
%% Check if the packet has subelements about XEP-0022, XEP-0085 or other
|
||||||
false;
|
find_x_event_chatstates([], Res) ->
|
||||||
find_x_event([{xmlcdata, _} | Els]) ->
|
Res;
|
||||||
find_x_event(Els);
|
find_x_event_chatstates([{xmlcdata, _} | Els], Res) ->
|
||||||
find_x_event([El | Els]) ->
|
find_x_event_chatstates(Els, Res);
|
||||||
|
find_x_event_chatstates([El | Els], {A, B, C}) ->
|
||||||
case xml:get_tag_attr_s("xmlns", El) of
|
case xml:get_tag_attr_s("xmlns", El) of
|
||||||
?NS_EVENT ->
|
?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.
|
end.
|
||||||
|
|
||||||
find_x_expire(_, []) ->
|
find_x_expire(_, []) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user