Skip to content

Commit d7ffef8

Browse files
github-actions[bot]itsmeadivishalnarkhedegithub-actions
authored
chore: release 6.9.0-beta.0 (#139)
* add moderation support * fix syntax * fix syntax * fix tests * lint * remove ignore * fix tests * fix tests * moderation reaction * moderation reaction * lint * remove used line * lint * [PBE-4786] moderation flag endpoint (#138) * flag endpoint * lint fix * ignore ci tests for moderation * ignore reaction test on ci * chore(release): 6.9.0-beta.0 --------- Co-authored-by: Aditya Agarwal <[email protected]> Co-authored-by: Vishal Narkhede <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent dc2cbf3 commit d7ffef8

File tree

13 files changed

+253
-11
lines changed

13 files changed

+253
-11
lines changed

.DS_Store

6 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [6.9.0-beta.0](https://github.com/GetStream/stream-net/compare/6.8.3...6.9.0-beta.0) (2024-07-24)
6+
57
### [6.8.3](https://github.com/GetStream/stream-net/compare/6.8.2...6.8.3) (2024-04-23)
68

79
### [6.8.2-prerelease](https://github.com/GetStream/stream-net/compare/6.8.1...6.8.2-prerelease) (2024-04-12)

src/IModeration.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Stream.Models;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
namespace Stream
6+
{
7+
public interface IModeration
8+
{
9+
Task<ResponseBase> FlagUserAsync(string flaggedUserId, string reason, IDictionary<string, object> options = null);
10+
11+
Task<ResponseBase> FlagActivityAsync(string entityId, string entityCreatorId, string reason,
12+
IDictionary<string, object> options = null);
13+
14+
Task<ResponseBase> FlagReactionAsync(string entityId, string entityCreatorId, string reason,
15+
IDictionary<string, object> options = null);
16+
Task<ResponseBase> FlagAsync(string entityType, string entityId, string entityCreatorId, string reason, IDictionary<string, object> options = null);
17+
}
18+
}

src/IReactions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public interface IReactions
1515
{
1616
/// <summary>Posts a new reaciton.</summary>
1717
/// <remarks>https://getstream.io/activity-feeds/docs/dotnet-csharp/reactions_introduction/?language=csharp</remarks>
18-
Task<Reaction> AddAsync(string reactionId, string kind, string activityId, string userId, IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null);
18+
Task<Reaction> AddAsync(string reactionId, string kind, string activityId, string userId, IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null, string moderationTemplate = null);
1919

2020
/// <summary>Posts a new reaciton.</summary>
2121
/// <remarks>https://getstream.io/activity-feeds/docs/dotnet-csharp/reactions_introduction/?language=csharp</remarks>
22-
Task<Reaction> AddAsync(string kind, string activityId, string userId, IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null);
22+
Task<Reaction> AddAsync(string kind, string activityId, string userId, IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null, string moderationTemplate = null);
2323

2424
/// <summary>Adds a new child reaction.</summary>
2525
/// <remarks>https://getstream.io/activity-feeds/docs/dotnet-csharp/reactions_introduction/?language=csharp</remarks>
@@ -61,4 +61,4 @@ public interface IReactions
6161
/// <remarks>https://getstream.io/activity-feeds/docs/dotnet-csharp/reactions_introduction/?language=csharp</remarks>
6262
Task<Reaction> UpdateAsync(string reactionId, IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null);
6363
}
64-
}
64+
}

src/IStreamClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public interface IStreamClient
2626
/// </summary>
2727
IReactions Reactions { get; }
2828

29+
IModeration Moderation { get; }
30+
2931
/// <summary>
3032
/// Returns an <see cref="IUsers"/> instance that let's you interact with users.
3133
/// You can used the returned instance as a singleton in your application.

src/Models/Activity.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class Activity : ActivityBase
2323
public string Origin { get; set; }
2424
public Dictionary<string, object> ScoreVars { get; set; }
2525

26+
public string ModerationTemplate { get; set; }
27+
2628
public Activity(string actor, string verb, string @object)
2729
{
2830
Actor = actor;
@@ -41,6 +43,19 @@ public class AddActivitiesResponse : ResponseBase
4143
public List<Activity> Activities { get; set; }
4244
}
4345

46+
public class ModerationResponse
47+
{
48+
public string Status { get; set; }
49+
public string RecommendedAction { get; set; }
50+
public APIError APIError { get; set; }
51+
}
52+
53+
public class APIError
54+
{
55+
public string Code { get; set; }
56+
public string Message { get; set; }
57+
}
58+
4459
public class ActivityPartialUpdateRequestObject
4560
{
4661
public string Id { get; set; }
@@ -49,4 +64,4 @@ public class ActivityPartialUpdateRequestObject
4964
public IEnumerable<string> Unset { get; set; }
5065
public DateTime? Time { get; set; }
5166
}
52-
}
67+
}

src/Models/GetOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class GetOptions
2222
private bool _score_vars = false;
2323
private string _discard_actors = null;
2424
private string _discard_actors_sep = null;
25+
private string _moderation_template = null;
2526

2627
private IDictionary<string, string> _custom = null;
2728

