From 61b7cdd025aaddb0bc979613f1143ae2d48d851f Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sat, 15 Apr 2023 15:24:10 +0100 Subject: [PATCH] Added "followedonly" and "excludeblocked" params to `GET /arbitrary/resources` and `GET /arbitrary/resources/search`, as well as `LIST_QDN_RESOURCES` and `SEARCH_QDN_RESOURCES` Q-Apps actions. --- Q-Apps.md | 4 ++ .../api/resource/ArbitraryResource.java | 10 ++- .../repository/ArbitraryRepository.java | 4 +- .../hsqldb/HSQLDBArbitraryRepository.java | 67 ++++++++++++++++++- src/main/resources/q-apps/q-apps.js | 4 ++ 5 files changed, 82 insertions(+), 7 deletions(-) diff --git a/Q-Apps.md b/Q-Apps.md index c659abd7..4b20d04b 100644 --- a/Q-Apps.md +++ b/Q-Apps.md @@ -303,6 +303,8 @@ let res = await qortalRequest({ default: true, // Optional includeStatus: false, // Optional - will take time to respond, so only request if necessary includeMetadata: false, // Optional - will take time to respond, so only request if necessary + followedOnly: false, // Optional - include followed names only + excludeBlocked: false, // Optional - exclude blocked content limit: 100, offset: 0, reverse: true @@ -321,6 +323,8 @@ let res = await qortalRequest({ default: false, // Optional - if true, only resources without identifiers are returned includeStatus: false, // Optional - will take time to respond, so only request if necessary includeMetadata: false, // Optional - will take time to respond, so only request if necessary + followedOnly: false, // Optional - include followed names only + excludeBlocked: false, // Optional - exclude blocked content limit: 100, offset: 0, reverse: true diff --git a/src/main/java/org/qortal/api/resource/ArbitraryResource.java b/src/main/java/org/qortal/api/resource/ArbitraryResource.java index 5725c155..f5985078 100644 --- a/src/main/java/org/qortal/api/resource/ArbitraryResource.java +++ b/src/main/java/org/qortal/api/resource/ArbitraryResource.java @@ -102,6 +102,8 @@ public class ArbitraryResource { @Parameter(ref = "limit") @QueryParam("limit") Integer limit, @Parameter(ref = "offset") @QueryParam("offset") Integer offset, @Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse, + @Parameter(description = "Include followed names only") @QueryParam("followedonly") Boolean followedOnly, + @Parameter(description = "Exclude blocked content") @QueryParam("excludeblocked") Boolean excludeBlocked, @Parameter(description = "Filter names by list") @QueryParam("namefilter") String nameFilter, @Parameter(description = "Include status") @QueryParam("includestatus") Boolean includeStatus, @Parameter(description = "Include metadata") @QueryParam("includemetadata") Boolean includeMetadata) { @@ -135,7 +137,7 @@ public class ArbitraryResource { } List resources = repository.getArbitraryRepository() - .getArbitraryResources(service, identifier, names, defaultRes, limit, offset, reverse); + .getArbitraryResources(service, identifier, names, defaultRes, followedOnly, excludeBlocked, limit, offset, reverse); if (resources == null) { return new ArrayList<>(); @@ -178,6 +180,8 @@ public class ArbitraryResource { @Parameter(ref = "limit") @QueryParam("limit") Integer limit, @Parameter(ref = "offset") @QueryParam("offset") Integer offset, @Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse, + @Parameter(description = "Include followed names only") @QueryParam("followedonly") Boolean followedOnly, + @Parameter(description = "Exclude blocked content") @QueryParam("excludeblocked") Boolean excludeBlocked, @Parameter(description = "Include status") @QueryParam("includestatus") Boolean includeStatus, @Parameter(description = "Include metadata") @QueryParam("includemetadata") Boolean includeMetadata) { @@ -192,7 +196,7 @@ public class ArbitraryResource { } List resources = repository.getArbitraryRepository() - .searchArbitraryResources(service, query, identifier, names, usePrefixOnly, defaultRes, limit, offset, reverse); + .searchArbitraryResources(service, query, identifier, names, usePrefixOnly, defaultRes, followedOnly, excludeBlocked, limit, offset, reverse); if (resources == null) { return new ArrayList<>(); @@ -253,7 +257,7 @@ public class ArbitraryResource { String name = creatorName.name; if (name != null) { List resources = repository.getArbitraryRepository() - .getArbitraryResources(service, identifier, Arrays.asList(name), defaultRes, null, null, reverse); + .getArbitraryResources(service, identifier, Arrays.asList(name), defaultRes, null, null, null, null, reverse); if (includeStatus != null && includeStatus) { resources = ArbitraryTransactionUtils.addStatusToResources(resources); diff --git a/src/main/java/org/qortal/repository/ArbitraryRepository.java b/src/main/java/org/qortal/repository/ArbitraryRepository.java index cd1b582b..9eea6bc2 100644 --- a/src/main/java/org/qortal/repository/ArbitraryRepository.java +++ b/src/main/java/org/qortal/repository/ArbitraryRepository.java @@ -24,9 +24,9 @@ public interface ArbitraryRepository { public ArbitraryTransactionData getLatestTransaction(String name, Service service, Method method, String identifier) throws DataException; - public List getArbitraryResources(Service service, String identifier, List names, boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException; + public List getArbitraryResources(Service service, String identifier, List names, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException; - public List searchArbitraryResources(Service service, String query, String identifier, List names, boolean prefixOnly, boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException; + public List searchArbitraryResources(Service service, String query, String identifier, List names, boolean prefixOnly, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException; public List getArbitraryResourceCreatorNames(Service service, String identifier, boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException; diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java index 443f7c6b..8d94c8bd 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java @@ -16,6 +16,7 @@ import org.qortal.arbitrary.ArbitraryDataFile; import org.qortal.transaction.ArbitraryTransaction; import org.qortal.transaction.Transaction.ApprovalStatus; import org.qortal.utils.Base58; +import org.qortal.utils.ListUtils; import java.sql.ResultSet; import java.sql.SQLException; @@ -284,7 +285,8 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { @Override public List getArbitraryResources(Service service, String identifier, List names, - boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException { + boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, + Integer limit, Integer offset, Boolean reverse) throws DataException { StringBuilder sql = new StringBuilder(512); List bindParams = new ArrayList<>(); @@ -319,6 +321,36 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { sql.append(")"); } + // Handle "followed only" + if (followedOnly != null && followedOnly) { + List followedNames = ListUtils.followedNames(); + if (followedNames != null && !followedNames.isEmpty()) { + sql.append(" AND name IN (?"); + bindParams.add(followedNames.get(0)); + + for (int i = 1; i < followedNames.size(); ++i) { + sql.append(", ?"); + bindParams.add(followedNames.get(i)); + } + sql.append(")"); + } + } + + // Handle "exclude blocked" + if (excludeBlocked != null && excludeBlocked) { + List blockedNames = ListUtils.blockedNames(); + if (blockedNames != null && !blockedNames.isEmpty()) { + sql.append(" AND name NOT IN (?"); + bindParams.add(blockedNames.get(0)); + + for (int i = 1; i < blockedNames.size(); ++i) { + sql.append(", ?"); + bindParams.add(blockedNames.get(i)); + } + sql.append(")"); + } + } + sql.append(" GROUP BY name, service, identifier ORDER BY name COLLATE SQL_TEXT_UCC_NO_PAD"); if (reverse != null && reverse) { @@ -361,7 +393,8 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { @Override public List searchArbitraryResources(Service service, String query, String identifier, List names, boolean prefixOnly, - boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException { + boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, + Integer limit, Integer offset, Boolean reverse) throws DataException { StringBuilder sql = new StringBuilder(512); List bindParams = new ArrayList<>(); @@ -417,6 +450,36 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { sql.append(")"); } + // Handle "followed only" + if (followedOnly != null && followedOnly) { + List followedNames = ListUtils.followedNames(); + if (followedNames != null && !followedNames.isEmpty()) { + sql.append(" AND name IN (?"); + bindParams.add(followedNames.get(0)); + + for (int i = 1; i < followedNames.size(); ++i) { + sql.append(", ?"); + bindParams.add(followedNames.get(i)); + } + sql.append(")"); + } + } + + // Handle "exclude blocked" + if (excludeBlocked != null && excludeBlocked) { + List blockedNames = ListUtils.blockedNames(); + if (blockedNames != null && !blockedNames.isEmpty()) { + sql.append(" AND name NOT IN (?"); + bindParams.add(blockedNames.get(0)); + + for (int i = 1; i < blockedNames.size(); ++i) { + sql.append(", ?"); + bindParams.add(blockedNames.get(i)); + } + sql.append(")"); + } + } + sql.append(" GROUP BY name, service, identifier ORDER BY date_created"); if (reverse != null && reverse) { diff --git a/src/main/resources/q-apps/q-apps.js b/src/main/resources/q-apps/q-apps.js index f72d8794..ca2d75c0 100644 --- a/src/main/resources/q-apps/q-apps.js +++ b/src/main/resources/q-apps/q-apps.js @@ -190,6 +190,8 @@ window.addEventListener("message", (event) => { if (data.default != null) url = url.concat("&default=" + new Boolean(data.default).toString()); if (data.includeStatus != null) url = url.concat("&includestatus=" + new Boolean(data.includeStatus).toString()); if (data.includeMetadata != null) url = url.concat("&includemetadata=" + new Boolean(data.includeMetadata).toString()); + if (data.followedOnly != null) url = url.concat("&followedonly=" + new Boolean(data.followedOnly).toString()); + if (data.excludeBlocked != null) url = url.concat("&excludeblocked=" + new Boolean(data.excludeBlocked).toString()); if (data.limit != null) url = url.concat("&limit=" + data.limit); if (data.offset != null) url = url.concat("&offset=" + data.offset); if (data.reverse != null) url = url.concat("&reverse=" + new Boolean(data.reverse).toString()); @@ -206,6 +208,8 @@ window.addEventListener("message", (event) => { if (data.default != null) url = url.concat("&default=" + new Boolean(data.default).toString()); if (data.includeStatus != null) url = url.concat("&includestatus=" + new Boolean(data.includeStatus).toString()); if (data.includeMetadata != null) url = url.concat("&includemetadata=" + new Boolean(data.includeMetadata).toString()); + if (data.followedOnly != null) url = url.concat("&followedonly=" + new Boolean(data.followedOnly).toString()); + if (data.excludeBlocked != null) url = url.concat("&excludeblocked=" + new Boolean(data.excludeBlocked).toString()); if (data.limit != null) url = url.concat("&limit=" + data.limit); if (data.offset != null) url = url.concat("&offset=" + data.offset); if (data.reverse != null) url = url.concat("&reverse=" + new Boolean(data.reverse).toString());