Skip to content

Commit 2b24dae

Browse files
committed
chore: lint moderation files
1 parent 7c9a154 commit 2b24dae

10 files changed

Lines changed: 288 additions & 279 deletions

File tree

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
11
package io.getstream.client;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
3+
import static io.getstream.core.utils.Auth.buildReactionsToken;
4+
import static io.getstream.core.utils.Routes.*;
5+
import static io.getstream.core.utils.Serialization.*;
6+
47
import io.getstream.core.Moderation;
5-
import io.getstream.core.StreamBatch;
68
import io.getstream.core.exceptions.StreamException;
7-
import io.getstream.core.http.HTTPClient;
9+
import io.getstream.core.http.Response;
810
import io.getstream.core.http.Token;
911
import io.getstream.core.utils.Auth;
10-
import java8.util.concurrent.CompletableFuture;
11-
import java8.util.concurrent.CompletionException;
12-
import io.getstream.core.http.Response;
13-
14-
import java.net.MalformedURLException;
15-
import java.net.URISyntaxException;
16-
import java.net.URL;
17-
import java.util.Arrays;
1812
import java.util.Map;
19-
20-
import static io.getstream.core.utils.Auth.buildReactionsToken;
21-
import static io.getstream.core.utils.Routes.*;
22-
23-
import java.io.IOException;
24-
25-
import static com.google.common.base.Preconditions.checkArgument;
26-
import static com.google.common.base.Preconditions.checkNotNull;
27-
import static io.getstream.core.utils.Request.buildPost;
28-
import static io.getstream.core.utils.Serialization.*;
13+
import java8.util.concurrent.CompletableFuture;
2914

3015
public class ModerationClient {
31-
private final String secret;
32-
private final Moderation mod;
33-
34-
ModerationClient(String secret, Moderation mod) {
35-
this.secret = secret;
36-
this.mod = mod;
37-
}
38-
39-
public CompletableFuture<Response> flagUser(String flaggedUserId, String reason, Map<String, Object> options)throws StreamException {
40-
return flag("stream:user", flaggedUserId, "", reason, options);
41-
}
42-
43-
public CompletableFuture<Response> flagActivity(String entityId, String entityCreatorId, String reason, Map<String, Object> options) throws StreamException{
44-
return flag("stream:feeds:v2:activity", entityId, entityCreatorId, reason, options);
45-
}
46-
47-
public CompletableFuture<Response> flagReaction(String entityId, String entityCreatorId, String reason, Map<String, Object> options) throws StreamException{
48-
return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options);
49-
}
50-
51-
private CompletableFuture<Response> flag(String entityType, String entityId, String entityCreatorId,
52-
String reason, Map<String, Object> options)throws StreamException {
53-
final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE);
54-
return mod.flag(token, entityType, entityId, entityCreatorId, reason, options);
55-
}
16+
private final String secret;
17+
private final Moderation mod;
18+
19+
ModerationClient(String secret, Moderation mod) {
20+
this.secret = secret;
21+
this.mod = mod;
22+
}
23+
24+
public CompletableFuture<Response> flagUser(
25+
String flaggedUserId, String reason, Map<String, Object> options) throws StreamException {
26+
return flag("stream:user", flaggedUserId, "", reason, options);
27+
}
28+
29+
public CompletableFuture<Response> flagActivity(
30+
String entityId, String entityCreatorId, String reason, Map<String, Object> options)
31+
throws StreamException {
32+
return flag("stream:feeds:v2:activity", entityId, entityCreatorId, reason, options);
33+
}
34+
35+
public CompletableFuture<Response> flagReaction(
36+
String entityId, String entityCreatorId, String reason, Map<String, Object> options)
37+
throws StreamException {
38+
return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options);
39+
}
40+
41+
private CompletableFuture<Response> flag(
42+
String entityType,
43+
String entityId,
44+
String entityCreatorId,
45+
String reason,
46+
Map<String, Object> options)
47+
throws StreamException {
48+
final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE);
49+
return mod.flag(token, entityType, entityId, entityCreatorId, reason, options);
50+
}
5651
}
Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
package io.getstream.core;
22

