如何检查通知是否被提及

How check if a notification is a mention

我正在使用 stream-laravel,我想将 @-mentions 集成到我的 post 模型中。我现在在 activityNotify() 中添加了 post 中提到的用户。这很好用。但是,当我检索通知提要时,动词是 'post',因为 activity 当然是 post。

对于前端,我想知道它何时被@mention。处理此问题的最佳方法是什么?

我这样通知@mention 用户

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

        return $notify;
    }

我的通知输出如下所示:

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"
  ]

可能最简单的方法是解析 activity 正文字段并搜索 @username。当找到时将 activity 渲染为提及而不是常规的 post.

您还可以向 activity 添加自定义数据; IE。添加 mentioned_user_ids 自定义字段并包含提到的所有用户的 ID。