首页 > 解决方案 > 如何检查通知是否是提及

问题描述

我正在使用 stream-laravel,我想将 @-mentions 集成到我的帖子模型中。我现在添加activityNotify()了帖子中提到的用户。这工作正常。但是,当我检索通知提要时,动词是“发布”,因为活动当然是发布。

对于前端,我想知道它何时是@提及。处理这个问题的最佳方法是什么?

我像这样通知@提及用户

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

标签: getstream-io

解决方案


可能最简单的方法是解析活动主体字段并搜索@username. 找到后,将活动呈现为提及而不是常规帖子。

您还可以将自定义数据添加到活动中;IE。添加一个提到的用户 ID 自定义字段并包含所有提到的用户的 ID。


推荐阅读