25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

minor improvements and binary fix

This commit is contained in:
Christophe Romain 2013-06-24 16:31:38 +02:00
parent 4195259d47
commit 6bfa34e8e0
2 changed files with 10 additions and 17 deletions

View File

@ -1256,7 +1256,7 @@ get_items(NodeId, _From,
Max = (?PUBSUB):escape(i2l(M)), Max = (?PUBSUB):escape(i2l(M)),
{Way, Order} = case Direction of {Way, Order} = case Direction of
aft -> {<<"<">>, <<"desc">>}; aft -> {<<"<">>, <<"desc">>};
before when I == [] -> {<<"is not">>, <<"asc">>}; before when I == <<>> -> {<<"is not">>, <<"asc">>};
before -> {<<">">>, <<"asc">>}; before -> {<<">">>, <<"asc">>};
_ when IncIndex =/= undefined -> _ when IncIndex =/= undefined ->
{<<"<">>, <<"desc">>}; % using index {<<"<">>, <<"desc">>}; % using index
@ -1279,7 +1279,7 @@ get_items(NodeId, _From,
_ -> [<<"modification">>, <<"null">>] _ -> [<<"modification">>, <<"null">>]
end; end;
undefined -> [<<"modification">>, <<"null">>]; undefined -> [<<"modification">>, <<"null">>];
[] -> [<<"modification">>, <<"null">>]; <<>> -> [<<"modification">>, <<"null">>];
I -> I ->
[A, B] = str:tokens((?PUBSUB):escape(i2l(I)), [A, B] = str:tokens((?PUBSUB):escape(i2l(I)),
<<"@">>), <<"@">>),
@ -1306,10 +1306,8 @@ get_items(NodeId, _From,
[<<"itemid">>, <<"publisher">>, <<"creation">>, [<<"itemid">>, <<"publisher">>, <<"creation">>,
<<"modification">>, <<"payload">>], <<"modification">>, <<"payload">>],
RItems} -> RItems} ->
case str:len(RItems) of case RItems of
0 -> {result, {[], #rsm_out{count = Count}}}; [[_, _, _, F, _]|_] ->
_ ->
[_, _, _, F, _] = hd(RItems),
Index = case catch Index = case catch
ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where " ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where "
"nodeid='">>, "nodeid='">>,
@ -1325,11 +1323,8 @@ get_items(NodeId, _From,
RsmOut = #rsm_out{count = Count, index = Index, RsmOut = #rsm_out{count = Count, index = Index,
first = <<"modification@", F/binary>>, first = <<"modification@", F/binary>>,
last = <<"modification@", (i2l(L))/binary>>}, last = <<"modification@", (i2l(L))/binary>>},
{result, {result, {[raw_to_item(NodeId, RItem) || RItem <- RItems], RsmOut}};
{lists:map(fun (RItem) -> raw_to_item(NodeId, RItem) 0 -> {result, {[], #rsm_out{count = Count}}}
end,
RItems),
RsmOut}}
end; end;
_ -> {result, {[], none}} _ -> {result, {[], none}}
end. end.
@ -1523,9 +1518,7 @@ can_fetch_item(owner, _) -> true;
can_fetch_item(member, _) -> true; can_fetch_item(member, _) -> true;
can_fetch_item(publisher, _) -> true; can_fetch_item(publisher, _) -> true;
can_fetch_item(outcast, _) -> false; can_fetch_item(outcast, _) -> false;
can_fetch_item(none, Subscriptions) -> can_fetch_item(none, Subscriptions) -> is_subscribed(Subscriptions).
is_subscribed(Subscriptions);
can_fetch_item(_Affiliation, _Subscription) -> false.
is_subscribed(Subscriptions) -> is_subscribed(Subscriptions) ->
lists:any(fun ({subscribed, _SubId}) -> true; lists:any(fun ({subscribed, _SubId}) -> true;
@ -1691,8 +1684,8 @@ raw_to_item(NodeId,
modification = {ToTime(Modification), JID}, modification = {ToTime(Modification), JID},
payload = Payload}. payload = Payload}.
l2i(L) when is_binary(L) -> jlib:binary_to_integer(L); l2i(I) when is_integer(I) -> I;
l2i(I) when is_integer(I) -> I. l2i(L) when is_binary(L) -> jlib:binary_to_integer(L).
i2l(I) when is_integer(I) -> i2l(I) when is_integer(I) ->
iolist_to_binary(integer_to_list(I)); iolist_to_binary(integer_to_list(I));

View File

@ -325,7 +325,7 @@ delete_node(Host, Node) ->
%% helpers %% helpers
-spec(raw_to_node/2 :: -spec(raw_to_node/2 ::
( (
Host :: mod_pubus:host(), Host :: mod_pubusb:host(),
_ :: {NodeId::mod_pubsub:nodeId(), _ :: {NodeId::mod_pubsub:nodeId(),
Parent::mod_pubsub:nodeId(), Parent::mod_pubsub:nodeId(),
Type::binary(), Type::binary(),