mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
allow check if archive is empty for or user or room
This commit is contained in:
parent
89b9e25588
commit
2e586000d7
@ -40,7 +40,8 @@
|
||||
muc_process_iq/2, muc_filter_message/3, message_is_archived/3,
|
||||
delete_old_messages/2, get_commands_spec/0, msg_to_el/4,
|
||||
get_room_config/4, set_room_option/3, offline_message/1, export/1,
|
||||
mod_options/1, remove_mam_for_user_with_peer/3, remove_mam_for_user/2]).
|
||||
mod_options/1, remove_mam_for_user_with_peer/3, remove_mam_for_user/2,
|
||||
is_empty_for_user/2, is_empty_for_room/3]).
|
||||
|
||||
-include("xmpp.hrl").
|
||||
-include("logger.hrl").
|
||||
@ -72,6 +73,8 @@
|
||||
-callback use_cache(binary()) -> boolean().
|
||||
-callback cache_nodes(binary()) -> [node()].
|
||||
-callback remove_from_archive(binary(), binary(), jid() | none) -> ok | {error, any()}.
|
||||
-callback is_empty_for_user(binary(), binary()) -> boolean().
|
||||
-callback is_empty_for_room(binary(), binary(), binary()) -> boolean().
|
||||
|
||||
-optional_callbacks([use_cache/1, cache_nodes/1]).
|
||||
|
||||
@ -572,6 +575,20 @@ export(LServer) ->
|
||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||
Mod:export(LServer).
|
||||
|
||||
-spec is_empty_for_user(binary(), binary()) -> boolean().
|
||||
is_empty_for_user(User, Server) ->
|
||||
LUser = jid:nodeprep(User),
|
||||
LServer = jid:nameprep(Server),
|
||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||
Mod:is_empty_for_user(LUser, LServer).
|
||||
|
||||
-spec is_empty_for_room(binary(), binary(), binary()) -> boolean().
|
||||
is_empty_for_room(LServer, Name, Host) ->
|
||||
LName = jid:nodeprep(Name),
|
||||
LHost = jid:nameprep(Host),
|
||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||
Mod:is_empty_for_room(LServer, LName, LHost).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
@ -28,7 +28,8 @@
|
||||
|
||||
%% API
|
||||
-export([init/2, remove_user/2, remove_room/3, delete_old_messages/3,
|
||||
extended_fields/0, store/8, write_prefs/4, get_prefs/2, select/6, remove_from_archive/3]).
|
||||
extended_fields/0, store/8, write_prefs/4, get_prefs/2, select/6, remove_from_archive/3,
|
||||
is_empty_for_user/2, is_empty_for_room/3]).
|
||||
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
-include("xmpp.hrl").
|
||||
@ -198,6 +199,13 @@ select(_LServer, JidRequestor,
|
||||
erlang:garbage_collect(),
|
||||
Result.
|
||||
|
||||
is_empty_for_user(LUser, LServer) ->
|
||||
not lists:member({LUser, LServer},
|
||||
mnesia:dirty_all_keys(archive_msg)).
|
||||
|
||||
is_empty_for_room(_LServer, LName, LHost) ->
|
||||
is_empty_for_user(LName, LHost).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
@ -30,7 +30,8 @@
|
||||
|
||||
%% API
|
||||
-export([init/2, remove_user/2, remove_room/3, delete_old_messages/3,
|
||||
extended_fields/0, store/8, write_prefs/4, get_prefs/2, select/6, export/1, remove_from_archive/3]).
|
||||
extended_fields/0, store/8, write_prefs/4, get_prefs/2, select/6, export/1, remove_from_archive/3,
|
||||
is_empty_for_user/2, is_empty_for_room/3]).
|
||||
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
-include("xmpp.hrl").
|
||||
@ -264,6 +265,23 @@ export(_Server) ->
|
||||
[]
|
||||
end}].
|
||||
|
||||
is_empty_for_user(LUser, LServer) ->
|
||||
case ejabberd_sql:sql_query(
|
||||
LServer,
|
||||
?SQL("select @(count(*))d from archive"
|
||||
" where username=%(LUser)s and %(LServer)H")) of
|
||||
{selected, [{Res}]} ->
|
||||
case Res of
|
||||
0 -> true;
|
||||
_ -> false
|
||||
end;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
is_empty_for_room(LServer, LName, LHost) ->
|
||||
LUser = jid:encode({LName, LHost, <<>>}),
|
||||
is_empty_for_user(LUser, LServer).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user