Get rid of the "item" table, enhanced "post" tables
authorMichael <heluecht@pirati.ca>
Sat, 13 Feb 2021 19:56:03 +0000 (19:56 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 13 Feb 2021 19:56:03 +0000 (19:56 +0000)
23 files changed:
database.sql
mod/item.php
src/Content/Widget/TagCloud.php
src/Factory/Api/Mastodon/Status.php
src/Model/Contact.php
src/Model/Item.php
src/Model/Post.php
src/Module/Conversation/Network.php
src/Module/Profile/Status.php
src/Module/Search/Filed.php
src/Module/Search/Index.php
src/Module/Update/Profile.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Feed.php
src/Worker/Delivery.php
src/Worker/Notifier.php
src/Worker/RemoveContact.php
static/dbstructure.config.php
static/dbview.config.php
tests/datasets/api.fixture.php
update.php

index 9d6adbb..52a1d7e 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.03-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1399
+-- DB_UPDATE_VERSION 1400
 -- ------------------------------------------
 
 
@@ -705,7 +705,6 @@ CREATE TABLE IF NOT EXISTS `item` (
        `global` boolean NOT NULL DEFAULT '0' COMMENT '',
        `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
        `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
-       `moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
        `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',
        `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
@@ -717,9 +716,10 @@ CREATE TABLE IF NOT EXISTS `item` (
        `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',
-       `type` varchar(20) COMMENT '',
-       `bookmark` boolean COMMENT '',
        `mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
+       `bookmark` boolean COMMENT 'Deprecated',
+       `type` varchar(20) COMMENT 'Deprecated',
+       `moderated` boolean NOT NULL DEFAULT '0' COMMENT 'Deprecated',
        `resource-id` varchar(32) COMMENT 'Deprecated',
        `uri-hash` varchar(80) COMMENT 'Deprecated',
        `iaid` int unsigned COMMENT 'Deprecated',
@@ -1026,6 +1026,43 @@ CREATE TABLE IF NOT EXISTS `photo` (
        FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage';
 
+--
+-- TABLE post
+--
+CREATE TABLE IF NOT EXISTS `post` (
+       `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+       `parent-uri-id` int unsigned COMMENT 'Id of the item-uri table that contains the parent uri',
+       `thr-parent-id` int unsigned COMMENT 'Id of the item-uri table that contains the thread parent uri',
+       `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation timestamp.',
+       `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last edit (default is created)',
+       `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime',
+       `gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+       `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from',
+       `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
+       `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
+       `causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
+       `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
+       `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
+       `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
+       `global` boolean NOT NULL DEFAULT '0' COMMENT '',
+       `visible` boolean NOT NULL DEFAULT '0' COMMENT '',
+       `deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been marked for deletion',
+        PRIMARY KEY(`uri-id`),
+        INDEX `parent-uri-id` (`parent-uri-id`),
+        INDEX `thr-parent-id` (`thr-parent-id`),
+        INDEX `owner-id` (`owner-id`),
+        INDEX `author-id` (`author-id`),
+        INDEX `causer-id` (`causer-id`),
+        INDEX `vid` (`vid`),
+       FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
+       FOREIGN KEY (`author-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
+       FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
+       FOREIGN KEY (`vid`) REFERENCES `verb` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
+
 --
 -- TABLE post-category
 --
@@ -1160,9 +1197,11 @@ CREATE TABLE IF NOT EXISTS `post-user` (
        `uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
        `protocol` tinyint unsigned COMMENT 'Protocol used to deliver the item for this user',
        `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id',
+       `event-id` int unsigned COMMENT 'Used to link to the event.id',
        `unseen` boolean NOT NULL DEFAULT '1' COMMENT 'post has not been seen',
        `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide the post from the user',
        `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+       `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',
        `psid` int unsigned COMMENT 'ID of the permission set of this post',
         PRIMARY KEY(`id`),
@@ -1171,9 +1210,12 @@ CREATE TABLE IF NOT EXISTS `post-user` (
         INDEX `contact-id` (`contact-id`),
         INDEX `psid` (`psid`),
         INDEX `uid_hidden` (`uid`,`hidden`),
+        INDEX `event-id` (`event-id`),
+        INDEX `uid_wall` (`uid`,`wall`),
        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,
        FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`event-id`) REFERENCES `event` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
        FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific post data';
 
@@ -1486,7 +1528,6 @@ CREATE VIEW `post-view` AS SELECT
        `item`.`thr-parent` AS `thr-parent`,
        `item`.`thr-parent-id` AS `thr-parent-id`,
        `item`.`guid` AS `guid`,
-       `item`.`type` AS `type`,
        `item`.`wall` AS `wall`,
        `item`.`gravity` AS `gravity`,
        `item`.`extid` AS `extid`,
@@ -1498,10 +1539,8 @@ CREATE VIEW `post-view` AS SELECT
        `item`.`post-type` AS `post-type`,
        `item`.`private` AS `private`,
        `item`.`pubmail` AS `pubmail`,
-       `item`.`moderated` AS `moderated`,
        `item`.`visible` AS `visible`,
        `item`.`starred` AS `starred`,
-       `item`.`bookmark` AS `bookmark`,
        `item`.`unseen` AS `unseen`,
        `item`.`deleted` AS `deleted`,
        `item`.`origin` AS `origin`,
@@ -1624,6 +1663,164 @@ CREATE VIEW `post-view` AS SELECT
                        STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`uri-id` = `item`.`parent-uri-id` AND `parent-item`.`uid` = `item`.`uid`
                        STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`;
 
+--
+-- VIEW post-view2
+--
+DROP VIEW IF EXISTS `post-view2`;
+CREATE VIEW `post-view2` AS SELECT 
+       `item`.`id` AS `id`,
+       `item`.`id` AS `item_id`,
+       `post-user`.`id` AS `post-user-id`,
+       `post-user`.`uid` AS `uid`,
+       `item`.`parent` AS `parent`,
+       `item-uri`.`uri` AS `uri`,
+       `post`.`uri-id` AS `uri-id`,
+       `parent-item-uri`.`uri` AS `parent-uri`,
+       `post`.`parent-uri-id` AS `parent-uri-id`,
+       `thr-parent-item-uri`.`uri` AS `thr-parent`,
+       `post`.`thr-parent-id` AS `thr-parent-id`,
+       `item-uri`.`guid` AS `guid`,
+       `post-user`.`wall` AS `wall`,
+       `post`.`gravity` AS `gravity`,
+       `item`.`extid` AS `extid`,
+       `post`.`created` AS `created`,
+       `post`.`edited` AS `edited`,
+       `post-thread`.`commented` AS `commented`,
+       `post`.`received` AS `received`,
+       `post-thread`.`changed` AS `changed`,
+       `post`.`post-type` AS `post-type`,
+       `post`.`private` AS `private`,
+       `post-thread-user`.`pubmail` AS `pubmail`,
+       `post`.`visible` AS `visible`,
+       `post-thread-user`.`starred` AS `starred`,
+       `post-user`.`unseen` AS `unseen`,
+       `post`.`deleted` AS `deleted`,
+       `post-user`.`origin` AS `origin`,
+       `post-thread-user`.`forum_mode` AS `forum_mode`,
+       `post-thread-user`.`mention` AS `mention`,
+       `post`.`global` AS `global`,
+       `post`.`network` AS `network`,
+       `post`.`vid` AS `vid`,
+       `post-user`.`psid` AS `psid`,
+       IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
+       `post-content`.`title` AS `title`,
+       `post-content`.`content-warning` AS `content-warning`,
+       `post-content`.`raw-body` AS `raw-body`,
+       `post-content`.`body` AS `body`,
+       `post-content`.`rendered-hash` AS `rendered-hash`,
+       `post-content`.`rendered-html` AS `rendered-html`,
+       `post-content`.`language` AS `language`,
+       `post-content`.`plink` AS `plink`,
+       `post-content`.`location` AS `location`,
+       `post-content`.`coord` AS `coord`,
+       `post-content`.`app` AS `app`,
+       `post-content`.`object-type` AS `object-type`,
+       `post-content`.`object` AS `object`,
+       `post-content`.`target-type` AS `target-type`,
+       `post-content`.`target` AS `target`,
+       `post-content`.`resource-id` AS `resource-id`,
+       `post-user`.`contact-id` AS `contact-id`,
+       `contact`.`url` AS `contact-link`,
+       `contact`.`addr` AS `contact-addr`,
+       `contact`.`name` AS `contact-name`,
+       `contact`.`nick` AS `contact-nick`,
+       `contact`.`thumb` AS `contact-avatar`,
+       `contact`.`network` AS `contact-network`,
+       `contact`.`blocked` AS `contact-blocked`,
+       `contact`.`hidden` AS `contact-hidden`,
+       `contact`.`readonly` AS `contact-readonly`,
+       `contact`.`archive` AS `contact-archive`,
+       `contact`.`pending` AS `contact-pending`,
+       `contact`.`rel` AS `contact-rel`,
+       `contact`.`uid` AS `contact-uid`,
+       `contact`.`contact-type` AS `contact-contact-type`,
+       IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
+       `contact`.`self` AS `self`,
+       `contact`.`id` AS `cid`,
+       `contact`.`alias` AS `alias`,
+       `contact`.`photo` AS `photo`,
+       `contact`.`name-date` AS `name-date`,
+       `contact`.`uri-date` AS `uri-date`,
+       `contact`.`avatar-date` AS `avatar-date`,
+       `contact`.`thumb` AS `thumb`,
+       `contact`.`dfrn-id` AS `dfrn-id`,
+       `post`.`author-id` AS `author-id`,
+       `author`.`url` AS `author-link`,
+       `author`.`addr` AS `author-addr`,
+       IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`) AS `author-name`,
+       `author`.`nick` AS `author-nick`,
+       IF (`contact`.`url` = `author`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
+       `author`.`network` AS `author-network`,
+       `author`.`blocked` AS `author-blocked`,
+       `author`.`hidden` AS `author-hidden`,
+       `post`.`owner-id` AS `owner-id`,
+       `owner`.`url` AS `owner-link`,
+       `owner`.`addr` AS `owner-addr`,
+       IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`) AS `owner-name`,
+       `owner`.`nick` AS `owner-nick`,
+       IF (`contact`.`url` = `owner`.`url` AND `contact`.`thumb` != '', `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
+       `owner`.`network` AS `owner-network`,
+       `owner`.`blocked` AS `owner-blocked`,
+       `owner`.`hidden` AS `owner-hidden`,
+       `post`.`causer-id` AS `causer-id`,
+       `causer`.`url` AS `causer-link`,
+       `causer`.`addr` AS `causer-addr`,
+       `causer`.`name` AS `causer-name`,
+       `causer`.`nick` AS `causer-nick`,
+       `causer`.`thumb` AS `causer-avatar`,
+       `causer`.`network` AS `causer-network`,
+       `causer`.`blocked` AS `causer-blocked`,
+       `causer`.`hidden` AS `causer-hidden`,
+       `causer`.`contact-type` AS `causer-contact-type`,
+       `post-delivery-data`.`postopts` AS `postopts`,
+       `post-delivery-data`.`inform` AS `inform`,
+       `post-delivery-data`.`queue_count` AS `delivery_queue_count`,
+       `post-delivery-data`.`queue_done` AS `delivery_queue_done`,
+       `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`,
+       IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`,
+       IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
+       IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
+       IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
+       `post-user`.`event-id` AS `event-id`,
+       `event`.`created` AS `event-created`,
+       `event`.`edited` AS `event-edited`,
+       `event`.`start` AS `event-start`,
+       `event`.`finish` AS `event-finish`,
+       `event`.`summary` AS `event-summary`,
+       `event`.`desc` AS `event-desc`,
+       `event`.`location` AS `event-location`,
+       `event`.`type` AS `event-type`,
+       `event`.`nofinish` AS `event-nofinish`,
+       `event`.`adjust` AS `event-adjust`,
+       `event`.`ignore` AS `event-ignore`,
+       `diaspora-interaction`.`interaction` AS `signed_text`,
+       `parent-item-uri`.`guid` AS `parent-guid`,
+       `parent-post`.`network` AS `parent-network`,
+       `parent-post`.`author-id` AS `parent-author-id`,
+       `parent-item-author`.`url` AS `parent-author-link`,
+       `parent-item-author`.`name` AS `parent-author-name`,
+       `parent-item-author`.`network` AS `parent-author-network`
+       FROM `post`
+                       STRAIGHT_JOIN `post-user` ON `post-user`.`uri-id` = `post`.`uri-id`
+                       STRAIGHT_JOIN `post-thread` ON `post-thread`.`uri-id` = `post`.`parent-uri-id`
+                       STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
+                       STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
+                       LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
+                       LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
+                       LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
+                       LEFT JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
+                       LEFT JOIN `contact` AS `author` ON `author`.`id` = `post`.`author-id`
+                       LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post`.`owner-id`
+                       LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post`.`causer-id`
+                       LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
+                       LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
+                       LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post`.`uri-id`
+                       LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post`.`uri-id`
+                       LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post`.`uri-id`
+                       LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
+                       LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
+                       LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-post`.`author-id`;
+
 --
 -- VIEW post-thread-view
 --
@@ -1632,42 +1829,40 @@ CREATE VIEW `post-thread-view` AS SELECT
        `item`.`id` AS `id`,
        `item`.`id` AS `iid`,
        `item`.`id` AS `item_id`,
+       `post-thread-user`.`post-user-id` AS `post-user-id`,
        `post-thread-user`.`uid` AS `uid`,
        `item`.`parent` AS `parent`,
-       `item`.`uri` AS `uri`,
+       `item-uri`.`uri` AS `uri`,
        `post-thread`.`uri-id` AS `uri-id`,
-       `item`.`parent-uri` AS `parent-uri`,
-       `item`.`parent-uri-id` AS `parent-uri-id`,
-       `item`.`thr-parent` AS `thr-parent`,
-       `item`.`thr-parent-id` AS `thr-parent-id`,
-       `item`.`guid` AS `guid`,
-       `item`.`type` AS `type`,
+       `parent-item-uri`.`uri` AS `parent-uri`,
+       `post`.`parent-uri-id` AS `parent-uri-id`,
+       `thr-parent-item-uri`.`uri` AS `thr-parent`,
+       `post`.`thr-parent-id` AS `thr-parent-id`,
+       `item-uri`.`guid` AS `guid`,
        `post-thread-user`.`wall` AS `wall`,
-       `item`.`gravity` AS `gravity`,
+       `post`.`gravity` AS `gravity`,
        `item`.`extid` AS `extid`,
        `post-thread`.`created` AS `created`,
-       `item`.`edited` AS `edited`,
+       `post`.`edited` AS `edited`,
        `post-thread`.`commented` AS `commented`,
        `post-thread`.`received` AS `received`,
        `post-thread`.`changed` AS `changed`,
-       `item`.`post-type` AS `post-type`,
-       `item`.`private` AS `private`,
+       `post`.`post-type` AS `post-type`,
+       `post`.`private` AS `private`,
        `post-thread-user`.`pubmail` AS `pubmail`,
-       `item`.`moderated` AS `moderated`,
        `post-thread-user`.`ignored` AS `ignored`,
-       `item`.`visible` AS `visible`,
+       `post`.`visible` AS `visible`,
        `post-thread-user`.`starred` AS `starred`,
-       `item`.`bookmark` AS `bookmark`,
        `post-thread-user`.`unseen` AS `unseen`,
-       `item`.`deleted` AS `deleted`,
+       `post`.`deleted` AS `deleted`,
        `post-thread-user`.`origin` AS `origin`,
        `post-thread-user`.`forum_mode` AS `forum_mode`,
-       `item`.`mention` AS `mention`,
-       `item`.`global` AS `global`,
+       `post-thread-user`.`mention` AS `mention`,
+       `post`.`global` AS `global`,
        `post-thread`.`network` AS `network`,
-       `item`.`vid` AS `vid`,
+       `post`.`vid` AS `vid`,
        `post-thread-user`.`psid` AS `psid`,
-       IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
+       IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
        `post-content`.`title` AS `title`,
        `post-content`.`content-warning` AS `content-warning`,
        `post-content`.`raw-body` AS `raw-body`,
@@ -1699,7 +1894,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `contact`.`rel` AS `contact-rel`,
        `contact`.`uid` AS `contact-uid`,
        `contact`.`contact-type` AS `contact-contact-type`,
-       IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
+       IF (`post`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
        `contact`.`self` AS `self`,
        `contact`.`id` AS `cid`,
        `contact`.`alias` AS `alias`,
@@ -1727,7 +1922,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `owner`.`network` AS `owner-network`,
        `owner`.`blocked` AS `owner-blocked`,
        `owner`.`hidden` AS `owner-hidden`,
-       `item`.`causer-id` AS `causer-id`,
+       `post-thread`.`causer-id` AS `causer-id`,
        `causer`.`url` AS `causer-link`,
        `causer`.`addr` AS `causer-addr`,
        `causer`.`name` AS `causer-name`,
@@ -1746,7 +1941,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`,
        IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`,
        IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`,
-       `item`.`event-id` AS `event-id`,
+       `post-user`.`event-id` AS `event-id`,
        `event`.`created` AS `event-created`,
        `event`.`edited` AS `event-edited`,
        `event`.`start` AS `event-start`,
@@ -1759,27 +1954,32 @@ CREATE VIEW `post-thread-view` AS SELECT
        `event`.`adjust` AS `event-adjust`,
        `event`.`ignore` AS `event-ignore`,
        `diaspora-interaction`.`interaction` AS `signed_text`,
-       `parent-item`.`guid` AS `parent-guid`,
-       `parent-item`.`network` AS `parent-network`,
-       `parent-item`.`author-id` AS `parent-author-id`,
+       `parent-item-uri`.`guid` AS `parent-guid`,
+       `parent-post`.`network` AS `parent-network`,
+       `parent-post`.`author-id` AS `parent-author-id`,
        `parent-item-author`.`url` AS `parent-author-link`,
        `parent-item-author`.`name` AS `parent-author-name`,
        `parent-item-author`.`network` AS `parent-author-network`
        FROM `post-thread`
                        STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id`
-                       STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
-                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
-                       STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
-                       STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
-                       STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
-                       LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid`
-                       LEFT JOIN `event` ON `event`.`id` = `item`.`event-id`
+                       STRAIGHT_JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
+                       STRAIGHT_JOIN `post` ON `post`.`uri-id` = `post-thread`.`uri-id`
+                       LEFT JOIN `item-uri` ON `item-uri`.`id` = `post`.`uri-id`
+                       LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post`.`thr-parent-id`
+                       LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post`.`parent-uri-id`
+                       LEFT JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
+                       LEFT JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
+                       LEFT JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
+                       LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
+                       LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
+                       LEFT JOIN `verb` ON `verb`.`id` = `post`.`vid`
+                       LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
                        LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
                        LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread`.`uri-id` AND `post-thread-user`.`origin`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
-                       STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`
-                       STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`;
+                       LEFT JOIN `post` AS `parent-post` ON `parent-post`.`uri-id` = `post`.`parent-uri-id`
+                       LEFT JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-post`.`author-id`;
 
 --
 -- VIEW category-view
@@ -1842,7 +2042,7 @@ CREATE VIEW `network-item-view` AS SELECT
                        LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id`
                        LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id`
                        LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id`
-                       WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND NOT `parent-item`.`moderated`
+                       WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted`
                        AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
                        AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
                        AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
@@ -1873,7 +2073,7 @@ CREATE VIEW `network-thread-view` AS SELECT
                        LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id`
                        LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id`
                        LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id`
-                       WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
+                       WHERE `item`.`visible` AND NOT `item`.`deleted`
                        AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
                        AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
                        AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
index 0b04790..0c252cd 100644 (file)
@@ -113,9 +113,9 @@ function item_post(App $a) {
 
        if ($parent_item_id || $thr_parent_uri) {
                if ($parent_item_id) {
-                       $parent_item = Post::selectFirst([], ['id' => $parent_item_id]);
+                       $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item_id]);
                } elseif ($thr_parent_uri) {
-                       $parent_item = Post::selectFirst([], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]);
+                       $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['uri' => $thr_parent_uri, 'uid' => $profile_uid]);
                }
 
                // if this isn't the top-level parent of the conversation, find it
@@ -125,7 +125,7 @@ function item_post(App $a) {
                        $toplevel_item = $parent_item;
 
                        if ($parent_item['gravity'] != GRAVITY_PARENT) {
-                               $toplevel_item = Post::selectFirst([], ['id' => $toplevel_item['parent']]);
+                               $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $toplevel_item['parent']]);
                        }
                }
 
@@ -143,7 +143,7 @@ function item_post(App $a) {
                        $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user());
                        Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]);
                        if ($stored) {
-                               $toplevel_item = Post::selectFirst([], ['id' => $stored]);
+                               $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]);
                        }
                }
 
@@ -462,7 +462,7 @@ function item_post(App $a) {
        /*
         * Next link in any attachment references we find in the post.
         */
-       $match = false;
+       $match = [];
 
        /// @todo these lines should be moved to Model/Attach (Once it exists)
        if (!$preview && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) {
@@ -489,6 +489,7 @@ function item_post(App $a) {
        // embedded bookmark or attachment in post? set bookmark flag
 
        $data = BBCode::getAttachmentData($body);
+       $match = [];
        if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"]))
                && ($posttype != Item::PT_PERSONAL_NOTE)) {
                $posttype = Item::PT_PAGE;
@@ -515,7 +516,7 @@ function item_post(App $a) {
        }
 
        $attachments = '';
-       $match = false;
+       $match = [];
 
        if (preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
                foreach ($match[2] as $mtch) {
@@ -603,7 +604,6 @@ function item_post(App $a) {
 
        $datarray['postopts']      = $postopts;
        $datarray['origin']        = $origin;
-       $datarray['moderated']     = false;
        $datarray['object']        = $object;
 
        /*
index c582c3e..cd170c3 100644 (file)
@@ -104,7 +104,7 @@ class TagCloud
                $tag_stmt = DBA::p("SELECT `name`, COUNT(`name`) AS `total` FROM `tag-search-view`
                        LEFT JOIN `post-view` ON `tag-search-view`.`uri-id` = `post-view`.`uri-id`
                        WHERE `tag-search-view`.`uid` = ?
-                       AND `post-view`.`visible` AND NOT `post-view`.`deleted` AND NOT `post-view`.`moderated`
+                       AND `post-view`.`visible` AND NOT `post-view`.`deleted`
                        $sql_options
                        GROUP BY `name` ORDER BY `total` DESC $limit",
                        $uid
index 6a3212c..6f2bf27 100644 (file)
@@ -61,7 +61,9 @@ class Status extends BaseFactory
         */
        public function createFromUriId(int $uriId, $uid = 0)
        {
-               $item = Post::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]);
+               $fields = ['uri-id', 'uid', 'author-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created',
+                       'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
+               $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => $uid]);
                if (!$item) {
                        throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
                }
index 05c7fb6..5a3f0aa 100644 (file)
@@ -1343,7 +1343,7 @@ class Contact
 
                        $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
                } else {
-                       $items = Post::toArray(Post::selectForUser(local_user(), [], $condition, $params));
+                       $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params));
 
                        $o .= conversation($a, $items, 'contact-posts', $update);
                }
index 0b0885b..6114457 100644 (file)
@@ -83,7 +83,7 @@ class Item
                'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type',
                'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
                'writable', 'self', 'cid', 'alias',
-               'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
+               'event-created', 'event-edited', 'event-start', 'event-finish',
                'event-summary', 'event-desc', 'event-location', 'event-type',
                'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
                'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
@@ -91,34 +91,38 @@ class Item
 
        // Field list that is used to deliver items via the protocols
        const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
-                       'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
-                       'private', 'title', 'body', 'location', 'coord', 'app',
-                       'deleted', 'extid', 'post-type', 'gravity',
+                       'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
+                       'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
+                       'inform', 'deleted', 'extid', 'post-type', 'gravity',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
-                       'author-id', 'author-link', 'owner-link', 'contact-uid',
-                       'signed_text', 'network'];
+                       'author-id', 'author-link', 'owner-id', 'owner-link', 'contact-uid',
+                       'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
+                       'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail', 
+                       'event-created', 'event-edited', 'event-start', 'event-finish',
+                       'event-summary', 'event-desc', 'event-location', 'event-type',
+                       'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
 
        // All fields in the item table
        const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
                        'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
-                       'contact-id', 'type', 'wall', 'gravity', 'extid', 'psid',
+                       'contact-id', 'wall', 'gravity', 'extid', 'psid',
                        'created', 'edited', 'commented', 'received', 'changed', 'verb',
                        'postopts', 'plink', 'resource-id', 'event-id', 'inform',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
-                       'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
+                       'private', 'pubmail', 'visible', 'starred',
                        'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
                        'title', 'content-warning', 'body', 'location', 'coord', 'app',
                        'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
                        'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id'];
 
-       // Item fiels that still are in use
+       // Item fields that still are in use
        const USED_FIELDLIST = ['id', 'parent', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id',
                'thr-parent', 'thr-parent-id', 'created', 'edited', 'commented', 'received', 'changed',
                'gravity', 'network', 'owner-id', 'author-id', 'causer-id', 'vid', 'extid', 'post-type',
-               'global', 'private', 'visible', 'moderated', 'deleted', 'uid', 'contact-id',
+               'global', 'private', 'visible', 'deleted', 'uid', 'contact-id',
                'wall', 'origin', 'pubmail', 'starred', 'unseen', 'mention', 'forum_mode', 'psid',
-               'event-id', 'type', 'bookmark'];
+               'event-id'];
 
        // Legacy item fields that aren't stored any more in the item table
        const LEGACY_FIELDLIST = ['uri-hash', 'iaid', 'icid', 'attach',
@@ -980,6 +984,12 @@ class Item
                        Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
                }
 
+               if (empty($item['event-id'])) {
+                       unset($item['event-id']);
+               }
+
+               Post::insert($item['uri-id'], $item);
+
                if ($item['gravity'] == GRAVITY_PARENT) {
                        Post\Thread::insert($item['uri-id'], $item);
                }
@@ -1010,6 +1020,12 @@ class Item
                        Tag::storeFromBody($item['uri-id'], $item['body']);
                }
 
+               $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid']];
+               if (Post::exists($condition)) {
+                       Logger::notice('Item is already inserted - aborting', $condition);
+                       return 0;
+               }
+
                $id = Post\User::insert($item['uri-id'], $item['uid'], $item);
                if (!$id) {
                        Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]);
@@ -1021,12 +1037,6 @@ class Item
                        Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item);
                }
 
-               $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
-               if (Post::exists($condition)) {
-                       Logger::notice('Item is already inserted - aborting', $condition);
-                       return 0;
-               }
-
                // Remove all fields that aren't part of the item table
                $table_fields = DBStructure::getFieldsForTable('item', $item);
 
@@ -1226,7 +1236,7 @@ class Item
                // Only distribute public items from native networks
                $condition = ['id' => $itemid, 'uid' => 0,
                        'network' => array_merge(Protocol::FEDERATED ,['']),
-                       'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => [self::PUBLIC, self::UNLISTED]];
+                       'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]];
                $item = Post::selectFirst(self::ITEM_FIELDLIST, $condition);
                if (!DBA::isResult($item)) {
                        return;
@@ -1405,7 +1415,7 @@ class Item
         */
        private static function addShadow($itemid)
        {
-               $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri-id'];
+               $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
                $condition = ['id' => $itemid, 'parent' => [0, $itemid]];
                $item = Post::selectFirst($fields, $condition);
 
@@ -1419,7 +1429,7 @@ class Item
                }
 
                // Is it a visible public post?
-               if (!$item["visible"] || $item["deleted"] || $item["moderated"] || ($item["private"] == self::PRIVATE)) {
+               if (!$item["visible"] || $item["deleted"]  || ($item["private"] == self::PRIVATE)) {
                        return;
                }
 
@@ -2154,7 +2164,7 @@ class Item
                $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
                $condition[] = $days;
 
-               $items = Post::select(['resource-id', 'starred', 'type', 'id', 'post-type', 'uid', 'uri-id'], $condition);
+               $items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition);
 
                if (!DBA::isResult($items)) {
                        return;
@@ -2187,9 +2197,9 @@ class Item
                                continue;
                        } elseif (!$expire_starred && intval($item['starred'])) {
                                continue;
-                       } elseif (!$expire_notes && (($item['type'] == 'note') || ($item['post-type'] == self::PT_PERSONAL_NOTE))) {
+                       } elseif (!$expire_notes && ($item['post-type'] == self::PT_PERSONAL_NOTE)) {
                                continue;
-                       } elseif (!$expire_items && ($item['type'] != 'note') && ($item['post-type'] != self::PT_PERSONAL_NOTE)) {
+                       } elseif (!$expire_items && ($item['post-type'] != self::PT_PERSONAL_NOTE)) {
                                continue;
                        }
 
@@ -2203,7 +2213,7 @@ class Item
 
        public static function firstPostDate($uid, $wall = false)
        {
-               $condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
+               $condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true];
                $params = ['order' => ['received' => false]];
                $thread = Post::selectFirst(['received'], $condition, $params);
                if (DBA::isResult($thread)) {
index a3d537b..30515d7 100644 (file)
 
 namespace Friendica\Model;
 
+use BadMethodCallException;
 use Friendica\Core\Logger;
+use Friendica\Core\System;
+use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Protocol\Activity;
 
 class Post
 {
+       /**
+        * Insert a new post entry
+        *
+        * @param integer $uri_id
+        * @param array   $fields
+        * @return int    ID of inserted post
+        * @throws \Exception
+        */
+       public static function insert(int $uri_id, array $data = [])
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               $fields = DBStructure::getFieldsForTable('post', $data);
+
+               // Additionally assign the key fields
+               $fields['uri-id'] = $uri_id;
+
+               if (!DBA::insert('post', $fields, Database::INSERT_IGNORE)) {
+                       return 0;
+               }
+
+               return DBA::lastInsertId();
+       }
+
        /**
         * Fetch a single post row
         *
@@ -189,12 +218,9 @@ class Post
        private static function selectView(string $view, array $selected = [], array $condition = [], $params = [])
        {
                if (empty($selected)) {
-                       $selected = array_merge(['author-addr', 'author-nick', 'owner-addr', 'owner-nick', 'causer-addr', 'causer-nick',
-                               'causer-network', 'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id',
-                               'parent-guid', 'parent-network', 'parent-author-id', 'parent-author-link', 'parent-author-name',
-                               'parent-author-network', 'signed_text', 'language', 'raw-body'], Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
-                       
-                       if ($view != 'post-view') {
+                       $selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
+
+                       if ($view == 'post-thread-view') {
                                $selected = array_merge($selected, ['ignored', 'iid']);
                        }
                }
@@ -216,7 +242,13 @@ class Post
         */
        public static function select(array $selected = [], array $condition = [], $params = [])
        {
-               return self::selectView('post-view', $selected, $condition, $params);
+               $timestamp = microtime(true);
+               $data = self::selectView('post-view', $selected, $condition, $params);
+               
+               $duration = microtime(true) - $timestamp;;
+               if ($duration > 0.1)
+                       Logger::info('Blubb', ['duration' => $duration, 'selected' => $selected, 'condition' => $condition, 'params' => $params, 'callstack' => System::callstack(20)]);
+               return $data;
        }
 
        /**
@@ -253,7 +285,7 @@ class Post
                }
 
                $condition = DBA::mergeConditions($condition,
-                       ["`visible` AND NOT `deleted` AND NOT `moderated`
+                       ["`visible` AND NOT `deleted`
                        AND NOT `author-blocked` AND NOT `owner-blocked`
                        AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked`
                        AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
@@ -299,6 +331,7 @@ class Post
         */
        public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
        {
+               //Logger::info('Blubb', ['uid' => $uid, 'selected' => $selected, 'condition' => $condition, 'params' => $params]);
                return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
        }
 
@@ -434,6 +467,20 @@ class Post
                        $affected = max($affected, DBA::affectedRows());
                }
 
+               $update_fields = DBStructure::getFieldsForTable('post', $fields);
+               if (!empty($update_fields)) {
+                       if (empty($uriids)) {
+                               $rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
+                               $uriids = array_column($rows, 'uri-id');
+                       }
+                       if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) {
+                               DBA::rollback();
+                               Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]);
+                               return false;
+                       }
+                       $affected = max($affected, DBA::affectedRows());
+               }
+
                $update_fields = Post\DeliveryData::extractFields($fields);
                if (!empty($update_fields)) {
                        if (empty($uriids)) {
@@ -450,7 +497,7 @@ class Post
 
                $update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
                if (!empty($update_fields)) {
-                       $rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
+                       $rows = DBA::selectToArray('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]);
                        $uriids = array_column($rows, 'uri-id');
                        if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) {
                                DBA::rollback();
@@ -494,4 +541,20 @@ class Post
                Logger::info('Updated posts', ['rows' => $affected]);
                return $affected;
        }
+
+       /**
+        * Delete a row from the post 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', $conditions, $options);
+       }
 }
index f3a60b4..be87da5 100644 (file)
@@ -434,7 +434,7 @@ class Network extends BaseModule
                }
 
                if (DBA::isResult($items)) {
-                       $parents = array_column($items, 'parent');
+                       $parents = array_column($items, 'parent-uri-id');
                } else {
                        $parents = [];
                }
@@ -446,7 +446,7 @@ class Network extends BaseModule
                        $condition = ['unseen' => true, 'uid' => local_user()];
                        self::setItemsSeenByCondition($condition);
                } elseif (!empty($parents)) {
-                       $condition = ['unseen' => true, 'uid' => local_user(), 'parent' => $parents];
+                       $condition = ['unseen' => true, 'uid' => local_user(), 'parent-uri-id' => $parents];
                        self::setItemsSeenByCondition($condition);
                }
 
index 7684c84..267e3c1 100644 (file)
@@ -189,7 +189,7 @@ class Status extends BaseProfile
                        0, $a->profile['uid']]);
 
                $condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED,
-                       'visible' => true, 'deleted' => false, 'moderated' => false]);
+                       'visible' => true, 'deleted' => false]);
 
                $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
                $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
index 6705542..f14c29a 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Content\Widget;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\Post\Category;
 use Friendica\Module\BaseSearch;
@@ -69,7 +70,7 @@ class Filed extends BaseSearch
                $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
                $item_params = ['order' => ['uri-id' => true]];
 
-               $items = Post::toArray(Post::selectForUser(local_user(), [], $item_condition, $item_params));
+               $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
 
                $o .= conversation(DI::app(), $items, 'filed', false, false, '', local_user());
 
index 78f2008..e0050f4 100644 (file)
@@ -172,7 +172,7 @@ class Index extends BaseSearch
 
                if (!empty($uriids)) {
                        $params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
-                       $items = Post::toArray(Post::selectForUser(local_user(), [], ['uri-id' => $uriids], $params));
+                       $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, ['uri-id' => $uriids], $params));
                }
 
                if (empty($items)) {
index f660d96..93a3752 100644 (file)
@@ -81,7 +81,7 @@ class Profile extends BaseModule
                        "SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, `created` FROM `post-view`
                                WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
                                AND `visible` AND (NOT `deleted` OR `gravity` = ?)
-                               AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra
+                               AND `wall` $sql_extra4 $sql_extra
                        ORDER BY `received` DESC",
                        $a->profile['uid'],
                        GRAVITY_ACTIVITY
index f281c7e..ba2b9e7 100644 (file)
@@ -868,8 +868,9 @@ class Processor
                }
 
                $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
-               if (Post::exists(['uri' => $replyto])) {
-                       Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
+               $uriid = ItemURI::getIdByURI($replyto);
+               if (Post::exists(['uri-id' => $uriid])) {
+                       Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'uri-id' => $uriid, 'replyto' => $replyto]);
                        return true;
                }
 
index f48135f..eef82f1 100644 (file)
@@ -930,7 +930,7 @@ class Receiver
                        } else {
                                Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
 
-                               $item = Post::selectFirst([], ['uri' => $object_id]);
+                               $item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri' => $object_id]);
                                if (!DBA::isResult($item)) {
                                        Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
                                        return false;
index 401d05c..62bdb7c 100644 (file)
@@ -258,7 +258,7 @@ class Transmitter
                $condition = array_merge($condition,
                        ['author-id' => $public_contact,
                        'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
-                       'deleted' => false, 'visible' => true, 'moderated' => false]);
+                       'deleted' => false, 'visible' => true]);
 
                $count = Post::count($condition);
 
@@ -1045,19 +1045,19 @@ class Transmitter
        public static function createActivityFromItem(int $item_id, bool $object_mode = false)
        {
                Logger::info('Fetching activity', ['item' => $item_id]);
-               $item = Post::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
+               $item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
                if (!DBA::isResult($item)) {
                        return false;
                }
 
                // In case of a forum post ensure to return the original post if author and forum are on the same machine
-               if (!empty($item['forum_mode'])) {
+               if (($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode'])) {
                        $author = Contact::getById($item['author-id'], ['nurl']);
                        if (!empty($author['nurl'])) {
                                $self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]);
                                if (!empty($self['uid'])) {
-                                       $forum_item = Post::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
-                                       if (DBA::isResult($item)) {
+                                       $forum_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
+                                       if (DBA::isResult($forum_item)) {
                                                $item = $forum_item; 
                                        }
                                }
@@ -1645,7 +1645,7 @@ class Transmitter
                        return [];
                }
 
-               $reshared_item = Post::selectFirst([], ['guid' => $reshared['guid']]);
+               $reshared_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['guid' => $reshared['guid']]);
                if (!DBA::isResult($reshared_item)) {
                        return [];
                }
index 027efb2..196d7c0 100644 (file)
@@ -887,9 +887,9 @@ class Feed
                $params = ['order' => ['received' => true], 'limit' => $max_items];
 
                if ($filter === 'posts') {
-                       $ret = Post::selectThread([], $condition, $params);
+                       $ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params);
                } else {
-                       $ret = Post::select([], $condition, $params);
+                       $ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
                }
 
                $items = Post::toArray($ret);
@@ -1041,7 +1041,7 @@ class Feed
 
                $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => Protocol::FEDERATED];
-               $repeated_item = Post::selectFirst([], $condition);
+               $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
                if (!DBA::isResult($repeated_item)) {
                        return false;
                }
index 3c6b877..d5a3e8f 100644 (file)
@@ -35,6 +35,7 @@ use Friendica\Util\Network;
 use Friendica\Core\Worker;
 use Friendica\Model\Conversation;
 use Friendica\Model\FContact;
+use Friendica\Model\Item;
 use Friendica\Protocol\Relay;
 
 class Delivery
@@ -80,9 +81,9 @@ class Delivery
                        }
                        $parent_id = intval($item['parent']);
 
-                       $condition = ['id' => [$target_id, $parent_id], 'visible' => true, 'moderated' => false];
+                       $condition = ['id' => [$target_id, $parent_id], 'visible' => true];
                        $params = ['order' => ['id']];
-                       $itemdata = Model\Post::select([], $condition, $params);
+                       $itemdata = Model\Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
 
                        while ($item = Model\Post::fetch($itemdata)) {
                                if ($item['verb'] == Activity::ANNOUNCE) {
index 4044e37..312dcc0 100644 (file)
@@ -100,8 +100,8 @@ class Notifier
                        $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition);
                } else {
                        // find ancestors
-                       $condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
-                       $target_item = Post::selectFirst([], $condition);
+                       $condition = ['id' => $target_id, 'visible' => true];
+                       $target_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
 
                        if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
                                Logger::info('No target item', ['cmd' => $cmd, 'target' => $target_id]);
@@ -117,9 +117,9 @@ class Notifier
                                return;
                        }
 
-                       $condition = ['parent' => $target_item['parent'], 'visible' => true, 'moderated' => false];
+                       $condition = ['parent' => $target_item['parent'], 'visible' => true];
                        $params = ['order' => ['id']];
-                       $items_stmt = Post::select([], $condition, $params);
+                       $items_stmt = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
                        if (!DBA::isResult($items_stmt)) {
                                Logger::info('No item found', ['cmd' => $cmd, 'target' => $target_id]);
                                return;
@@ -792,6 +792,6 @@ class Notifier
         */
        public static function isForumPost(array $item)
        {
-               return !empty($item['forum_mode']);
+               return ($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode']);
        }
 }
index e1e6cbc..6d48dd9 100644 (file)
@@ -47,13 +47,14 @@ class RemoveContact {
                        $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
                }
                do {
-                       $items = Post::select(['id', 'guid', 'uri-id', 'uid'], $condition, ['limit' => 100]);
+                       $items = Post::select(['id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
                        while ($item = Post::fetch($items)) {
-                               Logger::info('Delete removed contact item', ['id' => $item['id'], 'guid' => $item['guid']]);
+                               Logger::info('Delete removed contact item', ['id' => $item['id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
                                DBA::delete('item', ['id' => $item['id']]);
-                               Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
+                               Post::delete(['uri-id' => $item['uri-id']]);
+                               Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]);
                                Post\Thread::delete(['uri-id' => $item['uri-id']]);
-                               Post\ThreadUser::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
+                               Post\User::delete(['id' => $item['post-user-id']]);
                        }
                        DBA::close($items);
                } while (Post::exists($condition));
index 3002f6a..b91cd8a 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1399);
+       define('DB_UPDATE_VERSION', 1400);
 }
 
 return [
@@ -771,7 +771,6 @@ return [
                        "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
                        "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"],
                        // 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"],
@@ -787,10 +786,11 @@ return [
                        // 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
+                       // Deprecated fields. Will not be transferred to the "post" table
+                       "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
+                       "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
+                       "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Deprecated"],
                        "resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
                        "uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
                        "iaid" => ["type" => "int unsigned", "comment" => "Deprecated"],
@@ -1086,6 +1086,38 @@ return [
                        "resource-id" => ["resource-id"],
                ]
        ],
+       "post" => [
+               "comment" => "Structure for all posts",
+               "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"],
+                       "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the parent uri"],
+                       "thr-parent-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the thread parent uri"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation timestamp."],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last edit (default is created)"],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"],
+                       "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
+                       "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
+                       "causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
+                       "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
+                       "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been marked for deletion"]
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uri-id"],
+                       "parent-uri-id" => ["parent-uri-id"],
+                       "thr-parent-id" => ["thr-parent-id"],
+                       "owner-id" => ["owner-id"],
+                       "author-id" => ["author-id"],
+                       "causer-id" => ["causer-id"],
+                       "vid" => ["vid"],
+                       "received" => ["received"],
+               ]
+       ],
        "post-category" => [
                "comment" => "post relation to categories",
                "fields" => [
@@ -1209,12 +1241,30 @@ return [
                "fields" => [
                        "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"],
                        "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"],
+                       "parent-uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the parent uri"],
+                       "thr-parent-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table that contains the thread parent uri"],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation timestamp."],
+                       "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date of last edit (default is created)"],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "datetime"],
+                       "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
+                       "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
+                       "causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
+                       "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
+                       "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                       "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been marked for deletion"],
                        "uid" => ["type" => "mediumint unsigned", "not null" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
                        "protocol" => ["type" => "tinyint unsigned", "comment" => "Protocol used to deliver the item for this user"],
                        "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"],
