Skip to content

Commit 79a3d10

Browse files
authored
Add support to filtering by actors (#132)
* chore: added actors filter * chore: lint fix * chore: add basic test * chore: moved from filter to options * chore: finish test * chore: fix test * chore: fix test * chore: disabled test
1 parent a2205e0 commit 79a3d10

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Models/GetOptions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class GetOptions
2020
private string _user_id = null;
2121
private string _ranking_vars = null;
2222
private bool _score_vars = false;
23+
private string _discard_actors = null;
24+
private string _discard_actors_sep = null;
2325

2426
private IDictionary<string, string> _custom = null;
2527

@@ -106,6 +108,17 @@ public GetOptions WithCustom(string key, string value)
106108
return this;
107109
}
108110

111+
public GetOptions DiscardActors(List<string> actors, string separator = ",")
112+
{
113+
if (separator != ",")
114+
{
115+
_discard_actors_sep = separator;
116+
}
117+
118+
_discard_actors = string.Join(separator, actors);
119+
return this;
120+
}
121+
109122
internal void Apply(RestRequest request)
110123
{
111124
request.AddQueryParameter("offset", _offset.ToString());
@@ -132,6 +145,12 @@ internal void Apply(RestRequest request)
132145
if (_score_vars)
133146
request.AddQueryParameter("withScoreVars", "true");
134147

148+
if (!string.IsNullOrWhiteSpace(_discard_actors_sep))
149+
request.AddQueryParameter("discard_actors_sep", _discard_actors_sep);
150+
151+
if (!string.IsNullOrWhiteSpace(_discard_actors))
152+
request.AddQueryParameter("discard_actors", _discard_actors);
153+
135154
if (_custom != null)
136155
{
137156
foreach (KeyValuePair<string, string> kvp in _custom)

tests/ActivityTests/GetActivityTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ public async Task TestRankingVars()
129129
Assert.AreEqual(r2.Results[1].Score, 0.99999917);
130130
}
131131

132+
[Test]
133+
[Ignore("Test server doesn't support this feature at the moment")]
134+
public async Task TestActorFilter()
135+
{
136+
var feed = this.UserFeed;
137+
138+
var newActivity1 = new Activity("1", "test", "1");
139+
var r1 = await feed.AddActivityAsync(newActivity1);
140+
141+
var newActivity2 = new Activity("2", "test", "2");
142+
var r2 = await feed.AddActivityAsync(newActivity2);
143+
144+
var r3 = await feed.GetFlatActivitiesAsync(GetOptions.Default.DiscardActors(new List<string> { "1" }, ";"));
145+
Assert.IsNotNull(r3);
146+
Assert.AreEqual(1, r3.Results.Count);
147+
148+
var r4 = await feed.GetFlatActivitiesAsync(GetOptions.Default.DiscardActors(new List<string> { "1", "2" }, ";"));
149+
Assert.IsNotNull(r4);
150+
Assert.AreEqual(0, r4.Results.Count);
151+
}
152+
132153
[Test]
133154
[Ignore("Test database has no ranked method at the moment")]
134155
public async Task TestScoreVars()

0 commit comments

Comments
 (0)