From 9072107b8311ff9b2d645046a760c24c60ee7998 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Thu, 1 Apr 2021 04:58:53 +0000
Subject: [PATCH] Use post-type for the item container

---
 mod/photos.php                      | 2 +-
 src/Model/Item.php                  | 2 +-
 src/Worker/ExpirePosts.php          | 4 ++--
 src/Worker/RemoveUnusedContacts.php | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/mod/photos.php b/mod/photos.php
index e720d7d4b3..df84384645 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -784,7 +784,7 @@ function photos_post(App $a)
 	$arr['guid']          = System::createUUID();
 	$arr['uid']           = $page_owner_uid;
 	$arr['uri']           = $uri;
-	$arr['type']          = 'photo';
+	$arr['post-type']     = Item::PT_IMAGE;
 	$arr['wall']          = 1;
 	$arr['resource-id']   = $resource_id;
 	$arr['contact-id']    = $owner_record['id'];
diff --git a/src/Model/Item.php b/src/Model/Item.php
index c7103e41e5..c814ac9d83 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -2157,7 +2157,7 @@ class Item
 
 			// Only expire posts, not photos and photo comments
 
-			if (!$expire_photos && strlen($item['resource-id'])) {
+			if (!$expire_photos && (!empty($item['resource-id']) || ($item['post-type'] == self::PT_IMAGE))) {
 				continue;
 			} elseif (!$expire_starred && intval($item['starred'])) {
 				continue;
diff --git a/src/Worker/ExpirePosts.php b/src/Worker/ExpirePosts.php
index 2c3f6f68a1..cff6e2b120 100644
--- a/src/Worker/ExpirePosts.php
+++ b/src/Worker/ExpirePosts.php
@@ -224,10 +224,10 @@ class ExpirePosts
 					AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts`
 						WHERE `parent-uri-id` = `post-thread`.`uri-id`)
 					AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user`
-						WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`)
+						WHERE (`origin` OR `event-id` != 0 OR `post-type` IN (?, ?)) AND `parent-uri-id` = `post-thread`.`uri-id`)
 					AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content`
 						WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`))",
-				$expire_days, Item::PT_PERSONAL_NOTE]);
+				$expire_days, Item::PT_PERSONAL_NOTE, Item::PT_IMAGE]);
 
 			Logger::notice('Start deleting expired threads');
 			$affected_count = 0;
diff --git a/src/Worker/RemoveUnusedContacts.php b/src/Worker/RemoveUnusedContacts.php
index 2150b343e1..f93e3eb507 100644
--- a/src/Worker/RemoveUnusedContacts.php
+++ b/src/Worker/RemoveUnusedContacts.php
@@ -34,14 +34,14 @@ class RemoveUnusedContacts
 {
 	public static function execute()
 	{
-		$condition = ["`uid` = ? AND NOT `self` AND NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` != ?)
+		$condition = ["`id` != ? AND `uid` = ? AND NOT `self` AND NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` != ?)
 			AND (NOT `network` IN (?, ?, ?, ?, ?, ?) OR (`archive` AND `success_update` < UTC_TIMESTAMP() - INTERVAL ? DAY))
 			AND NOT `id` IN (SELECT `author-id` FROM `post-user`) AND NOT `id` IN (SELECT `owner-id` FROM `post-user`)
 			AND NOT `id` IN (SELECT `causer-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `post-tag`)
 			AND NOT `id` IN (SELECT `contact-id` FROM `post-user`) AND NOT `id` IN (SELECT `cid` FROM `user-contact`)
 			AND NOT `id` IN (SELECT `cid` FROM `event`) AND NOT `id` IN (SELECT `contact-id` FROM `group_member`)
 			AND `created` < UTC_TIMESTAMP() - INTERVAL ? DAY",
-			0, 0, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB, 365, 30];
+			0, 0, 0, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Protocol::ACTIVITYPUB, 365, 30];
 
 		$total = DBA::count('contact', $condition);
 		Logger::notice('Starting removal', ['total' => $total]);