Skip to content

Commit c609423

Browse files
itsmeadiaditya
andauthored
[MOD-0]Errors encountered while flagging users are now returned instead of being ignored. The flagUser method now requires a mandatory flaggingUserID parameter. (#158)
* chore: flag user, handle errors * chore: flag user should accept flagging userID, fix tests --------- Co-authored-by: aditya <[email protected]>
1 parent 4c2e0c5 commit c609423

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/IModeration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Stream
66
{
77
public interface IModeration
88
{
9-
Task<ResponseBase> FlagUserAsync(string flaggedUserId, string reason, IDictionary<string, object> options = null);
9+
Task<ResponseBase> FlagUserAsync(string flaggingUserID, string flaggedUserId, string reason, IDictionary<string, object> options = null);
1010

1111
Task<ResponseBase> FlagActivityAsync(string entityId, string entityCreatorId, string reason,
1212
IDictionary<string, object> options = null);

src/Moderation.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public Moderation(StreamClient client)
1919
_client = client;
2020
}
2121

22-
public async Task<ResponseBase> FlagUserAsync(string flaggedUserID, string reason, IDictionary<string, object> options = null)
22+
public async Task<ResponseBase> FlagUserAsync(string flaggingUserID, string flaggedUserID, string reason, IDictionary<string, object> options = null)
2323
{
24-
return await FlagAsync("stream:user", flaggedUserID, string.Empty, reason, options);
24+
return await FlagAsync("stream:user", flaggedUserID, flaggingUserID, reason, options);
2525
}
2626

2727
public async Task<ResponseBase> FlagActivityAsync(string entityId, string entityCreatorID, string reason, IDictionary<string, object> options = null)
@@ -45,7 +45,10 @@ public async Task<ResponseBase> FlagAsync(string entityType, string entityId, st
4545

4646
var response = await _client.MakeRequestAsync(request);
4747

48-
return StreamJsonConverter.DeserializeObject<ResponseBase>(response.Content);
48+
if (response.StatusCode == HttpStatusCode.Created)
49+
return StreamJsonConverter.DeserializeObject<ResponseBase>(response.Content);
50+
51+
throw StreamException.FromResponse(response);
4952
}
5053
}
5154
}

tests/ModerationTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,34 @@ public async Task TestReactionModeration()
6363

6464
Assert.AreEqual("complete", response.Status);
6565
Assert.AreEqual("remove", response.RecommendedAction);
66-
6766
}
6867

6968
[Test]
7069
public async Task TestFlagUser()
7170
{
72-
var userId = Guid.NewGuid().ToString();
71+
var userId = "flagginguser";
7372
var userData = new Dictionary<string, object>
7473
{
7574
{ "field", "value" },
7675
{ "is_admin", true },
7776
};
7877

79-
var u = await Client.Users.AddAsync(userId, userData);
78+
var u = await Client.Users.AddAsync(userId, userData, true);
8079

8180
Assert.NotNull(u);
8281
Assert.NotNull(u.CreatedAt);
8382
Assert.NotNull(u.UpdatedAt);
8483

85-
var response = await Client.Moderation.FlagUserAsync(userId, "blood");
84+
var response = await Client.Moderation.FlagUserAsync(userId, "flagged-user", "blood");
8685
Assert.NotNull(response);
8786
}
8887

88+
[Test]
89+
public async Task TestFlagUserError()
90+
{
91+
Assert.ThrowsAsync<StreamException>(async () => await Client.Moderation.FlagUserAsync("", string.Empty, "blood"));
92+
}
93+
8994
[Test]
9095
public async Task TestFlagActivity()
9196
{

0 commit comments

Comments
 (0)