Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

How to send vanilla notifications via API?

I have a PHP Chat integrated very nicely, and I wondering how to tap into the Vanilla's notification system.

I am working on some code that will sniff @mentions in the chat, but I can't find any docs on how to finalize it so it can send the notification.

I have spend time digging into the core and other plugins.

Thanks in advance

Comments

  • charrondevcharrondev Application Developer (PHP, JS) Montreal Vanilla Staff
    edited February 18

    About Notifications & ActivityModel

    Our notification system is due for a revamp relatively soon, but in the meantime our mention system is relatively unchanged and undocumented. Notifications currently work through the ActivityModel (see the related tables in the DB). 2.8 adds endpoints for getting notifications:

    but we haven't built out the ones for sending them yet. This will likely happen in a near future release.

    How to do it right now

    You can find an example in the discussions model (comment model as well).

    And a code snippet:

    $user = $userModel->getByUsername($username);
    if (!$user) {
    continue;
    }
    // Check user can still see the discussion.
    if (!$this->canView($fields, $user->UserID)) {
        continue;
    }
    $activity['HeadlineFormat'] = t('HeadlineFormat.Mention', '{ActivityUserID,user} mentioned you in <a href="{Url,html}">{Data.Name,text}</a>');
    $activity['NotifyUserID'] = val('UserID', $user);
    $activityModel->queue($activity, 'Mention');
    
    donshakespeare
Sign In or Register to comment.