33using Stream . Rest ;
44using System ;
55using System . Collections . Generic ;
6- using System . Linq ;
76using System . Threading . Tasks ;
87
98namespace Stream
109{
1110 using ReactionFilter = FeedFilter ;
1211
12+ public class ReactionsWithActivity
13+ {
14+ [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "results" ) ]
15+ public IEnumerable < Reaction > Reactions { get ; internal set ; }
16+
17+ public EnrichedActivity Activity { get ; internal set ; }
18+ }
19+
1320 public class Reaction
1421 {
1522 [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "id" ) ]
@@ -65,6 +72,13 @@ public ReactionFiltering WithFilter(ReactionFilter filter)
6572 return this ;
6673 }
6774
75+ internal ReactionFiltering WithActivityData ( )
76+ {
77+ _filter = ( _filter == null ) ? ReactionFilter . Where ( ) . WithActivityData ( ) : _filter . WithActivityData ( ) ;
78+
79+ return this ;
80+ }
81+
6882 internal void Apply ( RestRequest request )
6983 {
7084 request . AddQueryParameter ( "limit" , _limit . ToString ( ) ) ;
@@ -74,6 +88,14 @@ internal void Apply(RestRequest request)
7488 _filter . Apply ( request ) ;
7589 }
7690
91+ internal bool IncludesActivityData
92+ {
93+ get
94+ {
95+ return _filter . IncludesActivityData ;
96+ }
97+ }
98+
7799 public static ReactionFiltering Default
78100 {
79101 get
@@ -142,7 +164,21 @@ private class ReactionsFilterResponse
142164 {
143165 [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "results" ) ]
144166 public IEnumerable < Reaction > Reactions { get ; internal set ; }
145- }
167+
168+ internal static EnrichedActivity GetActivity ( string json )
169+ {
170+ JObject obj = JObject . Parse ( json ) ;
171+ foreach ( var prop in obj . Properties ( ) )
172+ {
173+ if ( prop . Name == "activity" )
174+ {
175+ return EnrichedActivity . FromJson ( ( JObject ) prop . Value ) ;
176+ }
177+ }
178+
179+ return null ;
180+ }
181+ }
146182
147183 internal Reactions ( StreamClient client )
148184 {
@@ -193,20 +229,51 @@ public async Task<Reaction> Get(string reactionID)
193229
194230 public async Task < IEnumerable < Reaction > > Filter ( ReactionFiltering filtering , ReactionPagination pagination )
195231 {
196- var urlPath = pagination . GetPath ( ) ;
197- var request = this . _client . BuildJWTAppRequest ( $ "reaction/{ urlPath } ", HttpMethod . GET ) ;
198- filtering . Apply ( request ) ;
232+ // var urlPath = pagination.GetPath();
233+ // var request = this._client.BuildJWTAppRequest($"reaction/{urlPath}", HttpMethod.GET);
234+ // filtering.Apply(request);
199235
200- var response = await this . _client . MakeRequest ( request ) ;
236+ //var response = await this._client.MakeRequest(request);
237+ var response = await FilterHelper ( filtering , pagination ) ;
201238
202239 if ( response . StatusCode == System . Net . HttpStatusCode . OK )
203- {
240+ {
204241 return JsonConvert . DeserializeObject < ReactionsFilterResponse > ( response . Content ) . Reactions ;
205242 }
206243
207244 throw StreamException . FromResponse ( response ) ;
208245 }
209246
247+ public async Task < ReactionsWithActivity > FilterWithActivityData ( ReactionFiltering filtering , ReactionPagination pagination )
248+ {
249+ var response = await FilterHelper ( filtering . WithActivityData ( ) , pagination ) ;
250+
251+ if ( response . StatusCode == System . Net . HttpStatusCode . OK )
252+ {
253+ var reactions = JsonConvert . DeserializeObject < ReactionsFilterResponse > ( response . Content ) . Reactions ;
254+ var activity = ReactionsFilterResponse . GetActivity ( response . Content ) ;
255+
256+ return new ReactionsWithActivity
257+ {
258+ Reactions = reactions ,
259+ Activity = activity
260+ } ;
261+ }
262+
263+ throw StreamException . FromResponse ( response ) ;
264+ }
265+
266+ private async Task < RestResponse > FilterHelper ( ReactionFiltering filtering , ReactionPagination pagination )
267+ {
268+ var urlPath = pagination . GetPath ( ) ;
269+ var request = this . _client . BuildJWTAppRequest ( $ "reaction/{ urlPath } ", HttpMethod . GET ) ;
270+ filtering . Apply ( request ) ;
271+
272+ var response = await this . _client . MakeRequest ( request ) ;
273+
274+ return response ;
275+ }
276+
210277 public async Task < Reaction > Update ( string reactionID , IDictionary < string , object > data = null , IEnumerable < string > targetFeeds = null )
211278 {
212279 var r = new Reaction ( )
0 commit comments