RayzorMamon
RayzorMamon

Reputation: 184

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.

Upvotes: 1

Views: 839

Answers (3)

RayzorMamon
RayzorMamon

Reputation: 184

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}"
]);

Upvotes: 0

iandouglas
iandouglas

Reputation: 4326

Our stream-laravel project has some documentation on how to change the model

class Pin extends Eloquent {
use GetStream\StreamLaravel\Eloquent\ActivityTrait;

public function author()
{
    return $this->belongsTo('Author');
}

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

As far as letting volunteers follow companies and users, we have some documentation in the main README.

(edited to remove my mistaken github reference)

Upvotes: 1

Jared
Jared

Reputation: 13

Ian seems to have confused you with me in his link to the Github issue which brought this post to my attention.

The reason this is still showing up on the user feed is that this isn't a configurable option at least on a case by case (or model by model) level. You can override what Stream Laravel uses as the "user feed" in the main configuration but as far as I can tell you are stuck posting to the active logged in user's feed unless you build out the functionality yourself with the Stream-PHP libs and abstain from using the StreamLaravel Activity trait.

You can see here starting at Line: 73 of StreamLaravelManager.php what's happening when an activity is created.

public function activityCreated($instance)
{
    $activity = $instance->createActivity();
    $feed = $this->getFeed($this->userFeed, $instance->activityActorId());
    $feed->addActivity($activity);
} 

Unfortunately "$this->userFeed" ultimately is pulled from the configuration file and I don't think there is a way to override it.

Personally, I ran into this when creating "like" functionality. I didn't really want people to have to see what everyone "likes" on their timeline since most of it would be irrelevant and it would get cluttered fast so I ended up not even creating a "like" activity. Instead I'm only added it to a users notification feed when someone likes something of theirs. Of course this may not be desirable for everyone to handle it that way but I noticed you had the "like" activity in your screenshot so I figured I'd mention it.

Good luck on your app!

Upvotes: 1

Related Questions