mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
mod_mam: Send new preferences when they are set
If a client updates the archiving preferences, include the new preferences with the IQ result (as mandated by XEP-0313).
This commit is contained in:
parent
d6323a7b5e
commit
17be70339c
@ -461,11 +461,13 @@ process_iq(#jid{luser = LUser, lserver = LServer},
|
|||||||
(_, {A, N}) ->
|
(_, {A, N}) ->
|
||||||
{A, N}
|
{A, N}
|
||||||
end, {[], []}, SubEl#xmlel.children)} of
|
end, {[], []}, SubEl#xmlel.children)} of
|
||||||
{Default, {Always, Never}} ->
|
{Default, {Always0, Never0}} ->
|
||||||
case write_prefs(LUser, LServer, LServer, Default,
|
Always = lists:usort(Always0),
|
||||||
lists:usort(Always), lists:usort(Never)) of
|
Never = lists:usort(Never0),
|
||||||
|
case write_prefs(LUser, LServer, LServer, Default, Always, Never) of
|
||||||
ok ->
|
ok ->
|
||||||
IQ#iq{type = result, sub_el = []};
|
NewPrefs = prefs_el(Default, Always, Never, IQ#iq.xmlns),
|
||||||
|
IQ#iq{type = result, sub_el = [NewPrefs]};
|
||||||
_Err ->
|
_Err ->
|
||||||
IQ#iq{type = error,
|
IQ#iq{type = error,
|
||||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
||||||
@ -477,21 +479,11 @@ process_iq(#jid{luser = LUser, lserver = LServer},
|
|||||||
#jid{lserver = LServer},
|
#jid{lserver = LServer},
|
||||||
#iq{type = get, sub_el = #xmlel{name = <<"prefs">>}} = IQ) ->
|
#iq{type = get, sub_el = #xmlel{name = <<"prefs">>}} = IQ) ->
|
||||||
Prefs = get_prefs(LUser, LServer),
|
Prefs = get_prefs(LUser, LServer),
|
||||||
Default = jlib:atom_to_binary(Prefs#archive_prefs.default),
|
PrefsEl = prefs_el(Prefs#archive_prefs.default,
|
||||||
JFun = fun(L) ->
|
Prefs#archive_prefs.always,
|
||||||
[#xmlel{name = <<"jid">>,
|
Prefs#archive_prefs.never,
|
||||||
children = [{xmlcdata, jid:to_string(J)}]}
|
IQ#iq.xmlns),
|
||||||
|| J <- L]
|
IQ#iq{type = result, sub_el = [PrefsEl]};
|
||||||
end,
|
|
||||||
Always = #xmlel{name = <<"always">>,
|
|
||||||
children = JFun(Prefs#archive_prefs.always)},
|
|
||||||
Never = #xmlel{name = <<"never">>,
|
|
||||||
children = JFun(Prefs#archive_prefs.never)},
|
|
||||||
IQ#iq{type = result,
|
|
||||||
sub_el = [#xmlel{name = <<"prefs">>,
|
|
||||||
attrs = [{<<"xmlns">>, IQ#iq.xmlns},
|
|
||||||
{<<"default">>, Default}],
|
|
||||||
children = [Always, Never]}]};
|
|
||||||
process_iq(_, _, #iq{sub_el = SubEl} = IQ) ->
|
process_iq(_, _, #iq{sub_el = SubEl} = IQ) ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
|
||||||
|
|
||||||
@ -874,6 +866,22 @@ get_prefs(LUser, LServer, odbc) ->
|
|||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
prefs_el(Default, Always, Never, NS) ->
|
||||||
|
Default1 = jlib:atom_to_binary(Default),
|
||||||
|
JFun = fun(L) ->
|
||||||
|
[#xmlel{name = <<"jid">>,
|
||||||
|
children = [{xmlcdata, jid:to_string(J)}]}
|
||||||
|
|| J <- L]
|
||||||
|
end,
|
||||||
|
Always1 = #xmlel{name = <<"always">>,
|
||||||
|
children = JFun(Always)},
|
||||||
|
Never1 = #xmlel{name = <<"never">>,
|
||||||
|
children = JFun(Never)},
|
||||||
|
#xmlel{name = <<"prefs">>,
|
||||||
|
attrs = [{<<"xmlns">>, NS},
|
||||||
|
{<<"default">>, Default1}],
|
||||||
|
children = [Always1, Never1]}.
|
||||||
|
|
||||||
maybe_activate_mam(LUser, LServer) ->
|
maybe_activate_mam(LUser, LServer) ->
|
||||||
ActivateOpt = gen_mod:get_module_opt(LServer, ?MODULE,
|
ActivateOpt = gen_mod:get_module_opt(LServer, ?MODULE,
|
||||||
request_activates_archiving,
|
request_activates_archiving,
|
||||||
|
@ -1713,7 +1713,7 @@ mam_master(Config, NS) ->
|
|||||||
?recv1(#presence{}),
|
?recv1(#presence{}),
|
||||||
wait_for_slave(Config),
|
wait_for_slave(Config),
|
||||||
?recv1(#presence{from = Peer}),
|
?recv1(#presence{from = Peer}),
|
||||||
#iq{type = result, sub_els = []} =
|
#iq{type = result, sub_els = [#mam_prefs{xmlns = NS, default = roster}]} =
|
||||||
send_recv(Config,
|
send_recv(Config,
|
||||||
#iq{type = set,
|
#iq{type = set,
|
||||||
sub_els = [#mam_prefs{xmlns = NS,
|
sub_els = [#mam_prefs{xmlns = NS,
|
||||||
@ -1747,7 +1747,7 @@ mam_master(Config, NS) ->
|
|||||||
mam_query_with(Config, Peer, NS),
|
mam_query_with(Config, Peer, NS),
|
||||||
%% mam_query_with(Config, jlib:jid_remove_resource(Peer)),
|
%% mam_query_with(Config, jlib:jid_remove_resource(Peer)),
|
||||||
mam_query_rsm(Config, NS),
|
mam_query_rsm(Config, NS),
|
||||||
#iq{type = result, sub_els = []} =
|
#iq{type = result, sub_els = [#mam_prefs{xmlns = NS, default = never}]} =
|
||||||
send_recv(Config, #iq{type = set,
|
send_recv(Config, #iq{type = set,
|
||||||
sub_els = [#mam_prefs{xmlns = NS,
|
sub_els = [#mam_prefs{xmlns = NS,
|
||||||
default = never}]}),
|
default = never}]}),
|
||||||
@ -1765,7 +1765,7 @@ mam_slave(Config, NS) ->
|
|||||||
wait_for_master(Config),
|
wait_for_master(Config),
|
||||||
send(Config, #presence{}),
|
send(Config, #presence{}),
|
||||||
?recv2(#presence{}, #presence{from = Peer}),
|
?recv2(#presence{}, #presence{from = Peer}),
|
||||||
#iq{type = result, sub_els = []} =
|
#iq{type = result, sub_els = [#mam_prefs{xmlns = NS, default = always}]} =
|
||||||
send_recv(Config,
|
send_recv(Config,
|
||||||
#iq{type = set,
|
#iq{type = set,
|
||||||
sub_els = [#mam_prefs{xmlns = NS, default = always}]}),
|
sub_els = [#mam_prefs{xmlns = NS, default = always}]}),
|
||||||
@ -1776,7 +1776,7 @@ mam_slave(Config, NS) ->
|
|||||||
?recv1(#message{from = Peer, body = [Text],
|
?recv1(#message{from = Peer, body = [Text],
|
||||||
sub_els = [#mam_archived{by = ServerJID}]})
|
sub_els = [#mam_archived{by = ServerJID}]})
|
||||||
end, lists:seq(1, 5)),
|
end, lists:seq(1, 5)),
|
||||||
#iq{type = result, sub_els = []} =
|
#iq{type = result, sub_els = [#mam_prefs{xmlns = NS, default = never}]} =
|
||||||
send_recv(Config, #iq{type = set,
|
send_recv(Config, #iq{type = set,
|
||||||
sub_els = [#mam_prefs{xmlns = NS, default = never}]}),
|
sub_els = [#mam_prefs{xmlns = NS, default = never}]}),
|
||||||
disconnect(Config).
|
disconnect(Config).
|
||||||
|
Loading…
Reference in New Issue
Block a user