Dnyan
Well-known member
Hello all,
I am developing addon for xF2.
Can anyone confirm below code is correct or not.
I want to take alert for conversation msg from below code, this will be further process to send alert.
Will this work to send alerts for conversation.
Thank You
I am developing addon for xF2.
Can anyone confirm below code is correct or not.
I want to take alert for conversation msg from below code, this will be further process to send alert.
PHP:
<?php
namespace My\Directory;
class Notifier extends XFCP_Notifier
{
protected $conversation;
protected function _sendNotifications(
$actionType, array $notifyUsers, \XF\Entity\ConversationMessage $message = null, \XF\Entity\User $sender = null
)
{
if (!$sender && $message)
{
$sender = $message->User;
}
$usersEmailed = [];
/** @var \XF\Entity\User $user */
foreach ($notifyUsers AS $user)
{
if (!$this->_canUserReceiveNotification($user, $sender))
{
continue;
}
if((isset($user->Profile->custom_fields->my_field) && $user->Profile->custom_fields->my_field)
$template = 'conversation_' . $actionType;
$params = [
'receiver' => $user,
'sender' => $sender,
'conversation' => $this->conversation,
'message' => $message
];
$this->app->mailer()->newMail()
->setToUser($user)
->setTemplate($template, $params)
->queue();
$usersEmailed[$user->user_id] = $user;
}
return $usersEmailed;
if($user->user_state == 'valid' && !$user->is_banned)
{
ConversationAlert::sendAlert($user->username, $conversation, $sender->username);
}
}
}
class ConversationAlert
{
public static function sendAlert($uname, $mid, $tuname)
{
$url = \XF::app()->router('public')->buildLink('full:account/conversations/'.$mid 'conversation_id' . '/unread');
$content = array(
"en" => 'New Conversation from ' . $tuname . $message
);
Few more lines for doing further processing to push notification
}
}
Will this work to send alerts for conversation.
Thank You