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 {
@@ -192,21 +228,47 @@ public async Task<Reaction> Get(string reactionID)
192228 }
193229
194230 public async Task < IEnumerable < Reaction > > Filter ( ReactionFiltering filtering , ReactionPagination pagination )
195- {
196- var urlPath = pagination . GetPath ( ) ;
197- var request = this . _client . BuildJWTAppRequest ( $ "reaction/{ urlPath } ", HttpMethod . GET ) ;
198- filtering . Apply ( request ) ;
231+ {
232+ var response = await FilterHelper ( filtering , pagination ) ;
199233
200- var response = await this . _client . MakeRequest ( request ) ;
234+ if ( response . StatusCode == System . Net . HttpStatusCode . OK )
235+ {
236+ return JsonConvert . DeserializeObject < ReactionsFilterResponse > ( response . Content ) . Reactions ;
237+ }
238+
239+ throw StreamException . FromResponse ( response ) ;
240+ }
241+
242+ public async Task < ReactionsWithActivity > FilterWithActivityData ( ReactionFiltering filtering , ReactionPagination pagination )
243+ {
244+ var response = await FilterHelper ( filtering . WithActivityData ( ) , pagination ) ;
201245
202246 if ( response . StatusCode == System . Net . HttpStatusCode . OK )
203247 {
204- return JsonConvert . DeserializeObject < ReactionsFilterResponse > ( response . Content ) . Reactions ;
248+ var reactions = JsonConvert . DeserializeObject < ReactionsFilterResponse > ( response . Content ) . Reactions ;
249+ var activity = ReactionsFilterResponse . GetActivity ( response . Content ) ;
250+
251+ return new ReactionsWithActivity
252+ {
253+ Reactions = reactions ,
254+ Activity = activity
255+ } ;
205256 }
206257
207258 throw StreamException . FromResponse ( response ) ;
208259 }
209260
261+ private async Task < RestResponse > FilterHelper ( ReactionFiltering filtering , ReactionPagination pagination )
262+ {
263+ var urlPath = pagination . GetPath ( ) ;
264+ var request = this . _client . BuildJWTAppRequest ( $ "reaction/{ urlPath } ", HttpMethod . GET ) ;
265+ filtering . Apply ( request ) ;
266+
267+ var response = await this . _client . MakeRequest ( request ) ;
268+
269+ return response ;
270+ }
271+
210272 public async Task < Reaction > Update ( string reactionID , IDictionary < string , object > data = null , IEnumerable < string > targetFeeds = null )
211273 {
212274 var r = new Reaction ( )
0 commit comments