mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Merge pull request #229 from weiss/no-carbons-to-sender
XEP-0280: Don't send v1 carbon copies back to the sender
This commit is contained in:
commit
f271ea6eef
@ -57,15 +57,19 @@
|
||||
version :: binary() | matchspec_atom()}).
|
||||
|
||||
is_carbon_copy(Packet) ->
|
||||
case xml:get_subtag(Packet, <<"sent">>) of
|
||||
#xmlel{name= <<"sent">>, attrs = AAttrs} ->
|
||||
case xml:get_attr_s(<<"xmlns">>, AAttrs) of
|
||||
?NS_CC_2 -> true;
|
||||
?NS_CC_1 -> true;
|
||||
_ -> false
|
||||
end;
|
||||
is_carbon_copy(Packet, <<"sent">>) orelse
|
||||
is_carbon_copy(Packet, <<"received">>).
|
||||
|
||||
is_carbon_copy(Packet, Direction) ->
|
||||
case xml:get_subtag(Packet, Direction) of
|
||||
#xmlel{name = Direction, attrs = Attrs} ->
|
||||
case xml:get_attr_s(<<"xmlns">>, Attrs) of
|
||||
?NS_CC_2 -> true;
|
||||
?NS_CC_1 -> true;
|
||||
_ -> false
|
||||
end.
|
||||
end;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue),
|
||||
@ -139,39 +143,20 @@ user_receive_packet(JID, _From, To, Packet) ->
|
||||
% - do not support "private" message mode, and do not modify the original packet in any way
|
||||
% - we also replicate "read" notifications
|
||||
check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, Direction)->
|
||||
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.
|
||||
SubTag = xml:get_subtag(Packet,<<"sent">>),
|
||||
if SubTag == false ->
|
||||
send_copies(JID, To, Packet, Direction);
|
||||
true ->
|
||||
case xml:get_subtag(SubTag,<<"forwarded">>) of
|
||||
false->
|
||||
send_copies(JID, To, Packet, Direction);
|
||||
_ ->
|
||||
stop
|
||||
end
|
||||
end;
|
||||
_ ->
|
||||
%% stop the hook chain, we don't want mod_logdb to register this message (duplicate)
|
||||
stop
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
case xml:get_attr_s(<<"type">>, Attrs) == <<"chat">> andalso
|
||||
xml:get_subtag(Packet, <<"private">>) == false andalso
|
||||
xml:get_subtag(Packet, <<"no-copy">>) == false of
|
||||
true ->
|
||||
case is_carbon_copy(Packet) of
|
||||
false ->
|
||||
send_copies(JID, To, Packet, Direction);
|
||||
true ->
|
||||
%% stop the hook chain, we don't want mod_logdb to register
|
||||
%% this message (duplicate)
|
||||
stop
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
|
||||
check_and_forward(_JID, _To, _Packet, _)-> ok.
|
||||
|
Loading…
Reference in New Issue
Block a user