Search code examples
getstream-io

How check if a notification is a mention


I'm using stream-laravel and I want to integrate @-mentions to my post model. I now added in my activityNotify() the user who is mentioned in the post. This works fine. But, when I retrieve the notification feed, the verb is 'post', because the activity is of course a post.

For the frontend I want to know when it's an @mention. What is the best way to handle this?

I notify the @mention users like this

public function activityNotify()
    {
        $notify = collect();
        foreach ($this->mentions as $mention) {
            $userNotification = \FeedManager::getNotificationFeed($mention);
            $notify->push($userNotification);
        }

        return $notify;
    }

My notification output looks like this:

0 => array:10 [▼
    "activities" => array:1 [▼
      0 => [
        "actor" => App\User {#1652 ▶}
        "body" => "Hey @john Doe"
        "foreign_id" => "CommunityPost:37"
        "id" => "26428c80-3cee-11ea-8080-80013d33eb64"
        "object" => CommunityPost {#1683 ▶}
        "origin" => null
        "target" => ""
        "time" => "2020-01-22T08:06:53.000000"
        "verb" => "post"
      ]
    ]
    "activity_count" => 1
    "actor_count" => 1
    "created_at" => "2020-01-22T08:06:53.970618"
    "group" => "post_2020-01-22_26428c80-3cee-11ea-8080-80013d33eb64_"
    "id" => "26d6a746-3cee-11ea-8080-80000fca6a99.post_2020-01-22_26428c80-3cee-11ea-8080-80013d33eb64_"
    "is_read" => false
    "is_seen" => false
    "updated_at" => "2020-01-22T08:06:53.970618"
    "verb" => "post"
  ]

Solution

  • Probably the simplest approach is to parse the activity body field and search for @username. When found render the activity as a mention instead of a regular post.

    You can also add custom data to the activity; ie. add a mentioned_user_ids custom field and include the IDs of all users that were mentioned.