Update the 'api/v2/subscriptions' API

This commit is contained in:
Feng Lee 2017-11-18 13:23:51 +08:00
parent 1d0e17b89c
commit f01deec950
2 changed files with 9 additions and 6 deletions

View File

@ -458,8 +458,7 @@ subscription_list(Key, PageNo, PageSize) ->
Keys = ets:lookup(mqtt_subscription, Key), Keys = ets:lookup(mqtt_subscription, Key),
Fun = case length(Keys) == 0 of Fun = case length(Keys) == 0 of
true -> true ->
MP = {{Key, '_'}, '_'}, fun() -> ets:match_object(mqtt_subproperty, {{Key, '_'}, '_'}) end;
fun() -> ets:match_object(mqtt_subproperty, MP) end;
false -> false ->
fun() -> fun() ->
lists:map(fun({S, T}) ->[R] = ets:lookup(mqtt_subproperty, {T, S}), R end, Keys) lists:map(fun({S, T}) ->[R] = ets:lookup(mqtt_subproperty, {T, S}), R end, Keys)

View File

@ -241,10 +241,14 @@ subscription_list('GET', Params, Node, Key) ->
Data = emqttd_mgmt:subscription_list(l2a(Node), l2b(Key), PageNo, PageSize), Data = emqttd_mgmt:subscription_list(l2a(Node), l2b(Key), PageNo, PageSize),
{ok, [{objects, [subscription_row(Row) || Row <- Data]}]}. {ok, [{objects, [subscription_row(Row) || Row <- Data]}]}.
subscription_row({{Topic, ClientId}, Option}) when is_pid(ClientId) -> subscription_row({{Topic, SubPid}, Options}) when is_pid(SubPid) ->
subscription_row({{Topic, l2b(pid_to_list(ClientId))}, Option}); subscription_row({{Topic, {undefined, SubPid}}, Options});
subscription_row({{Topic, ClientId}, Option}) -> subscription_row({{Topic, {SubId, SubPid}}, Options}) ->
Qos = get_value(qos, Option), Qos = proplists:get_value(qos, Options),
ClientId = case SubId of
undefined -> list_to_binary(pid_to_list(SubPid));
SubId -> SubId
end,
[{client_id, ClientId}, {topic, Topic}, {qos, Qos}]. [{client_id, ClientId}, {topic, Topic}, {qos, Qos}].
%%-------------------------------------------------------------------------- %%--------------------------------------------------------------------------