3+
import static io.getstream.core.utils.Request.buildPost;
4+
import static io.getstream.core.utils.Routes.*;
5+
import static io.getstream.core.utils.Serialization.*;
6+
37
import com.fasterxml.jackson.core.JsonProcessingException;
48
import io.getstream.core.exceptions.StreamException;
59
import io.getstream.core.http.HTTPClient;
610
import io.getstream.core.http.Response;
7-
import io.getstream.core.models.Activity;
8-
import java8.util.concurrent.CompletableFuture;
9-
import java8.util.concurrent.CompletionException;
1011
import io.getstream.core.http.Token;
11-
1212
import java.net.MalformedURLException;
1313
import java.net.URISyntaxException;
1414
import java.net.URL;
15-
import java.util.Arrays;
1615
import java.util.Map;
17-
import static io.getstream.core.utils.Routes.*;
18-
19-
import static io.getstream.core.utils.Request.buildPost;
20-
import static io.getstream.core.utils.Serialization.*;
16+
import java8.util.concurrent.CompletableFuture;
17+
import java8.util.concurrent.CompletionException;
2118

2219
public class Moderation {
23-
private final String key;
24-
private final URL baseURL;
25-
private final HTTPClient httpClient;
26-
27-
public Moderation(String key, URL baseURL, HTTPClient httpClient) {
28-
this.key = key;
29-
this.baseURL = baseURL;
30-
this.httpClient = httpClient;
20+
private final String key;
21+
private final URL baseURL;
22+
private final HTTPClient httpClient;
23+
24+
public Moderation(String key, URL baseURL, HTTPClient httpClient) {
25+
this.key = key;
26+
this.baseURL = baseURL;
27+
this.httpClient = httpClient;
28+
}
29+
30+
public CompletableFuture<Response> flag(
31+
Token token,
32+
String entityType,
33+
String entityId,
34+
String entityCreatorId,
35+
String reason,
36+
Map<String, Object> options)
37+
throws StreamException {
38+
try {
39+
final byte[] payload =
40+
toJSON(
41+
new Object() {
42+
public final String UserId = entityCreatorId;
43+
public final String EntityType = entityType;
44+
public final String EntityId = entityId;
45+
public final String Reason = reason;
46+
});
47+
48+
final URL url = buildModerationFlagURL(baseURL);
49+
return httpClient.execute(buildPost(url, key, token, payload));
50+
} catch (JsonProcessingException | MalformedURLException | URISyntaxException e) {
51+
throw new CompletionException(e);
3152
}
32-
33-
public CompletableFuture<Response> flag(Token token, String entityType, String entityId, String entityCreatorId,
34-
String reason, Map<String, Object> options) throws StreamException {
35-
try {
36-
final byte[] payload =
37-
toJSON(
38-
new Object() {
39-
public final String UserId = entityCreatorId;
40-
public final String EntityType = entityType;
41-
public final String EntityId = entityId;
42-
public final String Reason = reason;
43-
});
44-
45-
46-
final URL url = buildModerationFlagURL(baseURL);
47-
return httpClient.execute(buildPost(url, key, token, payload));
48-
} catch (JsonProcessingException | MalformedURLException | URISyntaxException e) {
49-
throw new CompletionException(e);
50-
}
51-
}
52-
53+
}
5354
}

src/main/java/io/getstream/core/Stream.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.fasterxml.jackson.annotation.JsonFormat;
1010
import com.fasterxml.jackson.annotation.OptBoolean;
1111
import com.fasterxml.jackson.core.JsonProcessingException;
12-
import io.getstream.client.ModerationClient;
1312
import io.getstream.core.exceptions.StreamException;
1413
import io.getstream.core.http.HTTPClient;
1514
import io.getstream.core.http.Response;

src/main/java/io/getstream/core/StreamReactions.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,26 +287,29 @@ public CompletableFuture<Void> update(Token token, Reaction reaction, FeedID...
287287
}
288288
}
289289