+                       "event-id" => ["type" => "int unsigned", "foreign" => ["event" => "id"], "comment" => "Used to link to the event.id"],
                        "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "post has not been seen"],
                        "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide the post from the user"],
                        "notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                       "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"],
                        "psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"],
                ],
@@ -1225,12 +1275,36 @@ return [
                        "contact-id" => ["contact-id"],
                        "psid" => ["psid"],
                        "uid_hidden" => ["uid", "hidden"],
+                       "event-id" => ["event-id"],
+                       "uid_wall" => ["uid", "wall"],
+                       "parent-uri-id" => ["parent-uri-id"],
+                       "thr-parent-id" => ["thr-parent-id"],
+                       "owner-id" => ["owner-id"],
+                       "author-id" => ["author-id"],
+                       "causer-id" => ["causer-id"],
+                       "vid" => ["vid"],
+                       "uid_received" => ["uid", "received"],
+                       "uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
+                       "uid_network_received" => ["uid", "network", "received"],
+                       "uid_contactid_received" => ["uid", "contact-id", "received"],
+                       "authorid_received" => ["author-id", "received"],
+                       "uid_unseen_wall" => ["uid", "unseen", "wall"],
+                       "uid_eventid" => ["uid", "event-id"],
+                       "psid_wall" => ["psid", "wall"],
                ],
        ],
        "post-thread-user" => [
                "comment" => "Thread related data per user",
                "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"],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"],
