mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
mod_blocking: Use #block_item{} record
This commit is contained in:
parent
56ee6f0518
commit
638f2d2e67
@ -25,7 +25,7 @@
|
||||
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
|
||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
|
||||
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
|
||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "1.1.21"}}},
|
||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "d958206"}},
|
||||
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
|
||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
||||
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
||||
|
@ -92,12 +92,12 @@ process_iq_set(#iq{lang = Lang, sub_els = [SubEl]} = IQ) ->
|
||||
Txt = <<"No items found in this query">>,
|
||||
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
|
||||
#block{items = Items} ->
|
||||
JIDs = [jid:tolower(Item) || Item <- Items],
|
||||
JIDs = [jid:tolower(JID) || #block_item{jid = JID} <- Items],
|
||||
process_block(IQ, JIDs);
|
||||
#unblock{items = []} ->
|
||||
process_unblock_all(IQ);
|
||||
#unblock{items = Items} ->
|
||||
JIDs = [jid:tolower(Item) || Item <- Items],
|
||||
JIDs = [jid:tolower(JID) || #block_item{jid = JID} <- Items],
|
||||
process_unblock(IQ, JIDs);
|
||||
_ ->
|
||||
Txt = <<"No module is handling this query">>,
|
||||
@ -163,7 +163,8 @@ process_block(#iq{from = From} = IQ, LJIDs) ->
|
||||
end) of
|
||||
ok ->
|
||||
mod_privacy:push_list_update(From, Name),
|
||||
Items = [jid:make(LJID) || LJID <- LJIDs],
|
||||
Items = [#block_item{jid = jid:make(LJID)}
|
||||
|| LJID <- LJIDs],
|
||||
broadcast_event(From, #block{items = Items}),
|
||||
xmpp:make_iq_result(IQ);
|
||||
{error, notfound} ->
|
||||
@ -218,14 +219,16 @@ process_unblock(#iq{from = From} = IQ, LJIDs) ->
|
||||
case mod_privacy:set_list(LUser, LServer, Name, NewList) of
|
||||
ok ->
|
||||
mod_privacy:push_list_update(From, Name),
|
||||
Items = [jid:make(LJID) || LJID <- LJIDs],
|
||||
Items = [#block_item{jid = jid:make(LJID)}
|
||||
|| LJID <- LJIDs],
|
||||
broadcast_event(From, #unblock{items = Items}),
|
||||
xmpp:make_iq_result(IQ);
|
||||
{error, _} ->
|
||||
err_db_failure(IQ)
|
||||
end;
|
||||
error ->
|
||||
Items = [jid:make(LJID) || LJID <- LJIDs],
|
||||
Items = [#block_item{jid = jid:make(LJID)}
|
||||
|| LJID <- LJIDs],
|
||||
broadcast_event(From, #unblock{items = Items}),
|
||||
xmpp:make_iq_result(IQ);
|
||||
{error, _} ->
|
||||
@ -249,7 +252,7 @@ process_get(#iq{from = #jid{luser = LUser, lserver = LServer}} = IQ) ->
|
||||
case mod_privacy:get_user_list(LUser, LServer, default) of
|
||||
{ok, {_, List}} ->
|
||||
LJIDs = listitems_to_jids(List, []),
|
||||
Items = [jid:make(J) || J <- LJIDs],
|
||||
Items = [#block_item{jid = jid:make(J)} || J <- LJIDs],
|
||||
xmpp:make_iq_result(IQ, #block_list{items = Items});
|
||||
error ->
|
||||
xmpp:make_iq_result(IQ, #block_list{});
|
||||
|
@ -203,6 +203,7 @@ malformed_iq_query(Config) ->
|
||||
|
||||
malformed_get(Config) ->
|
||||
JID = jid:make(randoms:get_string()),
|
||||
Item = #block_item{jid = JID},
|
||||
lists:foreach(
|
||||
fun(SubEl) ->
|
||||
#iq{type = error} =
|
||||
@ -211,7 +212,7 @@ malformed_get(Config) ->
|
||||
#privacy_query{default = none},
|
||||
#privacy_query{lists = [#privacy_list{name = <<"1">>},
|
||||
#privacy_list{name = <<"2">>}]},
|
||||
#block{items = [JID]}, #unblock{items = [JID]},
|
||||
#block{items = [Item]}, #unblock{items = [Item]},
|
||||
#block{}, #unblock{}]),
|
||||
disconnect(Config).
|
||||
|
||||
@ -225,7 +226,9 @@ malformed_set(Config) ->
|
||||
#privacy_list{name = <<"2">>}]},
|
||||
#block{},
|
||||
#block_list{},
|
||||
#block_list{items = [jid:make(randoms:get_string())]}]),
|
||||
#block_list{
|
||||
items = [#block_item{
|
||||
jid = jid:make(randoms:get_string())}]}]),
|
||||
disconnect(Config).
|
||||
|
||||
malformed_type_value(Config) ->
|
||||
@ -609,24 +612,25 @@ set_default(Config, Name) ->
|
||||
|
||||
get_block(Config) ->
|
||||
case send_recv(Config, #iq{type = get, sub_els = [#block_list{}]}) of
|
||||
#iq{type = result, sub_els = [#block_list{items = JIDs}]} ->
|
||||
lists:sort(JIDs);
|
||||
#iq{type = result, sub_els = [#block_list{items = Items}]} ->
|
||||
lists:sort([JID || #block_item{jid = JID} <- Items]);
|
||||
#iq{type = error} = Err ->
|
||||
xmpp:get_error(Err)
|
||||
end.
|
||||
|
||||
set_block(Config, JIDs) ->
|
||||
Items = [#block_item{jid = JID} || JID <- JIDs],
|
||||
case send_recv(Config, #iq{type = set,
|
||||
sub_els = [#block{items = JIDs}]}) of
|
||||
sub_els = [#block{items = Items}]}) of
|
||||
#iq{type = result, sub_els = []} ->
|
||||
{#iq{id = I1, sub_els = [#block{items = Items}]},
|
||||
{#iq{id = I1, sub_els = [#block{items = Items1}]},
|
||||
#iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} =
|
||||
?recv2(#iq{type = set, sub_els = [#block{}]},
|
||||
#iq{type = set, sub_els = [#privacy_query{}]}),
|
||||
send(Config, #iq{type = result, id = I1}),
|
||||
send(Config, #iq{type = result, id = I2}),
|
||||
ct:comment("Checking if all JIDs present in the push"),
|
||||
true = lists:sort(JIDs) == lists:sort(Items),
|
||||
true = lists:sort(Items) == lists:sort(Items1),
|
||||
ct:comment("Getting name of the corresponding privacy list"),
|
||||
[#privacy_list{name = Name}] = Lists,
|
||||
{ok, Name};
|
||||
@ -636,17 +640,18 @@ set_block(Config, JIDs) ->
|
||||
|
||||
set_unblock(Config, JIDs) ->
|
||||
ct:comment("Unblocking ~p", [JIDs]),
|
||||
Items = [#block_item{jid = JID} || JID <- JIDs],
|
||||
case send_recv(Config, #iq{type = set,
|
||||
sub_els = [#unblock{items = JIDs}]}) of
|
||||
sub_els = [#unblock{items = Items}]}) of
|
||||
#iq{type = result, sub_els = []} ->
|
||||
{#iq{id = I1, sub_els = [#unblock{items = Items}]},
|
||||
{#iq{id = I1, sub_els = [#unblock{items = Items1}]},
|
||||
#iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} =
|
||||
?recv2(#iq{type = set, sub_els = [#unblock{}]},
|
||||
#iq{type = set, sub_els = [#privacy_query{}]}),
|
||||
send(Config, #iq{type = result, id = I1}),
|
||||
send(Config, #iq{type = result, id = I2}),
|
||||
ct:comment("Checking if all JIDs present in the push"),
|
||||
true = lists:sort(JIDs) == lists:sort(Items),
|
||||
true = lists:sort(Items) == lists:sort(Items1),
|
||||
ct:comment("Getting name of the corresponding privacy list"),
|
||||
[#privacy_list{name = Name}] = Lists,
|
||||
{ok, Name};
|
||||
|
Loading…
Reference in New Issue
Block a user