Skip to content

Commit

Permalink
fix tests, fix token moderation
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeadi committed Nov 4, 2024
1 parent 1013992 commit bc9f2f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/main/java/io/getstream/client/ModerationClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.getstream.client;

import static io.getstream.core.utils.Auth.buildModerationToken;
import static io.getstream.core.utils.Auth.buildReactionsToken;
import static io.getstream.core.utils.Routes.*;
import static io.getstream.core.utils.Serialization.*;
Expand Down Expand Up @@ -33,19 +34,19 @@ public CompletableFuture<Response> flagActivity(
}

public CompletableFuture<Response> flagReaction(
String entityId, String entityCreatorId, String reason, Map<String, Object> options)
String entityId, String reportingUser, String reason, Map<String, Object> options)
throws StreamException {
return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options);
return flag("stream:feeds:v2:reaction", entityId, reportingUser, reason, options);
}

private CompletableFuture<Response> flag(
String entityType,
String entityId,
String entityCreatorId,
String reportingUser,
String reason,
Map<String, Object> options)
throws StreamException {
final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE);
return mod.flag(token, entityType, entityId, entityCreatorId, reason, options);
final Token token = buildModerationToken(secret, Auth.TokenAction.WRITE);
return mod.flag(token, entityType, entityId, reportingUser, reason, options);
}
}
18 changes: 11 additions & 7 deletions src/main/java/io/getstream/core/Moderation.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,28 @@ public CompletableFuture<Response> flag(
Token token,
String entityType,
String entityId,
String entityCreatorId,
String reason,
String reportingUser,
String Reason,
Map<String, Object> options)
throws StreamException {
try {
final byte[] payload =
toJSON(
new Object() {
public final String UserId = entityCreatorId;
public final String EntityType = entityType;
public final String EntityId = entityId;
public final String Reason = reason;
public final String user_id = reportingUser;
public final String entity_type = entityType;
public final String entity_id = entityId;
public final String reason = Reason;
});

final URL url = buildModerationFlagURL(baseURL);
String strsing = new String(payload);
System.out.println(strsing);
final URL url = buildModerationFlagURL(baseURL);
return httpClient.execute(buildPost(url, key, token, payload));
} catch (JsonProcessingException | MalformedURLException | URISyntaxException e) {
throw new CompletionException(e);
} catch (Exception e){
throw e;
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/io/getstream/core/utils/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public enum TokenResource {
OPEN_GRAPH("url"),
PERSONALIZATION("personalization"),
REACTIONS("reactions"),
USERS("users");
USERS("users"),
MODERATION("moderation");

private final String resource;

Expand Down Expand Up @@ -98,6 +99,10 @@ public static Token buildReactionsToken(String secret, TokenAction action) {
return buildBackendToken(secret, TokenResource.REACTIONS, action, "*");
}

public static Token buildModerationToken(String secret, TokenAction action) {
return buildBackendToken(secret, TokenResource.MODERATION, action, "*");
}

public static Token buildAnalyticsToken(String secret, TokenAction action) {
return buildBackendToken(secret, TokenResource.ANALYTICS, action, "*");
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/io/getstream/client/ModerationClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import io.getstream.core.http.Response;
import io.getstream.core.models.*;
import io.getstream.core.models.Activity;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Date;
import java.util.UUID;
import org.junit.*;
Expand Down Expand Up @@ -65,12 +69,15 @@ public void testFlagReaction() throws Exception {
assertNotNull(activityResponse);

Reaction reactionResponse =
client.reactions().add("user123", "like", activityResponse.getID()).join();
client.reactions().add("test", "like", activityResponse.getID()).join();
assertNotNull(reactionResponse);

Response flagResponse =
moderationClient.flagReaction(reactionResponse.getId(), "bobby", "blood", null).join();
moderationClient.flagReaction(reactionResponse.getId(), "vishal", "blood", null).join();
assertNotNull(flagResponse);
assertEquals(201, flagResponse.getCode());
assertNotNull(flagResponse);

}

@Test
Expand Down

0 comments on commit bc9f2f9

Please sign in to comment.