]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/UserNotification.php
Remove "fcontact" from suggestions
[friendica.git] / src / Model / Post / UserNotification.php
index 065cba44ca706f72f3e034a2b4b6eee64fda54d8..d14eb7f3be556a9c7b1cd94ecee028367bbc4337 100644 (file)
@@ -33,9 +33,9 @@ use Friendica\Model\Contact;
 use Friendica\Model\Post;
 use Friendica\Model\Subscription;
 use Friendica\Model\Tag;
+use Friendica\Navigation\Notifications;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
-use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
 class UserNotification
@@ -286,56 +286,46 @@ class UserNotification
                        return;
                }
 
-               $fields = [
-                       'uid' => $uid,
-                       'vid' => $item['vid'],
-                       'type' => $type,
-                       'actor-id' => $item['author-id'],
-                       'parent-uri-id' => $item['parent-uri-id'],
-                       'created' => DateTimeFormat::utcNow(),
-               ];
+               $notification = (new Notifications\Factory\Notification(DI::logger()))->createForUser(
+                       $uid,
+                       $item['vid'],
+                       $type,
+                       $item['author-id'],
+                       $item['gravity'] == GRAVITY_ACTIVITY ? $item['thr-parent-id'] : $item['uri-id'],
+                       $item['parent-uri-id']
+               );
 
-               if ($item['gravity'] == GRAVITY_ACTIVITY) {
-                       $fields['target-uri-id'] = $item['thr-parent-id'];
-               } else {
-                       $fields['target-uri-id'] = $item['uri-id'];
-               }
+               try {
+                       $notification = DI::notification()->save($notification);
+                       Subscription::pushByNotification($notification);
+               } catch (Exception $e) {
 
-               if (DBA::insert('notification', $fields, Database::INSERT_IGNORE)) {
-                       $id = DBA::lastInsertId();
-                       if (!empty($id)) {
-                               Subscription::pushByNotificationId($id);
-                       }
                }
        }
 
        /**
         * Add a notification entry
         *
-        * @param int $actor Contact ID of the actor
-        * @param int $vid   Verb ID
-        * @param int $uid   User ID
+        * @param int    $actor 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, int $vid, int $uid): bool
+       public static function insertNotification(int $actor, string $verb, int $uid): bool
        {
-               $fields = [
-                       'uid' => $uid,
-                       'vid' => $vid,
-                       'type' => self::TYPE_NONE,
-                       'actor-id' => $actor,
-                       'created' => DateTimeFormat::utcNow(),
-               ];
-
-               $ret = DBA::insert('notification', $fields, Database::INSERT_IGNORE);
-               if ($ret) {
-                       $id = DBA::lastInsertId();
-                       if (!empty($id)) {
-                               Subscription::pushByNotificationId($id);
-                       }
+               $notification = (new Notifications\Factory\Notification(DI::logger()))->createForRelationship(
+                       $uid,
+                       $actor,
+                       $verb
+               );
+               try {
+                       $notification = DI::notification()->save($notification);
+                       Subscription::pushByNotification($notification);
+                       return true;
+               } catch (Exception $e) {
+                       return false;
                }
-               return $ret;
        }
 
        /**