New table "post-user-notification"
This commit is contained in:
parent
08317036e7
commit
8c9346fc12
4 changed files with 123 additions and 10 deletions
|
@ -29,7 +29,7 @@ use Friendica\Database\DBStructure;
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Insert a new URI user entry
|
* Insert a new post user entry
|
||||||
*
|
*
|
||||||
* @param integer $uri_id
|
* @param integer $uri_id
|
||||||
* @param integer $uid
|
* @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 $uri_id
|
||||||
* @param integer $uid
|
* @param integer $uid
|
||||||
|
|
99
src/Model/Post/UserNotifcation.php
Normal file
99
src/Model/Post/UserNotifcation.php
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -152,10 +152,11 @@ class UserItem
|
||||||
return;
|
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];
|
$fields = ['notification-type' => $notification_type];
|
||||||
Post\User::update($item['uri-id'], $uid, $fields);
|
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);
|
DBA::update('user-item', $fields, ['iid' => $item['id'], 'uid' => $uid], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -773,22 +773,23 @@ return [
|
||||||
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
|
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
|
||||||
"moderated" => ["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"],
|
"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"],
|
"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"],
|
"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"],
|
"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"],
|
"origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
|
||||||
"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"],
|
"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
|
// 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"],
|
"event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
|
||||||
// Check deprecation status
|
// Check deprecation status
|
||||||
"type" => ["type" => "varchar(20)", "comment" => ""],
|
"type" => ["type" => "varchar(20)", "comment" => ""],
|
||||||
"bookmark" => ["type" => "boolean", "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
|
// Deprecated fields. Will be removed in upcoming versions
|
||||||
"resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
|
"resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
|
||||||
"uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
|
"uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
|
||||||
|
@ -1235,6 +1236,18 @@ return [
|
||||||
"psid" => ["psid"],
|
"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" => [
|
"process" => [
|
||||||
"comment" => "Currently running system processes",
|
"comment" => "Currently running system processes",
|
||||||
"fields" => [
|
"fields" => [
|
||||||
|
|
Loading…
Reference in a new issue