Update function for "post-user-notification"

This commit is contained in:
Michael 2021-02-01 20:11:25 +00:00
parent be3dfb4ffe
commit b26157e6e3
4 changed files with 38 additions and 12 deletions

View file

@ -709,17 +709,17 @@ CREATE TABLE IF NOT EXISTS `item` (
`deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted', `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id which owns this copy of the item',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id', `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
`wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
`origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
`pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
`starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
`unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen', `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
`mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it', `origin` boolean NOT NULL DEFAULT '0' COMMENT 'item originated at this site',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`psid` int unsigned COMMENT 'ID of the permission set of this post', `psid` int unsigned COMMENT 'ID of the permission set of this post',
`starred` boolean NOT NULL DEFAULT '0' COMMENT 'item has been favourited',
`wall` boolean NOT NULL DEFAULT '0' COMMENT 'This item was posted to the wall of uid',
`pubmail` boolean NOT NULL DEFAULT '0' COMMENT '',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`event-id` int unsigned COMMENT 'Used to link to the event.id', `event-id` int unsigned COMMENT 'Used to link to the event.id',
`type` varchar(20) COMMENT '', `type` varchar(20) COMMENT '',
`bookmark` boolean COMMENT '', `bookmark` boolean COMMENT '',
`mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
`resource-id` varchar(32) COMMENT 'Deprecated', `resource-id` varchar(32) COMMENT 'Deprecated',
`uri-hash` varchar(80) COMMENT 'Deprecated', `uri-hash` varchar(80) COMMENT 'Deprecated',
`iaid` int unsigned COMMENT 'Deprecated', `iaid` int unsigned COMMENT 'Deprecated',
@ -1186,6 +1186,19 @@ CREATE TABLE IF NOT EXISTS `post-user` (
FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
--
-- TABLE post-user-notification
--
CREATE TABLE IF NOT EXISTS `post-user-notification` (
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
`uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
`notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
PRIMARY KEY(`uid`,`uri-id`),
INDEX `uri-id` (`uri-id`),
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User post notifications';
-- --
-- TABLE process -- TABLE process
-- --

View file

@ -2170,16 +2170,15 @@ function api_statuses_mentions($type)
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$query = "`gravity` IN (?, ?) AND `uri-id` IN (SELECT `uri-id` FROM `post-user` $query = "`gravity` IN (?, ?) AND `uri-id` IN
WHERE (`hidden` IS NULL OR NOT `hidden`) AND (SELECT `uri-id` FROM `post-user-notification` WHERE `uid` = ? AND `notification-type` & ? != 0 ORDER BY `uri-id`)
`uid` = ? AND `notification-type` & ? != 0) AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `id` > ?";
AND `id` > ?";
$condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(), $condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(),
UserItem::NOTIF_EXPLICIT_TAGGED | UserItem::NOTIF_IMPLICIT_TAGGED | UserItem::NOTIF_EXPLICIT_TAGGED | UserItem::NOTIF_IMPLICIT_TAGGED |
UserItem::NOTIF_THREAD_COMMENT | UserItem::NOTIF_DIRECT_COMMENT | UserItem::NOTIF_THREAD_COMMENT | UserItem::NOTIF_DIRECT_COMMENT |
UserItem::NOTIF_DIRECT_THREAD_COMMENT, UserItem::NOTIF_DIRECT_THREAD_COMMENT,
$since_id]; api_user(), $since_id];
if ($max_id > 0) { if ($max_id > 0) {
$query .= " AND `id` <= ?"; $query .= " AND `id` <= ?";

View file

@ -1237,7 +1237,7 @@ return [
], ],
], ],
"post-user-notification" => [ "post-user-notification" => [
"comment" => "User specific post data", "comment" => "User post notifications",
"fields" => [ "fields" => [
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "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", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],

View file

@ -727,5 +727,19 @@ function update_1397()
FROM `thread` LEFT JOIN `user-item` ON `user-item`.`iid` = `thread`.`iid`")) { FROM `thread` LEFT JOIN `user-item` ON `user-item`.`iid` = `thread`.`iid`")) {
return Update::FAILED; return Update::FAILED;
} }
if (!DBA::e("INSERT INTO `post-user-notification`(`uri-id`, `uid`, `notification-type`)
SELECT `uri-id`, `user-item`.`uid`, `notification-type` FROM `user-item`
INNER JOIN `item` ON `item`.`id` = `user-item`.`iid` WHERE `notification-type` != 0
ON DUPLICATE KEY UPDATE `notification-type` = `user-item`.`notification-type`")) {
return Update::FAILED;
}
if (!DBA::e("INSERT IGNORE INTO `post-user-notification`(`uri-id`, `uid`, `notification-type`)
SELECT `uri-id`, `uid`, `notification-type` FROM `post-user` WHERE `notification-type` != 0
ON DUPLICATE KEY UPDATE `uri-id` = `post-user`.`uri-id`, `uid` = `post-user`.`uid`, `notification-type` = `post-user`.`notification-type`")) {
return Update::FAILED;
}
return Update::SUCCESS; return Update::SUCCESS;
} }