Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to connect a chat plugins notifications to bp-notifications


  • woofy123
    Participant

    @woofy123

    Hii,

    So I’ve tried a lot of searches, forms but I don’t seem to find an answer…..if someone could please help

    I have a chat plugin and I want that chat plugin to integrate with bp-notifications.
    So what I want is that-
    1. whenever a message arrives in the chat–it appears in the users bp-notification
    2. when a user is mentioned in the chat—it appears in the users’s bp-profile in the mentions

    please someone help me with this…please..please..please

    THANK YOU VERY MUCH

Viewing 2 replies - 1 through 2 (of 2 total)

  • shanebp
    Moderator

    @shanebp

    The integration needs to go from the chat plugin to BP, not the other way around.
    Therefore nobody here can help you.
    You need to speak to the creators of the chat plugin.


    woofy123
    Participant

    @woofy123

    @shanebp

    Hi, thanks for your reply before. I checked with the creators of the plugin and they say they can’t do it. so i decided to check by myself….the wise chat plugin redirects notifications to the email and the code for that is below….i don’t know coding and all that so i seriously need your help…what code do i put inplace of the email so that messages are reduirected to buddypress notifications? Please help..The code—–

    `<?php

    /**
    * WiseChat user notifications services.
    *
    * @author Kainex <contact@kaine.pl>
    */
    class WiseChatUserNotificationsService {

    /**
    * @var WiseChatUserNotificationsDAO
    */
    private $userNotificationsDAO;

    /**
    * @var WiseChatSentNotificationsDAO
    */
    private $sentNotificationsDAO;

    /**
    * @var WiseChatUsersDAO
    */
    private $usersDAO;

    /**
    * @var WiseChatChannelUsersDAO
    */
    private $channelUsersDAO;

    /**
    * @var WiseChatHttpRequestService
    */
    private $httpRequestService;

    /**
    * @var WiseChatOptions
    */
    private $options;

    public function __construct() {
    $this->options = WiseChatOptions::getInstance();
    $this->userNotificationsDAO = WiseChatContainer::getLazy(‘dao/WiseChatUserNotificationsDAO’);
    $this->sentNotificationsDAO = WiseChatContainer::getLazy(‘dao/WiseChatSentNotificationsDAO’);
    $this->usersDAO = WiseChatContainer::get(‘dao/user/WiseChatUsersDAO’);
    $this->channelUsersDAO = WiseChatContainer::get(‘dao/WiseChatChannelUsersDAO’);
    $this->httpRequestService = WiseChatContainer::getLazy(‘services/WiseChatHttpRequestService’);
    }

    /**
    * Sends all notifications for message.
    *
    * @param WiseChatMessage $message
    * @param WiseChatChannel $channel
    */
    public function send($message, $channel) {
    foreach ($this->userNotificationsDAO->getAll() as $notification) {
    $this->sendNotification($message, $channel, $notification);
    }
    }

    /**
    * Sends the notification.
    *
    * @param WiseChatMessage $message
    * @param WiseChatChannel $channel
    * @param WiseChatUserNotification $notification
    */
    private function sendNotification($message, $channel, $notification) {
    if ($notification->getType() == ’email’) {
    $this->sendEmailNotification($message, $channel, $notification);
    }
    }

    /**
    * Sends e-mail notification.
    *
    * @param WiseChatMessage $message
    * @param WiseChatChannel $channel
    * @param WiseChatUserNotification $notification
    */
    private function sendEmailNotification($message, $channel, $notification) {
    $timeRange = null; // seconds

    if ($notification->getFrequency() == ‘daily’) {
    $timeRange = 24 * 60 * 60;
    }
    if ($notification->getFrequency() == ‘hourly’) {
    $timeRange = 60 * 60;
    }
    if ($timeRange === null) {
    return;
    }

    if ($this->sentNotificationsDAO->wasNotificationSendForUser($notification->getId(), $channel->getId(), $message->getUserId(), $timeRange)) {
    return;
    }

    $recipientUser = $this->usersDAO->get($message->getRecipientId());
    if ($recipientUser === null) {
    return;
    }

    $channelUser = $this->channelUsersDAO->getActiveByUserIdAndChannelId($recipientUser->getId(), $channel->getId());
    if ($channelUser !== null) {
    return;
    }

    if ($recipientUser->getDataProperty(‘disableNotifications’) === true) {
    return;
    }

    if (!($recipientUser->getWordPressId() > 0)) {
    return;
    }

    $recipientWordPressUser = $this->usersDAO->getWpUserByID($recipientUser->getWordPressId());
    if ($recipientWordPressUser === null) {
    return;
    }

    $sentNotification = new WiseChatSentNotification();
    $sentNotification->setNotificationId($notification->getId());
    $sentNotification->setSentTime(time());
    $sentNotification->setChannelId($channel->getId());
    $sentNotification->setUserId($message->getUserId());
    $this->sentNotificationsDAO->save($sentNotification);

    // send the e-mail:
    $templateData = array(
    ‘${recipient}’ => $recipientWordPressUser->display_name,
    ‘${recipient-email}’ => $recipientWordPressUser->user_email,
    ‘${sender}’ => strip_tags($message->getUserName()),
    ‘${message}’ => $message->getText(),
    ‘${channel}’ => $message->getChannelName(),
    ‘${link}’ => $this->httpRequestService->getReferrerURL()
    );
    $emailSubject = str_replace(array_keys($templateData), array_values($templateData), $notification->getDetails()[‘subject’]);
    $emailBody = str_replace(array_keys($templateData), array_values($templateData), $notification->getDetails()[‘content’]);

    wp_mail($recipientWordPressUser->user_email, $emailSubject, $emailBody);
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar