mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Merge pull request #207 from weiss/xep-0334
Honor XEP-0334: Message Processing Hints
This commit is contained in:
commit
5d855f3723
@ -42,6 +42,7 @@
|
||||
-define(NS_IQDATA, <<"jabber:iq:data">>).
|
||||
-define(NS_DELAY91, <<"jabber:x:delay">>).
|
||||
-define(NS_DELAY, <<"urn:xmpp:delay">>).
|
||||
-define(NS_HINTS, <<"urn:xmpp:hints">>).
|
||||
-define(NS_EXPIRE, <<"jabber:x:expire">>).
|
||||
-define(NS_EVENT, <<"jabber:x:event">>).
|
||||
-define(NS_CHATSTATES,
|
||||
|
@ -142,11 +142,13 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet,
|
||||
case xml:get_attr_s(<<"type">>, Attrs) of
|
||||
<<"chat">> ->
|
||||
case xml:get_subtag(Packet, <<"private">>) of
|
||||
false ->
|
||||
case xml:get_subtag(Packet, <<"no-copy">>) of
|
||||
false ->
|
||||
case xml:get_subtag(Packet,<<"received">>) of
|
||||
false ->
|
||||
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>" tags in order to avoid
|
||||
%% receiving message back to original sender.
|
||||
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>"
|
||||
%% tags in order to avoid receiving message back to original sender.
|
||||
SubTag = xml:get_subtag(Packet,<<"sent">>),
|
||||
if SubTag == false ->
|
||||
send_copies(JID, To, Packet, Direction);
|
||||
@ -168,6 +170,9 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet,
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
|
||||
check_and_forward(_JID, _To, _Packet, _)-> ok.
|
||||
|
||||
|
@ -233,6 +233,10 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
|
||||
case {xml:get_subtag(Packet, <<"no-store">>),
|
||||
xml:get_subtag(Packet, <<"no-permanent-store">>)}
|
||||
of
|
||||
{false, false} ->
|
||||
case {xml:get_subtag(Packet, <<"subject">>),
|
||||
xml:get_subtag(Packet, <<"body">>)}
|
||||
of
|
||||
@ -244,6 +248,8 @@ add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
|
||||
Message = {subject, xml:get_tag_cdata(SubEl)},
|
||||
add_message_to_log(Nick, Message, Room, Opts, State)
|
||||
end;
|
||||
{_, _} -> ok
|
||||
end;
|
||||
add_to_log2(roomconfig_change, _Occupants, Room, Opts,
|
||||
State) ->
|
||||
add_message_to_log(<<"">>, roomconfig_change, Room,
|
||||
|
@ -237,6 +237,8 @@ store_packet(From, To, Packet) ->
|
||||
Type = xml:get_tag_attr_s(<<"type">>, Packet),
|
||||
if (Type /= <<"error">>) and (Type /= <<"groupchat">>)
|
||||
and (Type /= <<"headline">>) ->
|
||||
case has_no_storage_hint(Packet) of
|
||||
false ->
|
||||
case check_event(From, To, Packet) of
|
||||
true ->
|
||||
#jid{luser = LUser, lserver = LServer} = To,
|
||||
@ -250,9 +252,24 @@ store_packet(From, To, Packet) ->
|
||||
stop;
|
||||
_ -> ok
|
||||
end;
|
||||
_ -> ok
|
||||
end;
|
||||
true -> ok
|
||||
end.
|
||||
|
||||
has_no_storage_hint(Packet) ->
|
||||
case xml:get_subtag(Packet, <<"no-store">>) of
|
||||
#xmlel{attrs = Attrs} ->
|
||||
case xml:get_attr_s(<<"xmlns">>, Attrs) of
|
||||
?NS_HINTS ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% Check if the packet has any content about XEP-0022 or XEP-0085
|
||||
check_event(From, To, Packet) ->
|
||||
#xmlel{name = Name, attrs = Attrs, children = Els} =
|
||||
|
Loading…
Reference in New Issue
Block a user