Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/IModeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Stream
{
public interface IModeration
{
Task<ResponseBase> FlagUserAsync(string flaggedUserId, string reason, IDictionary<string, object> options = null);
Task<ResponseBase> FlagUserAsync(string flaggingUserID, string flaggedUserId, string reason, IDictionary<string, object> options = null);

Task<ResponseBase> FlagActivityAsync(string entityId, string entityCreatorId, string reason,
IDictionary<string, object> options = null);
Expand Down
9 changes: 6 additions & 3 deletions src/Moderation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public Moderation(StreamClient client)
_client = client;
}

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

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

var response = await _client.MakeRequestAsync(request);

return StreamJsonConverter.DeserializeObject<ResponseBase>(response.Content);
if (response.StatusCode == HttpStatusCode.Created)
return StreamJsonConverter.DeserializeObject<ResponseBase>(response.Content);

throw StreamException.FromResponse(response);
}
}
}
13 changes: 9 additions & 4 deletions tests/ModerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,34 @@

Assert.AreEqual("complete", response.Status);
Assert.AreEqual("remove", response.RecommendedAction);

}

[Test]
public async Task TestFlagUser()
{
var userId = Guid.NewGuid().ToString();
var userId = "flagginguser";
var userData = new Dictionary<string, object>
{
{ "field", "value" },
{ "is_admin", true },
};

var u = await Client.Users.AddAsync(userId, userData);
var u = await Client.Users.AddAsync(userId, userData, true);

Assert.NotNull(u);
Assert.NotNull(u.CreatedAt);
Assert.NotNull(u.UpdatedAt);

var response = await Client.Moderation.FlagUserAsync(userId, "blood");
var response = await Client.Moderation.FlagUserAsync(userId, "flagged-user", "blood");
Assert.NotNull(response);
}

[Test]
public async Task TestFlagUserError()

Check warning on line 89 in tests/ModerationTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Assert.ThrowsAsync<StreamException>(async () => await Client.Moderation.FlagUserAsync("", string.Empty, "blood"));
}

[Test]
public async Task TestFlagActivity()
{
Expand Down
Loading