<?php
 namespace App\Listeners; use Illuminate\Events\Dispatcher; use TechSoft\Laravel\Forum\Events\PostHasNewReply; use TechSoft\Laravel\Forum\Events\ThreadHasNewPost; use TechSoft\Laravel\Member\MemberUtil; use TechSoft\Laravel\MemberMessage\MemberMessageUtil; class MemberMessageListener { public function onThreadHasNewPost(ThreadHasNewPost $threadHasNewPost) { if ($threadHasNewPost->thread['memberUserId'] == $threadHasNewPost->post['memberUserId']) { return; } $threadHasNewPost->thread['_memberUser'] = MemberUtil::get($threadHasNewPost->thread['memberUserId']); $threadHasNewPost->post['_memberUser'] = MemberUtil::get($threadHasNewPost->post['memberUserId']); MemberMessageUtil::sendTemplate($threadHasNewPost->thread['memberUserId'], 'threadHasNewPost', [ 'thread' => $threadHasNewPost->thread, 'post' => $threadHasNewPost->post, 'postPage' => $threadHasNewPost->postPage, ]); } public function onPostHasNewReply(PostHasNewReply $postHasNewReply) { if ($postHasNewReply->yourPost['memberUserId'] == $postHasNewReply->replyPost['memberUserId']) { return; } if ($postHasNewReply->thread['memberUserId'] == $postHasNewReply->yourPost['memberUserId']) { return; } $postHasNewReply->thread['_memberUser'] = MemberUtil::get($postHasNewReply->thread['memberUserId']); $postHasNewReply->yourPost['_memberUser'] = MemberUtil::get($postHasNewReply->yourPost['memberUserId']); $postHasNewReply->replyPost['_memberUser'] = MemberUtil::get($postHasNewReply->replyPost['memberUserId']); MemberMessageUtil::sendTemplate($postHasNewReply->yourPost['memberUserId'], 'postHasNewReply', [ 'thread' => $postHasNewReply->thread, 'yourPost' => $postHasNewReply->yourPost, 'replyPost' => $postHasNewReply->replyPost, 'replyPostPage' => $postHasNewReply->replyPostPage, ]); } public function subscribe(Dispatcher $events) { $events->listen(ThreadHasNewPost::class, '\App\Listeners\MemberMessageListener@onThreadHasNewPost'); $events->listen(PostHasNewReply::class, '\App\Listeners\MemberMessageListener@onPostHasNewReply'); } }