From 45be80b05ed9526e291be6fae4876c5b05f92098 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Tue, 11 Aug 2020 16:40:01 +0000
Subject: [PATCH] Display reshared ("announced") messages of a user on their
 page

---
 src/Model/Contact.php | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/Model/Contact.php b/src/Model/Contact.php
index cdc3187da7..0e3b5724cb 100644
--- a/src/Model/Contact.php
+++ b/src/Model/Contact.php
@@ -1275,8 +1275,8 @@ class Contact
 		$contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
 
 		if ($thread_mode) {
-			$condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql,
-				$cid, GRAVITY_PARENT, local_user()];
+			$condition = ["`$contact_field` = ? AND (`gravity` = ? OR (`gravity` = ? AND `vid` = ?)) AND " . $sql,
+				$cid, GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()];
 		} else {
 			$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
 				$cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
@@ -1296,9 +1296,18 @@ class Contact
 			'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
 
 		if ($thread_mode) {
-			$r = Item::selectThreadForUser(local_user(), ['uri'], $condition, $params);
-
-			$items = Item::inArray($r);
+			$r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params);
+			$items = [];
+			while ($item = DBA::fetch($r)) {
+				if ($item['gravity'] != GRAVITY_PARENT) {
+					$item['uri'] = $item['parent-uri'];
+				}
+				unset($item['parent-uri']);
+				unset($item['gravity']);
+				
+				$items[] = $item;
+			}
+			DBA::close($r);
 
 			$o = conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
 		} else {