25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

mod_carboncopy: Support new copying rules

Support the copying rules added to XEP-0280 with version 0.13.0 under
the "urn:xmpp:carbons:rules:0" namespace.

Closes #3011.
This commit is contained in:
Holger Weiss 2020-01-12 13:42:00 +01:00
parent 919c9d6fb1
commit a8f6c1db1d
2 changed files with 19 additions and 7 deletions

View File

@ -25,7 +25,7 @@
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.18"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.38"}}},
{idna, ".*", {git, "https://github.com/benoitc/erlang-idna", {tag, "6.0.0"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "1.4.3"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "f98a50eb4135"}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.22"}}},
{yconf, ".*", {git, "https://github.com/processone/yconf", {tag, "1.0.2"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},

View File

@ -81,12 +81,10 @@ reload(_Host, _NewOpts, _OldOpts) ->
-spec disco_features({error, stanza_error()} | {result, [binary()]} | empty,
jid(), jid(), binary(), binary()) ->
{error, stanza_error()} | {result, [binary()]}.
disco_features({error, Err}, _From, _To, _Node, _Lang) ->
{error, Err};
disco_features(empty, _From, _To, <<"">>, _Lang) ->
{result, [?NS_CARBONS_2]};
disco_features(empty, From, To, <<"">>, Lang) ->
disco_features({result, []}, From, To, <<"">>, Lang);
disco_features({result, Feats}, _From, _To, <<"">>, _Lang) ->
{result, [?NS_CARBONS_2|Feats]};
{result, [?NS_CARBONS_2,?NS_CARBONS_RULES_0|Feats]};
disco_features(Acc, _From, _To, _Node, _Lang) ->
Acc.
@ -162,7 +160,8 @@ c2s_session_opened(State) ->
-spec check_and_forward(jid(), jid(), stanza(), direction()) ->
stanza() | {stop, stanza()}.
check_and_forward(JID, To, Packet, Direction)->
case is_chat_message(Packet) andalso
case (is_chat_message(Packet) orelse
is_received_muc_invite(Packet, Direction)) andalso
not is_received_muc_pm(To, Packet, Direction) andalso
not xmpp:has_subtag(Packet, #carbons_private{}) andalso
not xmpp:has_subtag(Packet, #hint{type = 'no-copy'}) of
@ -275,9 +274,18 @@ is_chat_message(#message{type = chat}) ->
true;
is_chat_message(#message{type = normal, body = [_|_]}) ->
true;
is_chat_message(#message{type = Type} = Msg) when Type == chat;
Type == normal ->
has_chatstate(Msg) orelse xmpp:has_subtag(Msg, #receipt_response{});
is_chat_message(_) ->
false.
-spec is_received_muc_invite(message(), direction()) -> boolean().
is_received_muc_invite(_Packet, sent) ->
false;
is_received_muc_invite(Packet, received) ->
xmpp:has_subtag(Packet, #x_conference{}).
-spec is_received_muc_pm(jid(), message(), direction()) -> boolean().
is_received_muc_pm(#jid{lresource = <<>>}, _Packet, _Direction) ->
false;
@ -286,6 +294,10 @@ is_received_muc_pm(_To, _Packet, sent) ->
is_received_muc_pm(_To, Packet, received) ->
xmpp:has_subtag(Packet, #muc_user{}).
-spec has_chatstate(message()) -> boolean().
has_chatstate(#message{sub_els = Els}) ->
lists:any(fun(El) -> xmpp:get_ns(El) == ?NS_CHATSTATES end, Els).
-spec list(binary(), binary()) -> [{Resource :: binary(), Namespace :: binary()}].
list(User, Server) ->
lists:filtermap(