From d0ef6f2b08b73dd53bb1f6e5c408860f57921b32 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 21 Jul 2020 23:26:01 +0000 Subject: [PATCH 1/3] Store personal copy of public item upon commenting --- mod/item.php | 10 ++++++++++ src/Model/Item.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mod/item.php b/mod/item.php index e2d47ae2f..c4d7231c2 100644 --- a/mod/item.php +++ b/mod/item.php @@ -136,6 +136,16 @@ function item_post(App $a) { throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.')); } + // When commenting on a public post then store the post for the current user + // This enables interaction like starring and saving into folders + if ($toplevel_item['uid'] == 0) { + $stored = Item::storeForUser($toplevel_item, local_user()); + Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); + if ($stored) { + $toplevel_item = Item::selectFirst([], ['id' => $stored]); + } + } + $toplevel_item_id = $toplevel_item['id']; $parent_user = $toplevel_item['uid']; diff --git a/src/Model/Item.php b/src/Model/Item.php index 860d9d73c..afecc4116 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2174,7 +2174,7 @@ class Item * @return integer stored item id * @throws \Exception */ - private static function storeForUser(array $item, int $uid) + public static function storeForUser(array $item, int $uid) { if (self::exists(['uri-id' => $item['uri-id'], 'uid' => $uid])) { Logger::info('Item already exists', ['uri-id' => $item['uri-id'], 'uid' => $uid]); From da349a1814d3a474ca7a1c9cf3edf1740adf6e4f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 Jul 2020 05:16:57 +0000 Subject: [PATCH 2/3] Store copy on activities --- src/Model/Item.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Model/Item.php b/src/Model/Item.php index afecc4116..70e6d7cea 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3015,6 +3015,14 @@ class Item return false; } + if (!Item::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) { + $parent_item = self::selectFirst(self::ITEM_FIELDLIST, ['uri-id' => $item['parent-uri-id'], 'uid' => 0]); + if (!empty($parent_item) && ($parent_item['private'] =! self::PRIVATE)) { + $stored = self::storeForUser($parent_item, $uid); + Logger::info('Public item stored for user', ['uri-id' => $parent_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); + } + } + // Retrieves the local post owner $owner_self_contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'self' => true]); if (!DBA::isResult($owner_self_contact)) { From abdcf7ca88e6c1875e1a5c20894550ad0dd7631a Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 Jul 2020 05:34:56 +0000 Subject: [PATCH 3/3] Fix "!=" --- src/Model/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 70e6d7cea..5cce6096f 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3017,7 +3017,7 @@ class Item if (!Item::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) { $parent_item = self::selectFirst(self::ITEM_FIELDLIST, ['uri-id' => $item['parent-uri-id'], 'uid' => 0]); - if (!empty($parent_item) && ($parent_item['private'] =! self::PRIVATE)) { + if (!empty($parent_item) && ($parent_item['private'] != self::PRIVATE)) { $stored = self::storeForUser($parent_item, $uid); Logger::info('Public item stored for user', ['uri-id' => $parent_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); }