Search code examples
laravel-5getstream-io

Laravel getStream - How to follow or add activity to a Company (non user)


an app I am creating needs to follow Companies, aside from users. And let the companies have their own activities. How is this configured in Laravel getStream. Seems the feeds are only for user types.

timelineFeed = FeedManager::getNewsFeed($user->id)['timeline'];
$aggregatedTimelineFeed = FeedManager::getNewsFeed($user->id)['timeline_aggregated'];

sample model i have is this:

namespace App;

use Illuminate\Database\Eloquent\Model;

class CompanyPost extends Model
{
    use \GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function company()
    {
        return $this->belongsTo('App\Company', 'company_id', 'id');
    }

    public function activityVerb()
    {
        return 'company_post';
    }

    public function activityActorMethodName()
    {
        return 'company';
    }
}

but i have noticed the feed is still saved on the user activities instead of the company activities.enter image description here

Thanks in advance guys.


Solution

  • sorry for the late reply. I have managed to follow a company creating a feed group: company flat On

    and the using sample code below to follow:

    $feed = FeedManager::getClient()->feed('timeline', $user->id);
    $feed->followFeed('company', $companyId);
    

    Unfollow:

    $feed->unfollowFeed('company', $companyId);
    

    Add activity:

    $companyFeed = FeedManager::getClient()->feed('company', $company->id);
    $companyFeed->addActivity([
        "actor"      => "App\Company:{$company->id}",
        "verb"       => "company_post",
        "object"     => "App\CompanyPost:{$post->id}",
        "foreign_id" => "App\CompanyPost:{$post->id}"
    ]);