List in Service Disco non-empty rooms and provide Node for empty (EJAB-343)

This commit is contained in:
Badlop 2015-12-02 01:50:30 +01:00
parent e5ae35c66b
commit ff22782752
2 changed files with 31 additions and 31 deletions

View File

@ -232,11 +232,12 @@ remove_room_mam(LServer, Host, Name) ->
process_iq_disco_items(Host, From, To, process_iq_disco_items(Host, From, To,
#iq{lang = Lang} = IQ) -> #iq{lang = Lang} = IQ) ->
Rsm = jlib:rsm_decode(IQ), Rsm = jlib:rsm_decode(IQ),
DiscoNode = xml:get_tag_attr_s(<<"node">>, IQ#iq.sub_el),
Res = IQ#iq{type = result, Res = IQ#iq{type = result,
sub_el = sub_el =
[#xmlel{name = <<"query">>, [#xmlel{name = <<"query">>,
attrs = [{<<"xmlns">>, ?NS_DISCO_ITEMS}], attrs = [{<<"xmlns">>, ?NS_DISCO_ITEMS}],
children = iq_disco_items(Host, From, Lang, Rsm)}]}, children = iq_disco_items(Host, From, Lang, DiscoNode, Rsm)}]},
ejabberd_router:route(To, From, jlib:iq_to_xml(Res)). ejabberd_router:route(To, From, jlib:iq_to_xml(Res)).
can_use_nick(_ServerHost, _Host, _JID, <<"">>) -> false; can_use_nick(_ServerHost, _Host, _JID, <<"">>) -> false;
@ -752,37 +753,28 @@ iq_disco_info(ServerHost, Lang) ->
[] []
end. end.
iq_disco_items(Host, From, Lang, none) -> iq_disco_items(Host, From, Lang, <<>>, none) ->
lists:zf(fun (#muc_online_room{name_host = XmlEmpty = #xmlel{name = <<"item">>,
{Name, _Host},
pid = Pid}) ->
case catch gen_fsm:sync_send_all_state_event(Pid,
{get_disco_item,
From, Lang},
100)
of
{item, Desc} ->
flush(),
{true,
#xmlel{name = <<"item">>,
attrs = attrs =
[{<<"jid">>, [{<<"jid">>, <<"conference.localhost">>},
jid:to_string({Name, Host, {<<"node">>, <<"emptyrooms">>},
<<"">>})}, {<<"name">>, translate:translate(Lang, <<"Empty Rooms">>)}],
{<<"name">>, Desc}], children = []},
children = []}}; Query = {get_disco_item, only_non_empty, From, Lang},
_ -> false [XmlEmpty | iq_disco_items_list(Host, get_vh_rooms(Host), Query)];
end iq_disco_items(Host, From, Lang, <<"emptyrooms">>, none) ->
end, get_vh_rooms(Host)); iq_disco_items_list(Host, get_vh_rooms(Host), {get_disco_item, 0, From, Lang});
iq_disco_items(Host, From, Lang, Rsm) -> iq_disco_items(Host, From, Lang, _DiscoNode, Rsm) ->
{Rooms, RsmO} = get_vh_rooms(Host, Rsm), {Rooms, RsmO} = get_vh_rooms(Host, Rsm),
RsmOut = jlib:rsm_encode(RsmO), RsmOut = jlib:rsm_encode(RsmO),
iq_disco_items_list(Host, Rooms, {get_disco_item, all, From, Lang}) ++ RsmOut.
iq_disco_items_list(Host, Rooms, Query) ->
lists:zf(fun (#muc_online_room{name_host = lists:zf(fun (#muc_online_room{name_host =
{Name, _Host}, {Name, _Host},
pid = Pid}) -> pid = Pid}) ->
case catch gen_fsm:sync_send_all_state_event(Pid, case catch gen_fsm:sync_send_all_state_event(Pid,
{get_disco_item, Query,
From, Lang},
100) 100)
of of
{item, Desc} -> {item, Desc} ->
@ -797,9 +789,7 @@ iq_disco_items(Host, From, Lang, Rsm) ->
children = []}}; children = []}};
_ -> false _ -> false
end end
end, end, Rooms).
Rooms)
++ RsmOut.
get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})-> get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})->
AllRooms = lists:sort(get_vh_rooms(Host)), AllRooms = lists:sort(get_vh_rooms(Host)),

View File

@ -712,10 +712,20 @@ handle_event({set_affiliations, Affiliations},
handle_event(_Event, StateName, StateData) -> handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
handle_sync_event({get_disco_item, JID, Lang}, _From, StateName, StateData) -> handle_sync_event({get_disco_item, Filter, JID, Lang}, _From, StateName, StateData) ->
Reply = get_roomdesc_reply(JID, StateData, Len = ?DICT:fold(fun(_, _, Acc) -> Acc + 1 end, 0,
get_roomdesc_tail(StateData, Lang)), StateData#state.users),
Reply = case (Filter == all) or (Filter == Len) or ((Filter /= 0) and (Len /= 0)) of
true ->
get_roomdesc_reply(JID, StateData,
get_roomdesc_tail(StateData, Lang));
false ->
false
end,
{reply, Reply, StateName, StateData}; {reply, Reply, StateName, StateData};
%% This clause is only for backwards compatibility
handle_sync_event({get_disco_item, JID, Lang}, From, StateName, StateData) ->
handle_sync_event({get_disco_item, any, JID, Lang}, From, StateName, StateData);
handle_sync_event(get_config, _From, StateName, handle_sync_event(get_config, _From, StateName,
StateData) -> StateData) ->
{reply, {ok, StateData#state.config}, StateName, {reply, {ok, StateData#state.config}, StateName,