290-
public CompletableFuture<Void> delete(Token token, String id, Boolean soft) throws StreamException {
290+
public CompletableFuture<Void> delete(Token token, String id, Boolean soft)
291+
throws StreamException {
291292
checkNotNull(id, "Reaction id can't be null");
292293
checkArgument(!id.isEmpty(), "Reaction id can't be empty");
293294

294295
try {
295296
final URL url = buildReactionsURL(baseURL, id + '/');
296-
297-
final Request deleteRequest = soft ? buildDelete(url, key, token, new CustomQueryParameter("soft", "true"))
298-
: buildDelete(url, key, token);
297+
298+
final Request deleteRequest =
299+
soft
300+
? buildDelete(url, key, token, new CustomQueryParameter("soft", "true"))
301+
: buildDelete(url, key, token);
299302

300303
return httpClient
301-
.execute(deleteRequest)
302-
.thenApply(
303-
response -> {
304-
try {
305-
return deserializeError(response);
306-
} catch (StreamException | IOException e) {
307-
throw new CompletionException(e);
308-
}
309-
});
304+
.execute(deleteRequest)
305+
.thenApply(
306+
response -> {
307+
try {
308+
return deserializeError(response);
309+
} catch (StreamException | IOException e) {
310+
throw new CompletionException(e);
311+
}
312+
});
310313
} catch (MalformedURLException | URISyntaxException e) {
311314
throw new StreamException(e);
312315
}

src/main/java/io/getstream/core/http/Request.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ public Request build() throws MalformedURLException, URISyntaxException {
155155
return new Request(this);
156156
}
157157
}
158-
}
158+
}

src/main/java/io/getstream/core/models/APIError.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55

66
public class APIError {
7-
private String Code;
8-
private String Message;
9-
private String Status;
7+
private String Code;
8+
private String Message;
9+
private String Status;
1010

11-
public String toString() {
12-
return "{Code='" + Code + "', Message=" + Message + "}";
13-
}
14-
// Default constructor
15-
public APIError() {}
11+
public String toString() {
12+
return "{Code='" + Code + "', Message=" + Message + "}";
13+
}
1614

17-
// Constructor with parameters
18-
@JsonCreator
19-
public APIError(
20-
@JsonProperty("code") String code,
21-
@JsonProperty("message") String message,
22-
@JsonProperty("status") String status) {
23-
this.Code = code;
24-
this.Message = message;
25-
this.Status = status;
26-
}
15+
// Default constructor
16+
public APIError() {}
2717

28-
// Getters
29-
public String getCode() {
30-
return Code;
31-
}
18+
// Constructor with parameters
19+
@JsonCreator
20+
public APIError(
21+
@JsonProperty("code") String code,
22+
@JsonProperty("message") String message,
23+
@JsonProperty("status") String status) {
24+
this.Code = code;
25+
this.Message = message;
26+
this.Status = status;
27+
}
3228

33-
public String getMessage() {
34-
return Message;
35-
}
29+
// Getters
30+
public String getCode() {
31+
return Code;
32+
}
33+
34+
public String getMessage() {
35+
return Message;
36+
}
3637
}

src/main/java/io/getstream/core/models/Activity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ public Builder foreignID(String foreignID) {
205205

206206
@JsonProperty("moderation")
207207
public Builder setModerationResponse(ModerationResponse mod) {
208-
this.moderationResponse=mod;
208+
this.moderationResponse = mod;
209209
return this;
210210
}
211211

212-
213212
public Builder target(String target) {
214213
this.target = target;
215214
return this;
@@ -297,4 +296,4 @@ public Activity build() {
297296
return new Activity(this);
298297
}
299298
}
300-
}
299+
}

0 commit comments

Comments
 (0)