+ /**
+ * Add a notification entry for a given item array
+ *
+ * @param int $type User notification type
+ * @param int $uid User ID
+ * @param array $item Item array
+ * @return void
+ * @throws Exception
+ */
+ private static function insertNotificationByItem(int $type, int $uid, array $item): void
+ {
+ if (($item['verb'] != Activity::ANNOUNCE) && ($item['gravity'] == Item::GRAVITY_ACTIVITY) &&
+ !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;
+ }
+
+ $notification = DI::notificationFactory()->createForUser(
+ $uid,
+ $item['vid'],
+ $type,
+ $item['author-id'],
+ $item['gravity'] == Item::GRAVITY_ACTIVITY ? $item['thr-parent-id'] : $item['uri-id'],
+ $item['parent-uri-id']
+ );
+
+ try {
+ $notification = DI::notification()->save($notification);
+ Subscription::pushByNotification($notification);
+ } catch (Exception $e) {
+
+ }
+ }
+
+ /**
+ * Add a notification entry
+ *
+ * @param int $actor Public contact ID of the actor
+ * @param string $verb One of the Activity verb constant values
+ * @param int $uid User ID
+ * @return boolean
+ * @throws Exception
+ */
+ public static function insertNotification(int $actor, string $verb, int $uid): bool
+ {
+ $notification = DI::notificationFactory()->createForRelationship(
+ $uid,
+ $actor,
+ $verb
+ );
+ try {
+ $notification = DI::notification()->save($notification);
+ Subscription::pushByNotification($notification);
+ return true;
+ } catch (Exception $e) {
+ return false;
+ }
+ }
+