Skip to content

Commit 04caca1

Browse files
authored
Merge pull request #88 from GetStream/feature/get_activities_enrichment
Add support for enrichment in getActivities
2 parents 4783725 + feb7b37 commit 04caca1

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

lib/GetStream/Stream/Activities.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ protected function getHttpRequestHeaders($resource, $action)
3535
return $headers;
3636
}
3737

38-
public function _getActivities($query_params)
38+
public function _getActivities($query_params, $enrich = false)
3939
{
4040
if (empty($query_params)) {
4141
return;
4242
}
4343

44-
return $this->makeHttpRequest('activities/', 'GET', null, $query_params);
44+
$url = 'activities/';
45+
46+
if($enrich) {
47+
$url = "enrich/$url";
48+
}
49+
50+
return $this->makeHttpRequest($url, 'GET', null, $query_params);
4551
}
4652
}

lib/GetStream/Stream/Client.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function buildRequestUrl($uri)
229229
return "{$baseUrl}/{$this->api_version}/{$uri}";
230230
}
231231

232-
public function getActivities($ids=null, $foreign_id_times=null)
232+
public function getActivities($ids=null, $foreign_id_times=null, $enrich=false, $reactions = null)
233233
{
234234
if($ids!==null){
235235
$query_params = ["ids" => join(',', $ids)];
@@ -251,9 +251,28 @@ public function getActivities($ids=null, $foreign_id_times=null)
251251
];
252252

253253
}
254+
255+
if($reactions !== null){
256+
if(!is_array($reactions)){
257+
throw new StreamFeedException("reactions argument should be an associative array");
258+
}
259+
if(isset($reactions["own"]) && $reactions["own"]){
260+
$query_params["withOwnReactions"] = true;
261+
$enrich = true;
262+
}
263+
if(isset($reactions["recent"]) && $reactions["recent"]){
264+
$query_params["withRecentReactions"] = true;
265+
$enrich = true;
266+
}
267+
if(isset($reactions["counts"]) && $reactions["counts"]){
268+
$query_params["withReactionCounts"] = true;
269+
$enrich = true;
270+
}
271+
}
272+
254273
$token = $this->signer->jwtScopeToken('*', 'activities', '*');
255274
$activities = new Activities($this, $this->api_key, $token);
256-
return $activities->_getActivities($query_params);
275+
return $activities->_getActivities($query_params, $enrich);
257276
}
258277

259278
public function batchPartialActivityUpdate($data)

tests/integration/FeedTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,5 +832,9 @@ public function testGetActivities(){
832832
$response = $this->client->getActivities(null, $foreign_id_times=$foreign_id_times)['results'];
833833
$this->assertCount(2, $response);
834834
$this->assertEquals(sort($activities), sort($response), $canonicalize=true);
835+
836+
$response = $this->client->getActivities($ids, null, false, array('withReactionCounts' => true));
837+
$this->assertCount(2,$response);
838+
$this->assertEquals($response["results"][0]["reaction_counts"], 0);
835839
}
836840
}

0 commit comments

Comments
 (0)