mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
mod_mam: Add "request_activates_archiving" option
Enabling "request_activates_archiving" tells mod_mam not to store any messages for a user until his client issued a MAM request, regardless of mod_mam's "default" option. Once a MAM request is issued, messages are archived as usual.
This commit is contained in:
parent
0183b2487e
commit
a61b0c303d
@ -360,7 +360,13 @@ process_iq(#jid{luser = LUser, lserver = LServer},
|
|||||||
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]}.
|
||||||
|
|
||||||
process_iq(LServer, From, To, IQ, SubEl, Fs, MsgType) ->
|
process_iq(LServer, #jid{luser = LUser} = From, To, IQ, SubEl, Fs, MsgType) ->
|
||||||
|
case MsgType of
|
||||||
|
chat ->
|
||||||
|
maybe_activate_mam(LUser, LServer);
|
||||||
|
{groupchat, _Role, _MUCState} ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
case catch lists:foldl(
|
case catch lists:foldl(
|
||||||
fun({<<"start">>, [Data|_]}, {_, End, With, RSM}) ->
|
fun({<<"start">>, [Data|_]}, {_, End, With, RSM}) ->
|
||||||
{{_, _, _} = jlib:datetime_string_to_timestamp(Data),
|
{{_, _, _} = jlib:datetime_string_to_timestamp(Data),
|
||||||
@ -620,6 +626,13 @@ get_prefs(LUser, LServer) ->
|
|||||||
{ok, Prefs} ->
|
{ok, Prefs} ->
|
||||||
Prefs;
|
Prefs;
|
||||||
error ->
|
error ->
|
||||||
|
ActivateOpt = gen_mod:get_module_opt(
|
||||||
|
LServer, ?MODULE, request_activates_archiving,
|
||||||
|
fun(B) when is_boolean(B) -> B end, false),
|
||||||
|
case ActivateOpt of
|
||||||
|
true ->
|
||||||
|
#archive_prefs{us = {LUser, LServer}, default = never};
|
||||||
|
false ->
|
||||||
Default = gen_mod:get_module_opt(
|
Default = gen_mod:get_module_opt(
|
||||||
LServer, ?MODULE, default,
|
LServer, ?MODULE, default,
|
||||||
fun(always) -> always;
|
fun(always) -> always;
|
||||||
@ -627,6 +640,7 @@ get_prefs(LUser, LServer) ->
|
|||||||
(roster) -> roster
|
(roster) -> roster
|
||||||
end, never),
|
end, never),
|
||||||
#archive_prefs{us = {LUser, LServer}, default = Default}
|
#archive_prefs{us = {LUser, LServer}, default = Default}
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_prefs(LUser, LServer, mnesia) ->
|
get_prefs(LUser, LServer, mnesia) ->
|
||||||
@ -654,6 +668,34 @@ get_prefs(LUser, LServer, odbc) ->
|
|||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
maybe_activate_mam(LUser, LServer) ->
|
||||||
|
ActivateOpt = gen_mod:get_module_opt(LServer, ?MODULE,
|
||||||
|
request_activates_archiving,
|
||||||
|
fun(B) when is_boolean(B) -> B end,
|
||||||
|
false),
|
||||||
|
case ActivateOpt of
|
||||||
|
true ->
|
||||||
|
Res = cache_tab:lookup(archive_prefs, {LUser, LServer},
|
||||||
|
fun() ->
|
||||||
|
get_prefs(LUser, LServer,
|
||||||
|
gen_mod:db_type(LServer,
|
||||||
|
?MODULE))
|
||||||
|
end),
|
||||||
|
case Res of
|
||||||
|
{ok, _Prefs} ->
|
||||||
|
ok;
|
||||||
|
error ->
|
||||||
|
Default = gen_mod:get_module_opt(LServer, ?MODULE, default,
|
||||||
|
fun(always) -> always;
|
||||||
|
(never) -> never;
|
||||||
|
(roster) -> roster
|
||||||
|
end, never),
|
||||||
|
write_prefs(LUser, LServer, LServer, Default, [], [])
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
select_and_send(LServer, From, To, Start, End, With, RSM, IQ, MsgType) ->
|
select_and_send(LServer, From, To, Start, End, With, RSM, IQ, MsgType) ->
|
||||||
DBType = case gen_mod:db_type(LServer, ?MODULE) of
|
DBType = case gen_mod:db_type(LServer, ?MODULE) of
|
||||||
odbc -> {odbc, LServer};
|
odbc -> {odbc, LServer};
|
||||||
@ -1131,8 +1173,10 @@ mod_opt_type(default) ->
|
|||||||
(roster) -> roster
|
(roster) -> roster
|
||||||
end;
|
end;
|
||||||
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
||||||
|
mod_opt_type(request_activates_archiving) ->
|
||||||
|
fun (B) when is_boolean(B) -> B end;
|
||||||
mod_opt_type(store_body_only) ->
|
mod_opt_type(store_body_only) ->
|
||||||
fun (B) when is_boolean(B) -> B end;
|
fun (B) when is_boolean(B) -> B end;
|
||||||
mod_opt_type(_) ->
|
mod_opt_type(_) ->
|
||||||
[cache_life_time, cache_size, db_type, default, iqdisc,
|
[cache_life_time, cache_size, db_type, default, iqdisc,
|
||||||
store_body_only].
|
request_activates_archiving, store_body_only].
|
||||||
|
Loading…
Reference in New Issue
Block a user