--- /dev/null
+<?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);
+ }
+}
"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"],
"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" => [