mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Support XEP-0085 Chat State Notifications (EJAB-961)
SVN Revision: 2351
This commit is contained in:
parent
f82131af15
commit
0e19ca68b4
@ -189,7 +189,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 ->
|
||||||
LUser = exmpp_jid:prep_node_as_list(To),
|
LUser = exmpp_jid:prep_node_as_list(To),
|
||||||
LServer = exmpp_jid:prep_domain_as_list(To),
|
LServer = exmpp_jid:prep_domain_as_list(To),
|
||||||
@ -210,11 +210,21 @@ 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
|
||||||
case find_x_event(Packet#xmlel.children) of
|
check_event_chatstates(From, To, Packet) ->
|
||||||
false ->
|
case find_x_event_chatstates(Packet#xmlel.children, {false, false, false}) of
|
||||||
|
%% 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 exmpp_xml:get_element(El, 'id') of
|
case exmpp_xml:get_element(El, 'id') of
|
||||||
undefined ->
|
undefined ->
|
||||||
case exmpp_xml:get_element(El, 'offline') of
|
case exmpp_xml:get_element(El, 'offline') of
|
||||||
@ -240,12 +250,17 @@ 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([#xmlel{ns = ?NS_MESSAGE_EVENT} = El | _Els]) ->
|
Res;
|
||||||
El;
|
find_x_event_chatstates([#xmlel{ns = ?NS_MESSAGE_EVENT} = El | Els], {_, B, C}) ->
|
||||||
find_x_event([_ | Els]) ->
|
find_x_event_chatstates(Els, {El, B, C});
|
||||||
find_x_event(Els).
|
find_x_event_chatstates([#xmlel{ns = ?NS_CHATSTATES} = El | Els], {A, _, C}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, El, C});
|
||||||
|
find_x_event_chatstates([#xmlcdata{} = _ | Els], {A, B, C}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, B, C});
|
||||||
|
find_x_event_chatstates([_ | Els], {A, B, _}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, B, true}).
|
||||||
|
|
||||||
find_x_expire(_, []) ->
|
find_x_expire(_, []) ->
|
||||||
never;
|
never;
|
||||||
|
@ -204,7 +204,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 ->
|
||||||
LUser = exmpp_jid:prep_node_as_list(To),
|
LUser = exmpp_jid:prep_node_as_list(To),
|
||||||
TimeStamp = now(),
|
TimeStamp = now(),
|
||||||
@ -224,41 +224,57 @@ 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
|
||||||
case find_x_event(Packet#xmlel.children) of
|
check_event_chatstates(From, To, Packet) ->
|
||||||
false ->
|
case find_x_event_chatstates(Packet#xmlel.children, {false, false, false}) of
|
||||||
|
%% 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 exmpp_xml:get_element(El, 'id') of
|
case exmpp_xml:get_element(El, 'id') of
|
||||||
undefined ->
|
undefined ->
|
||||||
case exmpp_xml:get_element(El, 'offline') of
|
case exmpp_xml:get_element(El, 'offline') of
|
||||||
undefined ->
|
undefined ->
|
||||||
true;
|
true;
|
||||||
_ ->
|
_ ->
|
||||||
ID = case exmpp_xml:get_attribute_as_list(Packet, 'id', "") of
|
ID = case exmpp_stanza:get_id(Packet) of
|
||||||
"" ->
|
undefined ->
|
||||||
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id'};
|
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id'};
|
||||||
S ->
|
S ->
|
||||||
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id',
|
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id',
|
||||||
children = [#xmlcdata{cdata = list_to_binary(S)}]}
|
children = [#xmlcdata{cdata =
|
||||||
|
S}]}
|
||||||
end,
|
end,
|
||||||
X = #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'x', children =
|
X = #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'x', children =
|
||||||
[ID, #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'offline'}]},
|
[ID, #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'offline'}]},
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
To, From, exmpp_xml:set_children(Packet, [X])),
|
To, From, exmpp_xml:set_children(Packet, [X])),
|
||||||
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([#xmlel{ns = ?NS_MESSAGE_EVENT} = El | _Els]) ->
|
Res;
|
||||||
El;
|
find_x_event_chatstates([#xmlel{ns = ?NS_MESSAGE_EVENT} = El | Els], {_, B, C}) ->
|
||||||
find_x_event([_ | Els]) ->
|
find_x_event_chatstates(Els, {El, B, C});
|
||||||
find_x_event(Els).
|
find_x_event_chatstates([#xmlel{ns = ?NS_CHATSTATES} = El | Els], {A, _, C}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, El, C});
|
||||||
|
find_x_event_chatstates([#xmlcdata{} = _ | Els], {A, B, C}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, B, C});
|
||||||
|
find_x_event_chatstates([_ | Els], {A, B, _}) ->
|
||||||
|
find_x_event_chatstates(Els, {A, B, true}).
|
||||||
|
|
||||||
find_x_expire(_, []) ->
|
find_x_expire(_, []) ->
|
||||||
never;
|
never;
|
||||||
|
Loading…
Reference in New Issue
Block a user