]> git.mxchange.org Git - friendica.git/commitdiff
New table "post-user-notification"
authorMichael <heluecht@pirati.ca>
Mon, 1 Feb 2021 10:31:38 +0000 (10:31 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 1 Feb 2021 10:31:38 +0000 (10:31 +0000)
src/Model/Post/User.php
src/Model/Post/UserNotifcation.php [new file with mode: 0644]
src/Model/UserItem.php
static/dbstructure.config.php

index 6c217665618e053c44c4098336017d607efad073..dc53b726e23b98323e3e0645c5e74aea84080fa1 100644 (file)
@@ -29,7 +29,7 @@ use Friendica\Database\DBStructure;
 class User
 {
        /**
-        * Insert a new URI user entry
+        * Insert a new post user entry
         *
         * @param integer $uri_id
         * @param integer $uid
@@ -66,7 +66,7 @@ class User
        }
 
        /**
-        * Update a URI user entry
+        * Update a post user entry
         *
         * @param integer $uri_id
         * @param integer $uid
diff --git a/src/Model/Post/UserNotifcation.php b/src/Model/Post/UserNotifcation.php
new file mode 100644 (file)
index 0000000..5dca875
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Model\Post;
+
+use \BadMethodCallException;
+use Friendica\Database\Database;
+use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
+
+class UserNotification
+{
+       /**
+        * Insert a new user notification entry
+        *
+        * @param integer $uri_id
+        * @param integer $uid
+        * @param array   $fields
+        * @return bool   success
+        * @throws \Exception
+        */
+       public static function insert(int $uri_id, int $uid, array $data = [])
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               $fields = DBStructure::getFieldsForTable('post-user-notification', $data);
+
+               // Additionally assign the key fields
+               $fields['uri-id'] = $uri_id;
+               $fields['uid'] = $uid;
+
+               return DBA::insert('post-user-notification', $fields, Database::INSERT_IGNORE);
+       }
+
+       /**
+        * Update a user notification entry
+        *
+        * @param integer $uri_id
+        * @param integer $uid
+        * @param array   $data
+        * @param bool    $insert_if_missing
+        * @return bool
+        * @throws \Exception
+        */
+       public static function update(int $uri_id, int $uid, array $data = [], bool $insert_if_missing = false)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               $fields = DBStructure::getFieldsForTable('post-user-notification', $data);
+
+               // Remove the key fields
+               unset($fields['uri-id']);
+               unset($fields['uid']);
+
+               if (empty($fields)) {
+                       return true;
+               }
+
+               return DBA::update('post-user-notification', $fields, ['uri-id' => $uri_id, 'uid' => $uid], $insert_if_missing ? true : []);
+       }
+
+       /**
+        * Delete a row from the post-user-notification table
+        *
+        * @param array        $conditions Field condition(s)
+        * @param array        $options
+        *                           - cascade: If true we delete records in other tables that depend on the one we're deleting through
+        *                           relations (default: true)
+        *
+        * @return boolean was the delete successful?
+        * @throws \Exception
+        */
+       public static function delete(array $conditions, array $options = [])
+       {
+               return DBA::delete('post-user-notification', $conditions, $options);
+       }
+}
index e4badadb0de04c718bc3dfccfac2506d291d75a7..3405d9a6a5faeae944278194b3dc94a81c4b5cae 100644 (file)
@@ -152,10 +152,11 @@ class UserItem
                        return;
                }
 
-               Logger::info('Set notification', ['iid' => $item['id'], 'uid' => $uid, 'notification-type' => $notification_type]);
+               Logger::info('Set notification', ['iid' => $item['id'], 'uri-id' => $item['uri-id'], 'uid' => $uid, 'notification-type' => $notification_type]);
 
                $fields = ['notification-type' => $notification_type];
                Post\User::update($item['uri-id'], $uid, $fields);
+               Post\UserNotification::update($item['uri-id'], $uid, $fields, true);
                DBA::update('user-item', $fields, ['iid' => $item['id'], 'uid' => $uid], true);
        }
 
index 3b833d9e3a80d4ea31c43ec618f515c9b06fc525..362f299c1e952604d5f835833bc3374522e06680 100644 (file)
@@ -773,22 +773,23 @@ return [
                        "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
-                       // User specific fields. Eventually they will move to post-user and post-thread-user
+                       // Part of "post-user". Will be deprecated in a later step
                        "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
                        "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"],
-                       "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
+                       "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
                        "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
-                       "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"],
+                       // Part of "post-thread-user". Will be deprecated in a later step
                        "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
-                       "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
-                       "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
+                       "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
+                       "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
-                       "psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"],
                        // It has to be decided whether these fields belong to the user or the structure
                        "event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
                        // Check deprecation status
                        "type" => ["type" => "varchar(20)", "comment" => ""],
                        "bookmark" => ["type" => "boolean", "comment" => ""],
+                       "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
                        // Deprecated fields. Will be removed in upcoming versions
                        "resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
                        "uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
@@ -1235,6 +1236,18 @@ return [
                        "psid" => ["psid"],
                ],
        ],
+// todo        
+       "post-user-notification" => [
+               "comment" => "User specific post data",
+               "fields" => [
+                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "uid" => ["type" => "mediumint unsigned", "not null" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
+                       "notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uid", "uri-id"],
+               ],
+       ],
        "process" => [
                "comment" => "Currently running system processes",
                "fields" => [