From 0e4d3fe9e500598a1a03d4e50cd63abbf4ad7fde Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 13:26:23 +0000 Subject: [PATCH 1/7] Display a symbol when a post had been reshared --- include/conversation.php | 19 +++++++++++++++++++ src/Object/Post.php | 4 +++- view/theme/frio/templates/sub/direction.tpl | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 1c9c37d24a..01139a2cb9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -708,17 +708,36 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o */ function conversation_fetch_comments($thread_items, $pinned) { $comments = []; + $parentlines = []; + $lineno = 0; + $direction = []; while ($row = Item::fetch($thread_items)) { + if (($row['verb'] == Activity::ANNOUNCE) && ($row['thr-parent'] == $row['parent-uri']) + && Contact::isSharing($row['author-id'], $row['uid'])) { + $direction = ['direction' => 3, 'title' => DI::l10n()->t('Reshared')]; + } + + if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) + && !Contact::isSharing($row['author-id'], $row['uid'])) { + $parentlines[] = $lineno; + } + if ($row['gravity'] == GRAVITY_PARENT) { $row['pinned'] = $pinned; } $comments[] = $row; + $lineno++; } DBA::close($thread_items); + if (!empty($direction)) { + foreach ($parentlines as $line) { + $comments[$line]['direction'] = $direction; + } + } return $comments; } diff --git a/src/Object/Post.php b/src/Object/Post.php index a1b3941aef..0f2a0c6518 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -409,7 +409,9 @@ class Post } $direction = []; - if (DI::config()->get('debug', 'show_direction')) { + if (!empty($item['direction'])) { + $direction = $item['direction']; + } elseif (DI::config()->get('debug', 'show_direction')) { $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]); if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) { $title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')]; diff --git a/view/theme/frio/templates/sub/direction.tpl b/view/theme/frio/templates/sub/direction.tpl index be34a1edc9..462f540b35 100644 --- a/view/theme/frio/templates/sub/direction.tpl +++ b/view/theme/frio/templates/sub/direction.tpl @@ -5,6 +5,8 @@ {{elseif $direction.direction == 2}} + {{elseif $direction.direction == 3}} + {{/if}} {{/if}} From e6431e53db73080be96cb615483860007de10dfd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 14:07:17 +0000 Subject: [PATCH 2/7] Changed "reshared" description --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 01139a2cb9..3d1aeddab9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -715,7 +715,7 @@ function conversation_fetch_comments($thread_items, $pinned) { while ($row = Item::fetch($thread_items)) { if (($row['verb'] == Activity::ANNOUNCE) && ($row['thr-parent'] == $row['parent-uri']) && Contact::isSharing($row['author-id'], $row['uid'])) { - $direction = ['direction' => 3, 'title' => DI::l10n()->t('Reshared')]; + $direction = ['direction' => 3, 'title' => DI::l10n()->t('%s reshared this.', $row['author-name'])]; } if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) From 15119f6a593ee88cf0ad66a0f814961f548b8d3f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 14:51:56 +0000 Subject: [PATCH 3/7] Added information about fetched post because of comment --- include/conversation.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 3d1aeddab9..4478745846 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -711,11 +711,17 @@ function conversation_fetch_comments($thread_items, $pinned) { $parentlines = []; $lineno = 0; $direction = []; + $received = ''; while ($row = Item::fetch($thread_items)) { if (($row['verb'] == Activity::ANNOUNCE) && ($row['thr-parent'] == $row['parent-uri']) - && Contact::isSharing($row['author-id'], $row['uid'])) { + && ($row['received'] > $received) && Contact::isSharing($row['author-id'], $row['uid'])) { $direction = ['direction' => 3, 'title' => DI::l10n()->t('%s reshared this.', $row['author-name'])]; + $received = $row['received']; + } + + if (empty($direction) && ($row['gravity'] == GRAVITY_COMMENT) && Contact::isSharing($row['author-id'], $row['uid'])) { + $direction = ['direction' => 2, 'title' => DI::l10n()->t('%s commented this.', $row['author-name'])]; } if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) From 1493875ec989ae4d7d124248d67b8f4fa8359d5b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 15:18:26 +0000 Subject: [PATCH 4/7] Speed improvement --- include/conversation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 4478745846..faee8f5b3e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -714,13 +714,15 @@ function conversation_fetch_comments($thread_items, $pinned) { $received = ''; while ($row = Item::fetch($thread_items)) { - if (($row['verb'] == Activity::ANNOUNCE) && ($row['thr-parent'] == $row['parent-uri']) - && ($row['received'] > $received) && Contact::isSharing($row['author-id'], $row['uid'])) { + if (!empty($parentlines) && ($row['verb'] == Activity::ANNOUNCE) + && ($row['thr-parent'] == $row['parent-uri']) && ($row['received'] > $received) + && Contact::isSharing($row['author-id'], $row['uid'])) { $direction = ['direction' => 3, 'title' => DI::l10n()->t('%s reshared this.', $row['author-name'])]; $received = $row['received']; } - if (empty($direction) && ($row['gravity'] == GRAVITY_COMMENT) && Contact::isSharing($row['author-id'], $row['uid'])) { + if (!empty($parentlines) && empty($direction) && ($row['gravity'] == GRAVITY_COMMENT) + && Contact::isSharing($row['author-id'], $row['uid'])) { $direction = ['direction' => 2, 'title' => DI::l10n()->t('%s commented this.', $row['author-name'])]; } From 6139f5883b0798bd83d2873c9d34930b35581f99 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 17:48:44 +0000 Subject: [PATCH 5/7] Mark posts that arrived in your network stream via tag --- include/conversation.php | 6 +++++- src/Model/Item.php | 15 ++++++++++++--- view/theme/frio/templates/sub/direction.tpl | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index faee8f5b3e..7ff4de2ead 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -728,6 +728,10 @@ function conversation_fetch_comments($thread_items, $pinned) { if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) && !Contact::isSharing($row['author-id'], $row['uid'])) { + if ($row['post-type'] == Item::PT_TAG) { + $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')]; + } + $parentlines[] = $lineno; } @@ -810,7 +814,7 @@ function conversation_fetch_items(array $parent, array $items, array $condition, $condition[0] .= " AND NOT `author`.`hidden`"; } - $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params); + $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity', 'post-type']), $condition, $params); $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false); diff --git a/src/Model/Item.php b/src/Model/Item.php index 28ea01b85b..c8b8aa385b 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -40,7 +40,6 @@ use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; use Friendica\Util\Network; -use Friendica\Util\Security; use Friendica\Util\Strings; use Friendica\Worker\Delivery; use Text_LanguageDetect; @@ -57,6 +56,7 @@ class Item const PT_VIDEO = 18; const PT_DOCUMENT = 19; const PT_EVENT = 32; + const PT_TAG = 64; const PT_PERSONAL_NOTE = 128; // Field list that is used to display the items @@ -2046,7 +2046,13 @@ class Item $uids = Tag::getUIDListByURIId($item['uri-id']); foreach ($uids as $uid) { - $stored = self::storeForUserByUriId($item['uri-id'], $uid); + if (Contact::isSharing($item['author-id'], $uid)) { + $fields = []; + } else { + $fields = ['post-type' => self::PT_TAG]; + } + + $stored = self::storeForUserByUriId($item['uri-id'], $uid, $fields); Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]); } } @@ -2215,9 +2221,10 @@ class Item * * @param integer $uri_id URI-ID of the given item * @param integer $uid The user that will receive the item entry + * @param array $fields Additional fields to be stored * @return integer stored item id */ - public static function storeForUserByUriId(int $uri_id, int $uid) + public static function storeForUserByUriId(int $uri_id, int $uid, array $fields = []) { $item = self::selectFirst(self::ITEM_FIELDLIST, ['uri-id' => $uri_id, 'uid' => 0]); if (!DBA::isResult($item)) { @@ -2229,6 +2236,8 @@ class Item return 0; } + $item = array_merge($item, $fields); + $stored = self::storeForUser($item, $uid); Logger::info('Public item stored for user', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]); return $stored; diff --git a/view/theme/frio/templates/sub/direction.tpl b/view/theme/frio/templates/sub/direction.tpl index 462f540b35..609a5105b2 100644 --- a/view/theme/frio/templates/sub/direction.tpl +++ b/view/theme/frio/templates/sub/direction.tpl @@ -7,6 +7,8 @@ {{elseif $direction.direction == 3}} + {{elseif $direction.direction == 4}} + {{/if}} {{/if}} From c403efb17702b09c89a44332fa1e69deaf8b51b8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 17:58:22 +0000 Subject: [PATCH 6/7] Improved logging --- 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 c8b8aa385b..baf113e17d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2053,7 +2053,7 @@ class Item } $stored = self::storeForUserByUriId($item['uri-id'], $uid, $fields); - Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]); + Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'fields' => $fields, 'stored' => $stored]); } } From a7946d80b803ce2956391d63fca0b305febb3fd0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Aug 2020 18:54:32 +0000 Subject: [PATCH 7/7] Added directions for the other themes --- view/theme/vier/templates/sub/direction.tpl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/view/theme/vier/templates/sub/direction.tpl b/view/theme/vier/templates/sub/direction.tpl index 8591026097..f884d51c26 100644 --- a/view/theme/vier/templates/sub/direction.tpl +++ b/view/theme/vier/templates/sub/direction.tpl @@ -5,6 +5,10 @@ {{elseif $direction.direction == 2}} + {{elseif $direction.direction == 3}} + + {{elseif $direction.direction == 4}} + {{/if}} {{/if}}