mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
If big offline message queue, show only subset on WebAdmin (EJAB-1095)
SVN Revision: 2896
This commit is contained in:
parent
855d427182
commit
9f5246cacc
@ -530,8 +530,9 @@ webadmin_page(Acc, _, _) -> Acc.
|
||||
user_queue(User, Server, Query, Lang) ->
|
||||
US = {jlib:nodeprep(User), jlib:nameprep(Server)},
|
||||
Res = user_queue_parse_query(US, Query),
|
||||
Msgs = lists:keysort(#offline_msg.timestamp,
|
||||
mnesia:dirty_read({offline_msg, US})),
|
||||
MsgsAll = lists:keysort(#offline_msg.timestamp,
|
||||
mnesia:dirty_read({offline_msg, US})),
|
||||
Msgs = get_messages_subset(User, Server, MsgsAll),
|
||||
FMsgs =
|
||||
lists:map(
|
||||
fun(#offline_msg{timestamp = TimeStamp, from = From, to = To,
|
||||
@ -616,6 +617,27 @@ us_to_list({User, Server}) ->
|
||||
get_queue_length(User, Server) ->
|
||||
length(mnesia:dirty_read({offline_msg, {User, Server}})).
|
||||
|
||||
get_messages_subset(User, Host, MsgsAll) ->
|
||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access_max_user_messages,
|
||||
max_user_offline_messages),
|
||||
MaxOfflineMsgs = case get_max_user_messages(Access, User, Host) of
|
||||
Number when is_integer(Number) -> Number;
|
||||
_ -> 100
|
||||
end,
|
||||
Length = length(MsgsAll),
|
||||
get_messages_subset2(MaxOfflineMsgs, Length, MsgsAll).
|
||||
|
||||
get_messages_subset2(Max, Length, MsgsAll) when Length =< Max*2 ->
|
||||
MsgsAll;
|
||||
get_messages_subset2(Max, Length, MsgsAll) ->
|
||||
FirstN = Max,
|
||||
{MsgsFirstN, Msgs2} = lists:split(FirstN, MsgsAll),
|
||||
MsgsLastN = lists:nthtail(Length - FirstN - FirstN, Msgs2),
|
||||
NoJID = jlib:make_jid("...", "...", ""),
|
||||
IntermediateMsg = #offline_msg{timestamp = now(), from = NoJID, to = NoJID,
|
||||
packet = {xmlelement, "...", [], []}},
|
||||
MsgsFirstN ++ [IntermediateMsg] ++ MsgsLastN.
|
||||
|
||||
webadmin_user(Acc, User, Server, Lang) ->
|
||||
QueueLen = get_queue_length(jlib:nodeprep(User), jlib:nameprep(Server)),
|
||||
FQueueLen = [?AC("queue/",
|
||||
|
@ -376,7 +376,7 @@ user_queue(User, Server, Query, Lang) ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
US = {LUser, LServer},
|
||||
Res = user_queue_parse_query(Username, LServer, Query),
|
||||
Msgs = case catch ejabberd_odbc:sql_query(
|
||||
MsgsAll = case catch ejabberd_odbc:sql_query(
|
||||
LServer,
|
||||
["select username, xml from spool"
|
||||
" where username='", Username, "'"
|
||||
@ -394,6 +394,7 @@ user_queue(User, Server, Query, Lang) ->
|
||||
_ ->
|
||||
[]
|
||||
end,
|
||||
Msgs = get_messages_subset(User, Server, MsgsAll),
|
||||
FMsgs =
|
||||
lists:map(
|
||||
fun({xmlelement, _Name, _Attrs, _Els} = Msg) ->
|
||||
@ -491,6 +492,25 @@ get_queue_length(Username, LServer) ->
|
||||
0
|
||||
end.
|
||||
|
||||
get_messages_subset(User, Host, MsgsAll) ->
|
||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access_max_user_messages,
|
||||
max_user_offline_messages),
|
||||
MaxOfflineMsgs = case get_max_user_messages(Access, User, Host) of
|
||||
Number when is_integer(Number) -> Number;
|
||||
_ -> 100
|
||||
end,
|
||||
Length = length(MsgsAll),
|
||||
get_messages_subset2(MaxOfflineMsgs, Length, MsgsAll).
|
||||
|
||||
get_messages_subset2(Max, Length, MsgsAll) when Length =< Max*2 ->
|
||||
MsgsAll;
|
||||
get_messages_subset2(Max, Length, MsgsAll) ->
|
||||
FirstN = Max,
|
||||
{MsgsFirstN, Msgs2} = lists:split(FirstN, MsgsAll),
|
||||
MsgsLastN = lists:nthtail(Length - FirstN - FirstN, Msgs2),
|
||||
IntermediateMsg = {xmlelement, "...", [], []},
|
||||
MsgsFirstN ++ [IntermediateMsg] ++ MsgsLastN.
|
||||
|
||||
webadmin_user(Acc, User, Server, Lang) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
|
Loading…
Reference in New Issue
Block a user