From 9df6e1fe0a23c27bef781e57594b252a449be798 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 12 Jan 2010 12:06:43 +0000 Subject: [PATCH] Support in user list page of WebAdmin when mod_offline is disabled (EJAB-377) SVN Revision: 2878 --- src/mod_offline.erl | 18 ++++++------------ src/mod_offline_odbc.erl | 29 ++++++++++++++--------------- src/web/ejabberd_web_admin.erl | 24 +++++++++++++++++------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/mod_offline.erl b/src/mod_offline.erl index f0a8cef59..5f52c8487 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -39,6 +39,7 @@ remove_expired_messages/0, remove_old_messages/1, remove_user/2, + get_queue_length/2, webadmin_page/3, webadmin_user/4, webadmin_user_parse_query/5]). @@ -702,19 +703,12 @@ user_queue_parse_query(US, Query) -> us_to_list({User, Server}) -> exmpp_jid:to_list(User, Server). +get_queue_length(User, Server) -> + length(mnesia:dirty_read({offline_msg, {User, Server}})). + webadmin_user(Acc, User, Server, Lang) -> - FQueueLen = try - US = { - exmpp_stringprep:nodeprep(User), - exmpp_stringprep:nameprep(Server) - }, - QueueLen = length(mnesia:dirty_read({offline_msg, US})), - [?AC("queue/", - integer_to_list(QueueLen))] - catch - _ -> - [?C("?")] - end, + QueueLen = get_queue_length(exmpp_stringprep:nodeprep(User), exmpp_stringprep:nameprep(Server)), + FQueueLen = [?AC("queue/", integer_to_list(QueueLen))], Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen ++ [?C(" "), ?INPUTT("submit", "removealloffline", "Remove All Offline Messages")]. webadmin_user_parse_query(_, "removealloffline", User, Server, _Query) -> diff --git a/src/mod_offline_odbc.erl b/src/mod_offline_odbc.erl index 6779533dd..3cdaaf747 100644 --- a/src/mod_offline_odbc.erl +++ b/src/mod_offline_odbc.erl @@ -38,6 +38,7 @@ pop_offline_messages/3, get_sm_features/5, remove_user/2, + get_queue_length/2, webadmin_page/3, webadmin_user/4, webadmin_user_parse_query/5]). @@ -495,25 +496,23 @@ user_queue_parse_query(Username, LServer, Query) -> us_to_list({User, Server}) -> exmpp_jid:to_list(User, Server). +get_queue_length(Username, LServer) -> + case catch ejabberd_odbc:sql_query( + LServer, + ["select count(*) from spool" + " where username='", Username, "';"]) of + {selected, [_], [{SCount}]} -> + SCount; + _ -> + 0 + end. + webadmin_user(Acc, User, Server, Lang) -> - FQueueLen = try LUser = exmpp_stringprep:nodeprep(User), LServer = exmpp_stringprep:nameprep(Server), Username = ejabberd_odbc:escape(LUser), - QueueLen = case catch ejabberd_odbc:sql_query( - LServer, - ["select count(*) from spool" - " where username='", Username, "';"]) of - {selected, [_], [{SCount}]} -> - SCount; - _ -> - 0 - end, - [?AC("queue/", QueueLen)] - catch - _ -> - [?C("?")] - end, + QueueLen = get_queue_length(Username, LServer), + FQueueLen = [?AC("queue/", QueueLen)], Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen ++ [?C(" "), ?INPUTT("submit", "removealloffline", "Remove All Offline Messages")]. webadmin_user_parse_query(_, "removealloffline", User, Server, _Query) -> diff --git a/src/web/ejabberd_web_admin.erl b/src/web/ejabberd_web_admin.erl index c4ef3acb8..1681ee9c5 100644 --- a/src/web/ejabberd_web_admin.erl +++ b/src/web/ejabberd_web_admin.erl @@ -1571,6 +1571,7 @@ list_users_in_diapason(Host, Diap, Lang, URLFunc) -> list_given_users(Host, Users, Prefix, Lang, URLFunc) -> ModLast = get_lastactivity_module(Host), + ModOffline = get_offlinemsg_module(Host), ?XE('table', [?XE('thead', [?XE('tr', @@ -1583,14 +1584,10 @@ list_given_users(Host, Users, Prefix, Lang, URLFunc) -> ServerB = list_to_binary(Server), UserB = list_to_binary(User), US = {UserB, ServerB}, - FQueueLen = try - QueueLen = length(mnesia:dirty_read({offline_msg, US})), - [?AC(URLFunc({users_queue, Prefix, + QueueLenStr = get_offlinemsg_length(ModOffline, UserB, ServerB), + FQueueLen = [?AC(URLFunc({users_queue, Prefix, User, Server}), - pretty_string_int(QueueLen))] - catch - _:_ -> [#xmlcdata{cdata = <<"Can't access the offline messages storage.">>}] - end, + QueueLenStr)], FLast = case ejabberd_sm:get_user_resources(UserB, ServerB) of [] -> @@ -1622,6 +1619,19 @@ list_given_users(Host, Users, Prefix, Lang, URLFunc) -> end, Users) )]). +get_offlinemsg_length(ModOffline, User, Server) -> + case ModOffline of + none -> "disabled"; + _ -> pretty_string_int(ModOffline:get_queue_length(User, Server)) + end. + +get_offlinemsg_module(Server) -> + case [mod_offline, mod_offline_odbc] -- gen_mod:loaded_modules(Server) of + [mod_offline, mod_offline_odbc] -> none; + [mod_offline_odbc] -> mod_offline; + [mod_offline] -> mod_offline_odbc + end. + get_lastactivity_module(Server) -> case lists:member(mod_last, gen_mod:loaded_modules(Server)) of true -> mod_last;