Skip to content

Commit

Permalink
Merge feb7b37 into 4783725
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-d committed Nov 12, 2019
2 parents 4783725 + feb7b37 commit f9d80ef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/GetStream/Stream/Activities.php
Expand Up @@ -35,12 +35,18 @@ protected function getHttpRequestHeaders($resource, $action)
return $headers;
}

public function _getActivities($query_params)
public function _getActivities($query_params, $enrich = false)
{
if (empty($query_params)) {
return;
}

return $this->makeHttpRequest('activities/', 'GET', null, $query_params);
$url = 'activities/';

if($enrich) {
$url = "enrich/$url";
}

return $this->makeHttpRequest($url, 'GET', null, $query_params);
}
}
23 changes: 21 additions & 2 deletions lib/GetStream/Stream/Client.php
Expand Up @@ -229,7 +229,7 @@ public function buildRequestUrl($uri)
return "{$baseUrl}/{$this->api_version}/{$uri}";
}

public function getActivities($ids=null, $foreign_id_times=null)
public function getActivities($ids=null, $foreign_id_times=null, $enrich=false, $reactions = null)
{
if($ids!==null){
$query_params = ["ids" => join(',', $ids)];
Expand All @@ -251,9 +251,28 @@ public function getActivities($ids=null, $foreign_id_times=null)
];

}

if($reactions !== null){
if(!is_array($reactions)){
throw new StreamFeedException("reactions argument should be an associative array");
}
if(isset($reactions["own"]) && $reactions["own"]){
$query_params["withOwnReactions"] = true;
$enrich = true;
}
if(isset($reactions["recent"]) && $reactions["recent"]){
$query_params["withRecentReactions"] = true;
$enrich = true;
}
if(isset($reactions["counts"]) && $reactions["counts"]){
$query_params["withReactionCounts"] = true;
$enrich = true;
}
}

$token = $this->signer->jwtScopeToken('*', 'activities', '*');
$activities = new Activities($this, $this->api_key, $token);
return $activities->_getActivities($query_params);
return $activities->_getActivities($query_params, $enrich);
}

public function batchPartialActivityUpdate($data)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/FeedTest.php
Expand Up @@ -832,5 +832,9 @@ public function testGetActivities(){
$response = $this->client->getActivities(null, $foreign_id_times=$foreign_id_times)['results'];
$this->assertCount(2, $response);
$this->assertEquals(sort($activities), sort($response), $canonicalize=true);

$response = $this->client->getActivities($ids, null, false, array('withReactionCounts' => true));
$this->assertCount(2,$response);
$this->assertEquals($response["results"][0]["reaction_counts"], 0);
}
}

0 comments on commit f9d80ef

Please sign in to comment.