From 8c9346fc12b57d8737c608625878a8b4adc5ef2d Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Feb 2021 10:31:38 +0000 Subject: [PATCH] New table "post-user-notification" --- src/Model/Post/User.php | 4 +- src/Model/Post/UserNotifcation.php | 99 ++++++++++++++++++++++++++++++ src/Model/UserItem.php | 3 +- static/dbstructure.config.php | 27 +++++--- 4 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 src/Model/Post/UserNotifcation.php diff --git a/src/Model/Post/User.php b/src/Model/Post/User.php index 6c2176656..dc53b726e 100644 --- a/src/Model/Post/User.php +++ b/src/Model/Post/User.php @@ -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 index 000000000..5dca875ab --- /dev/null +++ b/src/Model/Post/UserNotifcation.php @@ -0,0 +1,99 @@ +. + * + */ + +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); + } +} diff --git a/src/Model/UserItem.php b/src/Model/UserItem.php index e4badadb0..3405d9a6a 100644 --- a/src/Model/UserItem.php +++ b/src/Model/UserItem.php @@ -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); } diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 3b833d9e3..362f299c1 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -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"], - "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"], - "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], - "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"], - "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], + "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"], "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"], + "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" => ""], // 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" => [