@@ -142,6 +143,9 @@ internal void Apply(RestRequest request)
142143
if (!string.IsNullOrWhiteSpace(_ranking_vars))
143144
request.AddQueryParameter("ranking_vars", _ranking_vars);
144145

146+
if (!string.IsNullOrWhiteSpace(_moderation_template))
147+
request.AddQueryParameter("moderation_template", _moderation_template);
148+
145149
if (_score_vars)
146150
request.AddQueryParameter("withScoreVars", "true");
147151

src/Models/Reaction.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
23
using Stream.Rest;
34
using System;
45
using System.Collections.Generic;
@@ -14,6 +15,7 @@ public class Reaction
1415
public DateTime? UpdatedAt { get; set; }
1516
public string ActivityId { get; set; }
1617
public string UserId { get; set; }
18+
public string ModerationTemplate { get; set; }
1719
public GenericData User { get; set; }
1820

1921
public IDictionary<string, object> Data { get; set; }
@@ -30,6 +32,20 @@ public class Reaction
3032
public DateTime? DeletedAt { get; set; }
3133

3234
public string Ref() => $"SR:{Id}";
35+
36+
public Dictionary<string, object> Moderation { get; set; }
37+
public ModerationResponse GetModerationResponse()
38+
{
39+
var key = "response";
40+
if (Moderation != null && Moderation.ContainsKey(key))
41+
{
42+
return ((JObject)Moderation[key]).ToObject<ModerationResponse>();
43+
}
44+
else
45+
{
46+
throw new KeyNotFoundException($"Key '{key}' not found in moderation dictionary.");
47+
}
48+
}
3349
}
3450

3551
public class ReactionsWithActivity : GenericGetResponse<Reaction>
@@ -114,4 +130,4 @@ public ReactionPagination Kind(string kind)
114130
public string GetPath()
115131
=> _kind == null ? $"{_lookupAttr}/{_lookupValue}/" : $"{_lookupAttr}/{_lookupValue}/{_kind}/";
116132
}
117-
}
133+
}

src/Moderation.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Stream.Models;
2+
using Stream.Rest;
3+
using Stream.Utils;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net;
7+
using System.Net.Http;
8+
using System.Reflection;
9+
using System.Threading.Tasks;
10+
11+
namespace Stream
12+
{
13+
public class Moderation : IModeration
14+
{
15+
private readonly StreamClient _client;
16+
17+
public Moderation(StreamClient client)
18+
{
19+
_client = client;
20+
}
21+
22+
public async Task<ResponseBase> FlagUserAsync(string flaggedUserID, string reason, IDictionary<string, object> options = null)
23+
{
24+
return await FlagAsync("stream:user", flaggedUserID, string.Empty, reason, options);
25+
}
26+
27+
public async Task<ResponseBase> FlagActivityAsync(string entityId, string entityCreatorID, string reason, IDictionary<string, object> options = null)
28+
{
29+
return await FlagAsync("stream:feeds:v2:activity", entityId, entityCreatorID, reason, options);
30+
}
31+
32+
public async Task<ResponseBase> FlagReactionAsync(string entityId, string entityCreatorID, string reason, IDictionary<string, object> options = null)
33+
{
34+
return await FlagAsync("stream:feeds:v2:reaction", entityId, entityCreatorID, reason, options);
35+
}
36+
37+
public async Task<ResponseBase> FlagAsync(string entityType, string entityId, string entityCreatorID,
38+
string reason, IDictionary<string, object> options = null)
39+
{
40+
var request = _client.BuildAppRequest("/moderation/flag", HttpMethod.Post);
41+
request.SetJsonBody(StreamJsonConverter.SerializeObject(new
42+
{
43+
user_id = entityCreatorID, entity_type = entityType, entity_id = entityId, reason,
44+
}));
45+
46+
var response = await _client.MakeRequestAsync(request);
47+
48+
return StreamJsonConverter.DeserializeObject<ResponseBase>(response.Content);
49+
}
50+
}
51+
}

src/Reactions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ internal Reactions(StreamClient client)
1919
}
2020

2121
public async Task<Reaction> AddAsync(string kind, string activityId, string userId,
22-
IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null)
22+
IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null, string moderationTemplate = null)
2323
{
24-
return await AddAsync(null, kind, activityId, userId, data, targetFeeds);
24+
return await AddAsync(null, kind, activityId, userId, data, targetFeeds, moderationTemplate);
2525
}
2626

2727
public async Task<Reaction> AddAsync(string reactionId, string kind, string activityId, string userId,
28-
IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null)
28+
IDictionary<string, object> data = null, IEnumerable<string> targetFeeds = null, string moderationTemplate = null)
2929
{
3030
var r = new Reaction
3131
{
@@ -35,6 +35,7 @@ public async Task<Reaction> AddAsync(string reactionId, string kind, string acti
3535
UserId = userId,
3636
Data = data,
3737
TargetFeeds = targetFeeds,
38+
ModerationTemplate = moderationTemplate,
3839
};
3940

4041
return await AddAsync(r);
@@ -186,4 +187,4 @@ private async Task<Reaction> AddAsync(Reaction r)
186187
throw StreamException.FromResponse(response);
187188
}
188189
}
189-
}
190+
}

0 commit comments

Comments
 (0)