Skip to content

Commit

Permalink
user registration let it show immediately in list of registered users
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed Jun 12, 2024
1 parent 28fdea0 commit 64c1880
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/ejabberd_web_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -553,23 +553,26 @@ process_admin(Host, #request{path = [<<"users">>, <<"diapason">>, Diap | RPath]
lang = Lang} = R, AJID)
when is_binary(Host) ->
Level = 5 + length(RPath),
Res = list_users_in_diapason(Host, Level, 30, RPath, R, Diap),
RegisterEl = make_command(register, R, [{<<"host">>, Host}], []),
Res = list_users_in_diapason(Host, Level, 30, RPath, R, Diap, RegisterEl),
make_xhtml([?XCT(<<"h1">>, ?T("Users"))] ++ Res, Host,
Lang, AJID, Level);

process_admin(Host, #request{path = [<<"users">>, <<"top">>, Attribute | RPath],
lang = Lang} = R, AJID)
when is_binary(Host) ->
Level = 5 + length(RPath),
Res = list_users_top(Host, Level, 30, RPath, R, Attribute),
RegisterEl = make_command(register, R, [{<<"host">>, Host}], []),
Res = list_users_top(Host, Level, 30, RPath, R, Attribute, RegisterEl),
make_xhtml([?XCT(<<"h1">>, ?T("Users"))] ++ Res, Host,
Lang, AJID, Level);

process_admin(Host, #request{path = [<<"users">> | RPath],
lang = Lang} = R, AJID)
when is_binary(Host) ->
Level = 3 + length(RPath),
Res = list_users(Host, Level, 30, RPath, R),
RegisterEl = make_command(register, R, [{<<"host">>, Host}], []),
Res = list_users(Host, Level, 30, RPath, R, RegisterEl),
make_xhtml([?XCT(<<"h1">>, ?T("Users"))] ++ Res, Host,
Lang, AJID, Level);

Expand Down Expand Up @@ -705,7 +708,7 @@ maybe_disclaimer_not_admin(MenuItems, AJID, _Lang) ->

%% @format-begin

list_users(Host, Level, PageSize, RPath, R) ->
list_users(Host, Level, PageSize, RPath, R, RegisterEl) ->
Usernames =
case make_command_raw_value(registered_users, R, [{<<"host">>, Host}]) of
As when is_list(As) ->
Expand All @@ -718,12 +721,12 @@ list_users(Host, Level, PageSize, RPath, R) ->
end,
case length(Usernames) of
N when N =< 10 ->
list_users(Host, Level, PageSize, RPath, R, Usernames);
list_users(Host, Level, PageSize, RPath, R, Usernames, RegisterEl);
N when N > 10 ->
list_users_diapason(Host, R, Usernames, N)
list_users_diapason(Host, R, Usernames, N, RegisterEl)
end.

list_users(Host, Level, PageSize, RPath, R, Usernames) ->
list_users(Host, Level, PageSize, RPath, R, Usernames, RegisterEl) ->
Columns =
[<<"user">>,
{<<"offline">>, right},
Expand Down Expand Up @@ -758,14 +761,14 @@ list_users(Host, Level, PageSize, RPath, R, Usernames) ->
R,
[{<<"user">>, Username}, {<<"host">>, Host}])))}
|| Username <- Usernames],
[make_command(register, R, [{<<"host">>, Host}], []),
[RegisterEl,
make_command(registered_users, R, [], [{only, presentation}]),
make_command(get_offline_count, R, [], [{only, presentation}]),
make_command(get_roster_count, R, [], [{only, presentation}]),
make_command(get_last, R, [], [{only, presentation}]),
make_table(PageSize, RPath, Columns, Rows)].

list_users_diapason(Host, R, Usernames, N) ->
list_users_diapason(Host, R, Usernames, N, RegisterEl) ->
URLFunc = fun url_func/1,
SUsers = [{Host, U} || U <- Usernames],
NParts = trunc(math:sqrt(N * 6.17999999999999993783e-1)) + 1,
Expand All @@ -790,7 +793,7 @@ list_users_diapason(Host, R, Usernames, N) ->
[?AC(URLFunc({user_diapason, K, L}), Name), ?BR]
end,
lists:seq(1, N, M)),
[make_command(register, R, [{<<"host">>, Host}], []),
[RegisterEl,
make_command(get_offline_count, R, [], [{only, presentation}]),
?AC(<<"top/offline/">>, <<"View Top Offline Queues">>),
make_command(get_roster_count, R, [], [{only, presentation}]),
Expand All @@ -800,7 +803,7 @@ list_users_diapason(Host, R, Usernames, N) ->
make_command(registered_users, R, [], [{only, presentation}])]
++ FUsers.

list_users_in_diapason(Host, Level, PageSize, RPath, R, Diap) ->
list_users_in_diapason(Host, Level, PageSize, RPath, R, Diap, RegisterEl) ->
Usernames =
case make_command_raw_value(registered_users, R, [{<<"host">>, Host}]) of
As when is_list(As) ->
Expand All @@ -817,9 +820,9 @@ list_users_in_diapason(Host, Level, PageSize, RPath, R, Diap) ->
N2 = binary_to_integer(S2),
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
Usernames2 = [U || {_, U} <- Sub],
list_users(Host, Level, PageSize, RPath, R, Usernames2).
list_users(Host, Level, PageSize, RPath, R, Usernames2, RegisterEl).

list_users_top(Host, Level, PageSize, RPath, R, Operation) ->
list_users_top(Host, Level, PageSize, RPath, R, Operation, RegisterEl) ->
Usernames =
case make_command_raw_value(registered_users, R, [{<<"host">>, Host}]) of
As when is_list(As) ->
Expand Down Expand Up @@ -857,7 +860,7 @@ list_users_top(Host, Level, PageSize, RPath, R, Operation) ->
USorted
end,
Usernames2 = [U || {U, _} <- lists:sublist(UReversed, 100)],
list_users(Host, Level, PageSize, RPath, R, Usernames2).
list_users(Host, Level, PageSize, RPath, R, Usernames2, RegisterEl).

get_lastactivity_menuitem_list(Server) ->
case gen_mod:is_loaded(Server, mod_last) of
Expand Down

0 comments on commit 64c1880

Please sign in to comment.