public function __construct($api_key, $api_secret, $config) { $this->config = $config; if (getenv('STREAM_URL') !== false) { $this->client = Client::herokuConnect(getenv('STREAM_URL')); } else { $this->client = new Client($api_key, $api_secret); $location = $this->config->get("stream-laravel::location"); $this->client->setLocation($location); $this->client->timeout = $this->config->get("stream-laravel::timeout", 3); } $this->userFeed = $this->config->get("stream-laravel::user_feed"); }
public function feed() { $client = new StreamClient('m4rjggbpj7fb', 'bku9w4hvhzt8dpupzq9k4wz8kur3tqmhyg52qze2tnpppqyxzddpgts2jpds4m6z'); $current_feed = $client->feed('timeline', $this->Auth->user('id')); if (empty($activities = $current_feed->getActivities(0, 30)['results'])) { $this->set(['_serialize' => true, 'success' => false]); return; } $users = $this->_generateMemberQuery($activities); $users_array = $users->toArray(); foreach ($activities as $key => $activity) { $activity_entity = new FeedItem($activity); $first = array_key_exists($activity_entity->first_user_id, $users_array) ? $users_array[$activity_entity->first_user_id] : null; $second = array_key_exists($activity_entity->second_user_id, $users_array) ? $users_array[$activity_entity->second_user_id] : null; $game = null; $activity_entity->update($first, $second, $game); $activity_entity->format($this->Auth->user('id')); $activities[$key] = $activity_entity; } $this->set(['_serialize' => true, 'success' => true, 'data' => $activities]); }
public function _afterDelete_Delete(\Cake\Event\Event $event) { $game = $event->subject()->entity; $client = new StreamClient('m4rjggbpj7fb', 'bku9w4hvhzt8dpupzq9k4wz8kur3tqmhyg52qze2tnpppqyxzddpgts2jpds4m6z'); foreach ($game->game_memberships as $gm) { if (!empty($gm->member_id)) { $feed = $client->feed('user', $gm->member_id); $feed->removeActivity('Game:' . $event->subject()->id, true); } } }
public function home() { $this->response->disableCache(); $loggedUserId = $this->Auth->user('id'); $isCurrentUser = false; if (!Configure::read('Users.Profile.viewOthers') || empty($id)) { $id = $loggedUserId; } try { $appContain = (array) Configure::read('Auth.authenticate.' . \Cake\Controller\Component\AuthComponent::ALL . '.contain'); $socialContain = Configure::read('Users.Social.login') ? ['SocialAccounts'] : []; $user = $this->getUsersTable()->get($id, ['contain' => array_merge((array) $appContain, (array) $socialContain)]); $this->set('avatarPlaceholder', Configure::read('Users.Avatar.placeholder')); if ($user->id === $loggedUserId) { $isCurrentUser = true; } } catch (RecordNotFoundException $ex) { $this->Flash->error(__d('Users', 'User was not found')); return $this->redirect($this->request->referer()); } catch (InvalidPrimaryKeyException $ex) { $this->Flash->error(__d('Users', 'Not authorized, please login first')); return $this->redirect($this->request->referer()); } $this->set(compact('user', 'isCurrentUser')); $this->set('_serialize', ['user', 'isCurrentUser']); $this->set('pane', $this->request->query('pane') ? $this->request->query('pane') : 'feed'); $client = new StreamClient('m4rjggbpj7fb', 'bku9w4hvhzt8dpupzq9k4wz8kur3tqmhyg52qze2tnpppqyxzddpgts2jpds4m6z'); $member_feed = $client->feed('user', $this->Auth->user('id')); $readonlyToken = $member_feed->getReadonlyToken(); $this->set('stream_token', $readonlyToken); }
/** * Start the shell and interactive console. * * @return int|void */ public function main() { $f_table = TableRegistry::get('Friendships'); $friends = $f_table->find()->where(['status' => 'accepted']); $friends = $friends->contain(['Froms', 'Tos'])->all(); $client = new StreamClient('m4rjggbpj7fb', 'bku9w4hvhzt8dpupzq9k4wz8kur3tqmhyg52qze2tnpppqyxzddpgts2jpds4m6z'); $follows = []; foreach ($friends as $friend) { //follow each others feeds array_push($follows, ['source' => 'timeline:' . $friend->to_id, 'target' => 'user:'******'source' => 'timeline:' . $friend->from_id, 'target' => 'user:'******'source' => 'timeline_agg:' . $friend->to_id, 'target' => 'user:'******'source' => 'timeline_agg:' . $friend->from_id, 'target' => 'user:'******'source' => 'timeline:'.$this->Auth->user('id'), 'target' => 'user:'******'source' => 'timeline:'.$oppo, 'target' => 'user:'******'id')], // ['source' => 'timeline_aggregated:'.$this->Auth->user('id'), 'target' => 'user:'******'source' => 'timeline_aggregated:'.$oppo, 'target' => 'user:'******'id')], // // ]; // } $m_table = TableRegistry::get('Members'); $members = $m_table->find(); foreach ($members as $member) { array_push($follows, ['source' => 'timeline:' . $member->id, 'target' => 'user:'******'source' => 'user_aggregated:' . $member->id, 'target' => 'user:'******'source' => 'timeline_agg:' . $member->id, 'target' => 'user:' . $member->id]); } // debug($follows); $client->batcher()->followMany($follows); }