+                       "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item author"],
+                       "causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
+                       "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+                       "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "changed" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
+                       "commented" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
                        "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
                        "pinned" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The thread is pinned on the profile page"],
                        "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
@@ -1254,6 +1328,24 @@ return [
                        "contact-id" => ["contact-id"],
                        "psid" => ["psid"],
                        "post-user-id" => ["post-user-id"],
+                       "owner-id" => ["owner-id"],
+                       "causer-id" => ["causer-id"],
+                       "uid_received" => ["uid", "received"],
+                       "uid_commented" => ["uid", "commented"],
+                       "uid_changed" => ["uid", "changed"],
+                       "uid_contact-id" => ["uid", "contact-id", "received"],
+                       "uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
+                       "uid_network_received" => ["uid", "network", "received"],
+                       "uid_network_commented" => ["uid", "network", "commented"],
+                       "uid_contact-id_received" => ["uid", "contact-id", "received"],
+                       "author-id_received" => ["author-id", "received"],
+                       "uid_wall_changed" => ["uid", "wall", "changed"],
+                       "uid_unseen_wall" => ["uid", "unseen", "wall"],
+                       "mention_uid" => ["mention", "uid"],
+                       "psid_wall" => ["psid", "wall"],
+                       "received" => ["received"],
+                       "commented" => ["commented"],
+                       "changed" => ["changed"],
                ]
        ],
        "post-user-notification" => [
index 6b48a95..cd1e81d 100644 (file)
                        "id" => ["item", "id"],
                        "item_id" => ["item", "id"],
                        "post-user-id" => ["post-user", "id"],
-                       "uid" => ["item", "uid"],
+                       "uid" => ["post-user", "uid"],
                        "parent" => ["item", "parent"],
-                       "uri" => ["item", "uri"],
-                       "uri-id" => ["item", "uri-id"],
-                       "parent-uri" => ["item", "parent-uri"],
-                       "parent-uri-id" => ["item", "parent-uri-id"],
-                       "thr-parent" => ["item", "thr-parent"],
-                       "thr-parent-id" => ["item", "thr-parent-id"],
-                       "guid" => ["item", "guid"],
-                       "type" => ["item", "type"],
-                       "wall" => ["item", "wall"],
-                       "gravity" => ["item", "gravity"],
+                       "uri" => ["item-uri", "uri"],
+                       "uri-id" => ["post-user", "uri-id"],
+                       "parent-uri" => ["parent-item-uri", "uri"],
+                       "parent-uri-id" => ["post-user", "parent-uri-id"],
+                       "thr-parent" => ["thr-parent-item-uri", "uri"],
+                       "thr-parent-id" => ["post-user", "thr-parent-id"],
+                       "guid" => ["item-uri", "guid"],
+                       "wall" => ["post-user", "wall"],
+                       "gravity" => ["post-user", "gravity"],
                        "extid" => ["item", "extid"],
-                       "created" => ["item", "created"],
-                       "edited" => ["item", "edited"],
-                       "commented" => ["item", "commented"],
-                       "received" => ["item", "received"],
-                       "changed" => ["item", "changed"],
-                       "post-type" => ["item", "post-type"],
-                       "private" => ["item", "private"],
-                       "pubmail" => ["item", "pubmail"],
-                       "moderated" => ["item", "moderated"],
-                       "visible" => ["item", "visible"],
-                       "starred" => ["item", "starred"],
-                       "bookmark" => ["item", "bookmark"],
-                       "unseen" => ["item", "unseen"],
-                       "deleted" => ["item", "deleted"],
-                       "origin" => ["item", "origin"],
-                       "forum_mode" => ["item", "forum_mode"],
-                       "mention" => ["item", "mention"],
-                       "global" => ["item", "global"],
-                       "network" => ["item", "network"],
-                       "vid" => ["item", "vid"],
-                       "psid" => ["item", "psid"],
-                       "verb" => "IF (`item`.`vid` IS NULL, '', `verb`.`name`)",
+                       "created" => ["post-user", "created"],
+                       "edited" => ["post-user", "edited"],
+                       "commented" => ["post-thread-user", "commented"],
+                       "received" => ["post-user", "received"],
+                       "changed" => ["post-thread-user", "changed"],
+                       "post-type" => ["post-user", "post-type"],
+                       "private" => ["post-user", "private"],
+                       "pubmail" => ["post-thread-user", "pubmail"],
+                       "visible" => ["post-user", "visible"],
+                       "starred" => ["post-thread-user", "starred"],
+                       "unseen" => ["post-user", "unseen"],
+                       "deleted" => ["post-user", "deleted"],
+                       "origin" => ["post-user", "origin"],
+                       "forum_mode" => ["post-thread-user", "forum_mode"],
+                       "mention" => ["post-thread-user", "mention"],
+                       "global" => ["post-user", "global"],
+                       "network" => ["post-user", "network"],
+                       "vid" => ["post-user", "vid"],
+                       "psid" => ["post-user", "psid"],
+                       "verb" => "IF (`post-user`.`vid` IS NULL, '', `verb`.`name`)",
                        "title" => ["post-content", "title"],
                        "content-warning" => ["post-content", "content-warning"],
                        "raw-body" => ["post-content", "raw-body"],
@@ -93,7 +90,7 @@
                        "target-type" => ["post-content", "target-type"],
                        "target" => ["post-content", "target"],
                        "resource-id" => ["post-content", "resource-id"],
-                       "contact-id" => ["item", "contact-id"],
+                       "contact-id" => ["post-user", "contact-id"],
                        "contact-link" => ["contact", "url"],
                        "contact-addr" => ["contact", "addr"],
                        "contact-name" => ["contact", "name"],
                        "contact-rel" => ["contact", "rel"],
                        "contact-uid" => ["contact", "uid"],
                        "contact-contact-type" => ["contact", "contact-type"],
-                       "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)",
+                       "writable" => "IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)",
                        "self" => ["contact", "self"],
                        "cid" => ["contact", "id"],
                        "alias" => ["contact", "alias"],
                        "avatar-date" => ["contact", "avatar-date"],
                        "thumb" => ["contact", "thumb"],
                        "dfrn-id" => ["contact", "dfrn-id"],
-                       "author-id" => ["item", "author-id"],
+                       "author-id" => ["post-user", "author-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)",
                        "author-network" => ["author", "network"],
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
-                       "owner-id" => ["item", "owner-id"],
+                       "owner-id" => ["post-user", "owner-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)",
                        "owner-network" => ["owner", "network"],
                        "owner-blocked" => ["owner", "blocked"],
                        "owner-hidden" => ["owner", "hidden"],
-                       "causer-id" => ["item", "causer-id"],
+                       "causer-id" => ["post-user", "causer-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "delivery_queue_count" => ["post-delivery-data", "queue_count"],
                        "delivery_queue_done" => ["post-delivery-data", "queue_done"],
                        "delivery_queue_failed" => ["post-delivery-data", "queue_failed"],
-                       "allow_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`)",
-                       "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)",
-                       "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)",
-                       "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)",
-                       "event-id" => ["item", "event-id"],
+                       "allow_cid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_cid`)",
+                       "allow_gid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`)",
+                       "deny_cid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`)",
+                       "deny_gid" => "IF (`post-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`)",
+                       "event-id" => ["post-user", "event-id"],
                        "event-created" => ["event", "created"],
                        "event-edited" => ["event", "edited"],
                        "event-start" => ["event", "start"],
                        "event-adjust" => ["event", "adjust"],
                        "event-ignore" => ["event", "ignore"],
                        "signed_text" => ["diaspora-interaction", "interaction"],
-                       "parent-guid" => ["parent-item", "guid"],
-                       "parent-network" => ["parent-item", "network"],
-                       "parent-author-id" => ["parent-item", "author-id"],
-                       "parent-author-link" => ["parent-item-author", "url"],  
-                       "parent-author-name" => ["parent-item-author", "name"],
-                       "parent-author-network" => ["parent-item-author", "network"], 
+                       "parent-guid" => ["parent-item-uri", "guid"],
+                       "parent-network" => ["parent-post", "network"],
+                       "parent-author-id" => ["parent-post", "author-id"],
+                       "parent-author-link" => ["parent-post-author", "url"],  
+                       "parent-author-name" => ["parent-post-author", "name"],
+                       "parent-author-network" => ["parent-post-author", "network"], 
                ],
-               "query" => "FROM `item`
-                       LEFT JOIN `post-user` ON `post-user`.`uri-id` = `item`.`uri-id` AND `post-user`.`uid` = `item`.`uid`
-                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                       STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id`
-                       STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id`
-                       STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id`
-                       LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid`
-                       LEFT JOIN `event` ON `event`.`id` = `item`.`event-id`
-                       LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id`
-                       LEFT JOIN `post-content` ON `post-content`.`uri-id` = `item`.`uri-id`
-                       LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin`
-                       LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`
-                       STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`uri-id` = `item`.`parent-uri-id` AND `parent-item`.`uid` = `item`.`uid`
-                       STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`"
+               "query" => "FROM `post-user`
+                       STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
+                       LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
+                       INNER JOIN `contact` ON `contact`.`id` = `post-user`.`contact-id`
+                       INNER JOIN `contact` AS `author` ON `author`.`id` = `post-user`.`author-id`
+                       INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-user`.`owner-id`
+                       INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-user`.`causer-id`
+                       INNER JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
+                       INNER JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
+                       INNER JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
+                       INNER JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
+                       LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
+                       LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-user`.`uri-id`
+                       LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-user`.`uri-id`
+                       LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-user`.`uri-id`
+                       LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-user`.`psid`
+                       LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
+                       INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
        ],
        "post-thread-view" => [
                "fields" => [
                        "item_id" => ["item", "id"],
                        "uid" => ["post-thread-user", "uid"],
                        "parent" => ["item", "parent"],
-                       "uri" => ["item", "uri"],
-                       "uri-id" => ["post-thread", "uri-id"],
-                       "parent-uri" => ["item", "parent-uri"],
-                       "parent-uri-id" => ["item", "parent-uri-id"],
-                       "thr-parent" => ["item", "thr-parent"],
-                       "thr-parent-id" => ["item", "thr-parent-id"],
-                       "guid" => ["item", "guid"],
-                       "type" => ["item", "type"],
+                       "uri" => ["item-uri", "uri"],
+                       "uri-id" => ["post-thread-user", "uri-id"],
+                       "parent-uri" => ["parent-item-uri", "uri"],
+                       "parent-uri-id" => ["post-user", "parent-uri-id"],
+                       "thr-parent" => ["thr-parent-item-uri", "uri"],
+                       "thr-parent-id" => ["post-user", "thr-parent-id"],
+                       "guid" => ["item-uri", "guid"],
                        "wall" => ["post-thread-user", "wall"],
-                       "gravity" => ["item", "gravity"],
+                       "gravity" => ["post-user", "gravity"],
                        "extid" => ["item", "extid"],
-                       "created" => ["post-thread", "created"],
-                       "edited" => ["item", "edited"],
-                       "commented" => ["post-thread", "commented"],
-                       "received" => ["post-thread", "received"],
-                       "changed" => ["post-thread", "changed"],
-                       "post-type" => ["item", "post-type"],
-                       "private" => ["item", "private"],
+                       "created" => ["post-thread-user", "created"],
+                       "edited" => ["post-user", "edited"],
+                       "commented" => ["post-thread-user", "commented"],
+                       "received" => ["post-thread-user", "received"],
+                       "changed" => ["post-thread-user", "changed"],
+                       "post-type" => ["post-user", "post-type"],
+                       "private" => ["post-user", "private"],
                        "pubmail" => ["post-thread-user", "pubmail"],
-                       "moderated" => ["item", "moderated"],
                        "ignored" => ["post-thread-user", "ignored"],
-                       "visible" => ["item", "visible"],
+                       "visible" => ["post-user", "visible"],
                        "starred" => ["post-thread-user", "starred"],
-                       "bookmark" => ["item", "bookmark"],
                        "unseen" => ["post-thread-user", "unseen"],
-                       "deleted" => ["item", "deleted"],
+                       "deleted" => ["post-user", "deleted"],
                        "origin" => ["post-thread-user", "origin"],
                        "forum_mode" => ["post-thread-user", "forum_mode"],
-                       "mention" => ["item", "mention"],
-                       "global" => ["item", "global"],
-                       "network" => ["post-thread", "network"],
-                       "vid" => ["item", "vid"],
+                       "mention" => ["post-thread-user", "mention"],
+                       "global" => ["post-user", "global"],
+                       "network" => ["post-thread-user", "network"],
+                       "vid" => ["post-user", "vid"],
                        "psid" => ["post-thread-user", "psid"],
-                       "verb" => "IF (`item`.`vid` IS NULL, '', `verb`.`name`)",
+                       "verb" => "IF (`post-user`.`vid` IS NULL, '', `verb`.`name`)",
                        "title" => ["post-content", "title"],
                        "content-warning" => ["post-content", "content-warning"],
                        "raw-body" => ["post-content", "raw-body"],
                        "contact-rel" => ["contact", "rel"],
                        "contact-uid" => ["contact", "uid"],
                        "contact-contact-type" => ["contact", "contact-type"],
-                       "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)",
+                       "writable" => "IF (`post-user`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)",
                        "self" => ["contact", "self"],
                        "cid" => ["contact", "id"],
                        "alias" => ["contact", "alias"],
                        "avatar-date" => ["contact", "avatar-date"],
                        "thumb" => ["contact", "thumb"],
                        "dfrn-id" => ["contact", "dfrn-id"],
-                       "author-id" => ["post-thread", "author-id"],
+                       "author-id" => ["post-thread-user", "author-id"],
                        "author-link" => ["author", "url"],
                        "author-addr" => ["author", "addr"],
                        "author-name" => "IF (`contact`.`url` = `author`.`url` AND `contact`.`name` != '', `contact`.`name`, `author`.`name`)",
                        "author-network" => ["author", "network"],
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
-                       "owner-id" => ["post-thread", "owner-id"],
+                       "owner-id" => ["post-thread-user", "owner-id"],
                        "owner-link" => ["owner", "url"],
                        "owner-addr" => ["owner", "addr"],
                        "owner-name" => "IF (`contact`.`url` = `owner`.`url` AND `contact`.`name` != '', `contact`.`name`, `owner`.`name`)",
                        "owner-network" => ["owner", "network"],
                        "owner-blocked" => ["owner", "blocked"],
                        "owner-hidden" => ["owner", "hidden"],
-                       "causer-id" => ["item", "causer-id"],
+                       "causer-id" => ["post-thread-user", "causer-id"],
                        "causer-link" => ["causer", "url"],
                        "causer-addr" => ["causer", "addr"],
                        "causer-name" => ["causer", "name"],
                        "allow_gid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`allow_gid`)",
                        "deny_cid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_cid`)",
                        "deny_gid" => "IF (`post-thread-user`.`psid` IS NULL, '', `permissionset`.`deny_gid`)",
-                       "event-id" => ["item", "event-id"],
+                       "event-id" => ["post-user", "event-id"],
                        "event-created" => ["event", "created"],
                        "event-edited" => ["event", "edited"],
                        "event-start" => ["event", "start"],
                        "event-adjust" => ["event", "adjust"],
                        "event-ignore" => ["event", "ignore"],
                        "signed_text" => ["diaspora-interaction", "interaction"],
-                       "parent-guid" => ["parent-item", "guid"],
-                       "parent-network" => ["parent-item", "network"],
-                       "parent-author-id" => ["parent-item", "author-id"],
-                       "parent-author-link" => ["parent-item-author", "url"],  
-                       "parent-author-name" => ["parent-item-author", "name"],
-                       "parent-author-network" => ["parent-item-author", "network"], 
+                       "parent-guid" => ["parent-item-uri", "guid"],
+                       "parent-network" => ["parent-post", "network"],
+                       "parent-author-id" => ["parent-post", "author-id"],
+                       "parent-author-link" => ["parent-post-author", "url"],  
+                       "parent-author-name" => ["parent-post-author", "name"],
+                       "parent-author-network" => ["parent-post-author", "network"], 
                ],
-               "query" => "FROM `post-thread`
-                       STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id`
-                       STRAIGHT_JOIN `item` ON `item`.`uri-id` = `post-thread`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
-                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
-                       STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `post-thread`.`author-id`
-                       STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread`.`owner-id`
-                       STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread`.`causer-id`
-                       LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid`
-                       LEFT JOIN `event` ON `event`.`id` = `item`.`event-id`
-                       LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread`.`uri-id`
-                       LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread`.`uri-id`
-                       LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread`.`uri-id` AND `post-thread-user`.`origin`
+               "query" => "FROM `post-thread-user`
+                       INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
+                       INNER JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
+                       INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
+                       INNER JOIN `contact` AS `author` ON `author`.`id` = `post-thread-user`.`author-id`
+                       INNER JOIN `contact` AS `owner` ON `owner`.`id` = `post-thread-user`.`owner-id`
+                       INNER JOIN `contact` AS `causer` ON `causer`.`id` = `post-thread-user`.`causer-id`
+                       LEFT JOIN `item-uri` ON `item-uri`.`id` = `post-user`.`uri-id`
+                       LEFT JOIN `item-uri` AS `thr-parent-item-uri` ON `thr-parent-item-uri`.`id` = `post-user`.`thr-parent-id`
+                       LEFT JOIN `item-uri` AS `parent-item-uri` ON `parent-item-uri`.`id` = `post-user`.`parent-uri-id`
+                       LEFT JOIN `verb` ON `verb`.`id` = `post-user`.`vid`
+                       LEFT JOIN `event` ON `event`.`id` = `post-user`.`event-id`
+                       LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `post-thread-user`.`uri-id`
+                       LEFT JOIN `post-content` ON `post-content`.`uri-id` = `post-thread-user`.`uri-id`
+                       LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `post-thread-user`.`uri-id` AND `post-thread-user`.`origin`
                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `post-thread-user`.`psid`
-                       STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`
-                       STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`"
+                       LEFT JOIN `post-user` AS `parent-post` ON `parent-post`.`uri-id` = `post-user`.`parent-uri-id` AND `parent-post`.`uid` = `post-user`.`uid`
+                       INNER JOIN `contact` AS `parent-post-author` ON `parent-post-author`.`id` = `parent-post`.`author-id`"
        ],
        "category-view" => [
                "fields" => [
                        LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `parent-item`.`uid` AND `author`.`cid` = `parent-item`.`author-id`
                        LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `parent-item`.`uid` AND `owner`.`cid` = `parent-item`.`owner-id`
                        LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `parent-item`.`owner-id`
-                       WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted` AND NOT `parent-item`.`moderated`
+                       WHERE `parent-item`.`visible` AND NOT `parent-item`.`deleted`
                        AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
                        AND (`post-user`.`hidden` IS NULL OR NOT `post-user`.`hidden`)
                        AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
                        LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread`.`author-id`
                        LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread`.`owner-id`
                        LEFT JOIN `contact` AS `ownercontact` ON `ownercontact`.`id` = `post-thread`.`owner-id`
-                       WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
+                       WHERE `item`.`visible` AND NOT `item`.`deleted`
                        AND (NOT `contact`.`readonly` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`)
                        AND (`post-thread-user`.`hidden` IS NULL OR NOT `post-thread-user`.`hidden`)
                        AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
index 175f266..4f85fe0 100644 (file)
@@ -23,6 +23,7 @@ use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Notification;
+use Friendica\Model\Verb;
 
 return [
        // Empty these tables
@@ -373,6 +374,86 @@ return [
                        'post-user-id' => 12,
                ],
        ],
+       'post'    => [
+               [
+                       'uri-id'        => 1,
+                       'parent-uri-id' => 1,
+                       'thr-parent-id' => 1,
+                       'gravity'       => GRAVITY_PARENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 42,
+                       'causer-id'     => 42,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+               [
+                       'uri-id'        => 2,
+                       'parent-uri-id' => 1,
+                       'thr-parent-id' => 1,
+                       'gravity'       => GRAVITY_COMMENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 42,
+                       'causer-id'     => 42,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+               [
+                       'uri-id'        => 3,
+                       'parent-uri-id' => 3,
+                       'thr-parent-id' => 3,
+                       'gravity'       => GRAVITY_PARENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 43,
+                       'causer-id'     => 43,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+               [
+                       'uri-id'        => 4,
+                       'parent-uri-id' => 1,
+                       'thr-parent-id' => 1,
+                       'gravity'       => GRAVITY_COMMENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 44,
+                       'causer-id'     => 44,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+               [
+                       'uri-id'        => 5,
+                       'parent-uri-id' => 1,
+                       'thr-parent-id' => 1,
+                       'gravity'       => GRAVITY_COMMENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 42,
+                       'causer-id'     => 42,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+               [
+                       'uri-id'        => 6,
+                       'parent-uri-id' => 6,
+                       'thr-parent-id' => 6,
+                       'gravity'       => GRAVITY_PARENT,
+                       'network'       => Protocol::DFRN,
+                       'owner-id'      => 42,
+                       'author-id'     => 44,
+                       'causer-id'     => 44,
+                       'vid'           => Verb::getID('http://activitystrea.ms/schema/1.0/post'),
+                       'private'       => Item::PUBLIC,
+                       'visible'       => 1,
+               ],
+       ],
        'item'    => [
                [
                        'id'          => 1,
index 9b5c7ac..444189c 100644 (file)
@@ -768,5 +768,53 @@ function update_1399()
                        return Update::FAILED;
        }
 
+       return Update::SUCCESS;
+}
+
+function update_1400()
+{
+/*     
+       if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`,
+               `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`)
+               SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, 
+                       `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted` FROM `item`")) {
+                       return Update::FAILED;
+       }
+
+       if (!DBA::e("UPDATE `post` INNER JOIN `item` ON `item`.`uri-id` = `post`.`uri-id` AND `item`.`uid` = 0
+               SET `post`.`global` = true")) {
+               return Update::FAILED;
+
+// --------------------------------------
+       if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
+               INNER JOIN `event` ON `item`.`event-id` = `event`.`id` AND `event`.`id` != 0
+               SET `post-user`.`event-id` = `item`.`event-id`")) {
+               return Update::FAILED;
+       }
+
+       if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
+               SET `post-user`.`wall` = `item`.`wall`, `post-user`.`parent-uri-id` = `item`.`parent-uri-id`,
+               `post-user`.`thr-parent-id` = `item`.`thr-parent-id`,
+               `post-user`.`created` = `item`.`created`, `post-user`.`edited` = `item`.`edited`,
+               `post-user`.`received` = `item`.`received`, `post-user`.`gravity` = `item`.`gravity`,
+               `post-user`.`network` = `item`.`network`, `post-user`.`owner-id` = `item`.`owner-id`,
+               `post-user`.`author-id` = `item`.`author-id`, `post-user`.`causer-id` = `item`.`causer-id`,
+               `post-user`.`post-type` = `item`.`post-type`, `post-user`.`vid` = `item`.`vid`,
+               `post-user`.`private` = `item`.`private`, `post-user`.`global` = `item`.`global`,
+               `post-user`.`visible` = `item`.`visible`, `post-user`.`deleted` = `item`.`deleted`")) {
+               return Update::FAILED;
+       }
+
+       */
+
+       if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-thread` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id`
+               SET `post-thread-user`.`owner-id` = `post-thread`.`owner-id`, `post-thread-user`.`author-id` = `post-thread`.`author-id`,
+               `post-thread-user`.`causer-id` = `post-thread`.`causer-id`, `post-thread-user`.`network` = `post-thread`.`network`,
+               `post-thread-user`.`created` = `post-thread`.`created`, `post-thread-user`.`received` = `post-thread`.`received`,
+               `post-thread-user`.`changed` = `post-thread`.`changed`, `post-thread-user`.`commented` = `post-thread`.`commented`")) {
+               return Update::FAILED;
+       }
+
+       
        return Update::SUCCESS;
 }