(SELECT `uri-id` FROM `post-user-notification` WHERE `uid` = ? AND `notification-type` & ? != 0 ORDER BY `uri-id`)
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `id` > ?";
- $condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(),
- Post\UserNotification::NOTIF_EXPLICIT_TAGGED | Post\UserNotification::NOTIF_IMPLICIT_TAGGED |
- Post\UserNotification::NOTIF_THREAD_COMMENT | Post\UserNotification::NOTIF_DIRECT_COMMENT |
- Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT,
- api_user(), $since_id];
+ $condition = [
+ GRAVITY_PARENT, GRAVITY_COMMENT,
+ api_user(),
+ Post\UserNotification::TYPE_EXPLICIT_TAGGED | Post\UserNotification::TYPE_IMPLICIT_TAGGED |
+ Post\UserNotification::TYPE_THREAD_COMMENT | Post\UserNotification::TYPE_DIRECT_COMMENT |
+ Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT,
+ api_user(), $since_id,
+ ];
if ($max_id > 0) {
$query .= " AND `id` <= ?";
{
Logger::info('Start', ['uid' => $notification['uid'], 'id' => $notification['id'], 'type' => $notification['type']]);
- if ($notification['type'] == Post\UserNotification::NOTIF_NONE) {
+ if ($notification['type'] == Post\UserNotification::TYPE_NONE) {
Logger::info('Not an item based notification, quitting', ['uid' => $notification['uid'], 'id' => $notification['id'], 'type' => $notification['type']]);
return false;
}
// So, we cannot have different subjects for notifications of the same thread.
// Before this we have the name of the replier on the subject rendering
// different subjects for messages on the same thread.
- if ($notification['type'] == Post\UserNotification::NOTIF_EXPLICIT_TAGGED) {
+ if ($notification['type'] == Post\UserNotification::TYPE_EXPLICIT_TAGGED) {
$params['type'] = Notification\Type::TAG_SELF;
$subject = $l10n->t('%s %s tagged you', $subjectPrefix, $contact['name']);
- } elseif ($notification['type'] == Post\UserNotification::NOTIF_SHARED) {
+ } elseif ($notification['type'] == Post\UserNotification::TYPE_SHARED) {
$params['type'] = Notification\Type::SHARE;
$subject = $l10n->t('%s %s shared a new post', $subjectPrefix, $contact['name']);
} else {
*/
public static function getType(array $notification): string
{
- if (($notification['vid'] == Verb::getID(Activity::FOLLOW)) && ($notification['type'] == Post\UserNotification::NOTIF_NONE)) {
+ if (($notification['vid'] == Verb::getID(Activity::FOLLOW)) && ($notification['type'] == Post\UserNotification::TYPE_NONE)) {
$contact = Contact::getById($notification['actor-id'], ['pending']);
$type = $contact['pending'] ? 'follow_request' : 'follow';
} elseif (($notification['vid'] == Verb::getID(Activity::ANNOUNCE)) &&
- in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
+ in_array($notification['type'], [Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT])) {
$type = 'reblog';
} elseif (in_array($notification['vid'], [Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE)]) &&
- in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
+ in_array($notification['type'], [Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT])) {
$type = 'favourite';
- } elseif ($notification['type'] == Post\UserNotification::NOTIF_SHARED) {
+ } elseif ($notification['type'] == Post\UserNotification::TYPE_SHARED) {
$type = 'status';
- } elseif (in_array($notification['type'], [Post\UserNotification::NOTIF_EXPLICIT_TAGGED,
- Post\UserNotification::NOTIF_IMPLICIT_TAGGED, Post\UserNotification::NOTIF_DIRECT_COMMENT,
- Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT])) {
+ } elseif (in_array($notification['type'], [
+ Post\UserNotification::TYPE_EXPLICIT_TAGGED,
+ Post\UserNotification::TYPE_IMPLICIT_TAGGED,
+ Post\UserNotification::TYPE_DIRECT_COMMENT,
+ Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT,
+ Post\UserNotification::TYPE_THREAD_COMMENT
+ ])) {
$type = 'mention';
} else {
return '';
return $message;
}
- if ($notification['type'] == Post\UserNotification::NOTIF_NONE) {
+ if ($notification['type'] == Post\UserNotification::TYPE_NONE) {
if ($contact['pending']) {
$msg = $l10n->t('%1$s wants to follow you');
} else {
$announce = Verb::getID(Activity::ANNOUNCE);
$post = Verb::getID(Activity::POST);
- if (in_array($notification['type'], [Post\UserNotification::NOTIF_THREAD_COMMENT, Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION, Post\UserNotification::NOTIF_EXPLICIT_TAGGED])) {
+ if (in_array($notification['type'], [Post\UserNotification::TYPE_THREAD_COMMENT, Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_EXPLICIT_TAGGED])) {
$item = Post::selectFirst([], ['uri-id' => $notification['parent-uri-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]);
if (empty($item)) {
Logger::info('Parent post not found', ['uri-id' => $notification['parent-uri-id']]);
$cid = $item['causer-id'];
}
- if (($notification['type'] == Post\UserNotification::NOTIF_SHARED) && !empty($cid)) {
+ if (($notification['type'] == Post\UserNotification::TYPE_SHARED) && !empty($cid)) {
$causer = Contact::getById($cid, ['id', 'name', 'url']);
if (empty($contact)) {
Logger::info('Causer not found', ['causer' => $cid]);
return $message;
}
- } elseif (in_array($notification['type'], [Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION])) {
+ } elseif (in_array($notification['type'], [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION])) {
$contact = Contact::getById($item['author-id'], ['id', 'name', 'url']);
if (empty($contact)) {
Logger::info('Author not found', ['author' => $item['author-id']]);
switch ($notification['vid']) {
case $like:
switch ($notification['type']) {
- case Post\UserNotification::NOTIF_DIRECT_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_COMMENT:
$msg = $l10n->t('%1$s liked your comment %2$s');
break;
- case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s liked your post %2$s');
break;
}
break;
case $dislike:
switch ($notification['type']) {
- case Post\UserNotification::NOTIF_DIRECT_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_COMMENT:
$msg = $l10n->t('%1$s disliked your comment %2$s');
break;
- case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s disliked your post %2$s');
break;
}
break;
case $announce:
switch ($notification['type']) {
- case Post\UserNotification::NOTIF_DIRECT_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_COMMENT:
$msg = $l10n->t('%1$s shared your comment %2$s');
break;
- case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s shared your post %2$s');
break;
}
break;
case $post:
switch ($notification['type']) {
- case Post\UserNotification::NOTIF_EXPLICIT_TAGGED:
+ case Post\UserNotification::TYPE_EXPLICIT_TAGGED:
$msg = $l10n->t('%1$s tagged you on %2$s');
break;
- case Post\UserNotification::NOTIF_IMPLICIT_TAGGED:
+ case Post\UserNotification::TYPE_IMPLICIT_TAGGED:
$msg = $l10n->t('%1$s replied to you on %2$s');
break;
- case Post\UserNotification::NOTIF_THREAD_COMMENT:
+ case Post\UserNotification::TYPE_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented in your thread %2$s');
break;
- case Post\UserNotification::NOTIF_DIRECT_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_COMMENT:
$msg = $l10n->t('%1$s commented on your comment %2$s');
break;
- case Post\UserNotification::NOTIF_COMMENT_PARTICIPATION:
- case Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION:
+ case Post\UserNotification::TYPE_COMMENT_PARTICIPATION:
+ case Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION:
if (($causer['id'] == $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s commented in their thread %2$s');
} elseif ($causer['id'] == $contact['id']) {
}
break;
- case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
+ case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented on your thread %2$s');
break;
- case Post\UserNotification::NOTIF_SHARED:
+ case Post\UserNotification::TYPE_SHARED:
if (($causer['id'] != $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s shared the post %2$s from %3$s');
} elseif ($causer['id'] != $contact['id']) {
class UserNotification
{
// Notification types
- const NOTIF_NONE = 0;
- const NOTIF_EXPLICIT_TAGGED = 1;
- const NOTIF_IMPLICIT_TAGGED = 2;
- const NOTIF_THREAD_COMMENT = 4;
- const NOTIF_DIRECT_COMMENT = 8;
- const NOTIF_COMMENT_PARTICIPATION = 16;
- const NOTIF_ACTIVITY_PARTICIPATION = 32;
- const NOTIF_DIRECT_THREAD_COMMENT = 64;
- const NOTIF_SHARED = 128;
-
+ const TYPE_NONE = 0;
+ const TYPE_EXPLICIT_TAGGED = 1;
+ const TYPE_IMPLICIT_TAGGED = 2;
+ const TYPE_THREAD_COMMENT = 4;
+ const TYPE_DIRECT_COMMENT = 8;
+ const TYPE_COMMENT_PARTICIPATION = 16;
+ const TYPE_ACTIVITY_PARTICIPATION = 32;
+ const TYPE_DIRECT_THREAD_COMMENT = 64;
+ const TYPE_SHARED = 128;
/**
* Insert a new user notification entry
return;
}
- $notification_type = self::NOTIF_NONE;
+ $notification_type = self::TYPE_NONE;
if (self::checkShared($item, $uid)) {
- $notification_type = $notification_type | self::NOTIF_SHARED;
- self::insertNoticationByItem(self::NOTIF_SHARED, $uid, $item);
+ $notification_type = $notification_type | self::TYPE_SHARED;
+ self::insertNoticationByItem(self::TYPE_SHARED, $uid, $item);
$notified = true;
} else {
$notified = false;
}
if (self::checkExplicitMention($item, $profiles)) {
- $notification_type = $notification_type | self::NOTIF_EXPLICIT_TAGGED;
+ $notification_type = $notification_type | self::TYPE_EXPLICIT_TAGGED;
if (!$notified) {
- self::insertNoticationByItem( self::NOTIF_EXPLICIT_TAGGED, $uid, $item);
+ self::insertNoticationByItem( self::TYPE_EXPLICIT_TAGGED, $uid, $item);
$notified = true;
}
}
if (self::checkImplicitMention($item, $profiles)) {
- $notification_type = $notification_type | self::NOTIF_IMPLICIT_TAGGED;
+ $notification_type = $notification_type | self::TYPE_IMPLICIT_TAGGED;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_IMPLICIT_TAGGED, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_IMPLICIT_TAGGED, $uid, $item);
$notified = true;
}
}
if (self::checkDirectComment($item, $contacts)) {
- $notification_type = $notification_type | self::NOTIF_DIRECT_COMMENT;
+ $notification_type = $notification_type | self::TYPE_DIRECT_COMMENT;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_DIRECT_COMMENT, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_DIRECT_COMMENT, $uid, $item);
$notified = true;
}
}
if (self::checkDirectCommentedThread($item, $contacts)) {
- $notification_type = $notification_type | self::NOTIF_DIRECT_THREAD_COMMENT;
+ $notification_type = $notification_type | self::TYPE_DIRECT_THREAD_COMMENT;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_DIRECT_THREAD_COMMENT, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_DIRECT_THREAD_COMMENT, $uid, $item);
$notified = true;
}
}
if (self::checkCommentedThread($item, $contacts)) {
- $notification_type = $notification_type | self::NOTIF_THREAD_COMMENT;
+ $notification_type = $notification_type | self::TYPE_THREAD_COMMENT;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_THREAD_COMMENT, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_THREAD_COMMENT, $uid, $item);
$notified = true;
}
}
if (self::checkCommentedParticipation($item, $contacts)) {
- $notification_type = $notification_type | self::NOTIF_COMMENT_PARTICIPATION;
+ $notification_type = $notification_type | self::TYPE_COMMENT_PARTICIPATION;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_COMMENT_PARTICIPATION, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_COMMENT_PARTICIPATION, $uid, $item);
$notified = true;
}
}
if (self::checkActivityParticipation($item, $contacts)) {
- $notification_type = $notification_type | self::NOTIF_ACTIVITY_PARTICIPATION;
+ $notification_type = $notification_type | self::TYPE_ACTIVITY_PARTICIPATION;
if (!$notified) {
- self::insertNoticationByItem(self::NOTIF_ACTIVITY_PARTICIPATION, $uid, $item);
+ self::insertNoticationByItem(self::TYPE_ACTIVITY_PARTICIPATION, $uid, $item);
$notified = true;
}
}
private static function insertNoticationByItem(int $type, int $uid, array $item)
{
if (($item['gravity'] == GRAVITY_ACTIVITY) &&
- !in_array($type, [self::NOTIF_DIRECT_COMMENT, self::NOTIF_DIRECT_THREAD_COMMENT])) {
+ !in_array($type, [self::TYPE_DIRECT_COMMENT, self::TYPE_DIRECT_THREAD_COMMENT])) {
// Activities are only stored when performed on the user's post or comment
return;
}
$fields = [
'uid' => $uid,
'vid' => $vid,
- 'type' => self::NOTIF_NONE,
+ 'type' => self::TYPE_NONE,
'actor-id' => $actor,
'created' => DateTimeFormat::utcNow(),
];
if (in_array('follow_request', $request['exclude_types'])) {
$condition = DBA::mergeConditions($condition,
["(`vid` != ? OR `type` != ? OR NOT EXISTS (SELECT `id` FROM `contact` WHERE `id` = `actor-id` AND `pending`))",
- Verb::getID(Activity::FOLLOW), Post\UserNotification::NOTIF_NONE]);
+ Verb::getID(Activity::FOLLOW), Post\UserNotification::TYPE_NONE]);
}
if (in_array('follow', $request['exclude_types'])) {
$condition = DBA::mergeConditions($condition,
["(`vid` != ? OR `type` != ? OR NOT EXISTS (SELECT `id` FROM `contact` WHERE `id` = `actor-id` AND NOT `pending`))",
- Verb::getID(Activity::FOLLOW), Post\UserNotification::NOTIF_NONE]);
+ Verb::getID(Activity::FOLLOW), Post\UserNotification::TYPE_NONE]);
}
if (in_array('favourite', $request['exclude_types'])) {
- $condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?, ?) OR NOT `type` IN (?, ?))",
+ $condition = DBA::mergeConditions($condition, [
+ "(NOT `vid` IN (?, ?) OR NOT `type` IN (?, ?))",
Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE),
- Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
+ Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT
+ ]);
}
if (in_array('reblog', $request['exclude_types'])) {
- $condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?, ?))",
+ $condition = DBA::mergeConditions($condition, [
+ "(NOT `vid` IN (?) OR NOT `type` IN (?, ?))",
Verb::getID(Activity::ANNOUNCE),
- Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
+ Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT
+ ]);
}
if (in_array('mention', $request['exclude_types'])) {
- $condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?, ?, ?, ?, ?))",
- Verb::getID(Activity::POST), Post\UserNotification::NOTIF_EXPLICIT_TAGGED,
- Post\UserNotification::NOTIF_IMPLICIT_TAGGED, Post\UserNotification::NOTIF_DIRECT_COMMENT,
- Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
+ $condition = DBA::mergeConditions($condition, [
+ "(NOT `vid` IN (?) OR NOT `type` IN (?, ?, ?, ?, ?))",
+ Verb::getID(Activity::POST), Post\UserNotification::TYPE_EXPLICIT_TAGGED,
+ Post\UserNotification::TYPE_IMPLICIT_TAGGED, Post\UserNotification::TYPE_DIRECT_COMMENT,
+ Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT]);
}
if (in_array('status', $request['exclude_types'])) {
$condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?))",
- Verb::getID(Activity::POST), Post\UserNotification::NOTIF_SHARED]);
+ Verb::getID(Activity::POST), Post\UserNotification::TYPE_SHARED]);
}
if (!empty($request['max_id'])) {