24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

Simplify mod_carboncopy:check_and_forward/4

Use the existing is_carbon_copy/1 function, and combine multiple case
clauses into a single one.
This commit is contained in:
Holger Weiss 2014-05-30 23:44:19 +02:00
parent bb952f9ecc
commit f45654a16a

View File

@ -143,44 +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 % - do not support "private" message mode, and do not modify the original packet in any way
% - we also replicate "read" notifications % - we also replicate "read" notifications
check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, Direction)-> check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, Direction)->
case xml:get_attr_s(<<"type">>, Attrs) of case xml:get_attr_s(<<"type">>, Attrs) == <<"chat">> andalso
<<"chat">> -> xml:get_subtag(Packet, <<"private">>) == false andalso
case xml:get_subtag(Packet, <<"private">>) of xml:get_subtag(Packet, <<"no-copy">>) == false of
false -> true ->
case xml:get_subtag(Packet, <<"no-copy">>) of case is_carbon_copy(Packet) of
false -> false ->
case xml:get_subtag(Packet,<<"received">>) of send_copies(JID, To, Packet, Direction);
false -> true ->
%% We must check if a packet contains "<sent><forwarded></sent></forwarded>" %% stop the hook chain, we don't want mod_logdb to register
%% tags in order to avoid receiving message back to original sender. %% this message (duplicate)
SubTag = xml:get_subtag(Packet,<<"sent">>), stop
if SubTag == false -> end;
send_copies(JID, To, Packet, Direction); _ ->
true -> ok
case xml:get_subtag(Packet,<<"forwarded">>) of
false->
case xml:get_subtag(SubTag,<<"forwarded">>) of
false ->
send_copies(JID, To, Packet, Direction);
_ ->
stop
end;
_ ->
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
end; end;
check_and_forward(_JID, _To, _Packet, _)-> ok. check_and_forward(_JID, _To, _Packet, _)-> ok.