+/**
+ * @brief Set "success_update" and "last-item" to the date of the last time we heard from this contact
+ *
+ * This can be used to filter for inactive contacts.
+ * Only do this for public postings to avoid privacy problems, since poco data is public.
+ * Don't set this value if it isn't from the owner (could be an author that we don't know)
+ *
+ * @param array $arr Contains the just posted item record
+ */
+function item_set_last_item($arr) {
+
+ $update = (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"])));
+
+ // Is it a forum? Then we don't care about the rules from above
+ if (!$update AND ($arr["network"] == NETWORK_DFRN) AND ($arr["parent-uri"] === $arr["uri"])) {
+ $isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
+ intval($arr['contact-id']));
+ if ($isforum) {
+ $update = true;
+ }
+ }
+
+ if ($update) {
+ q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+ dbesc($arr['received']),
+ dbesc($arr['received']),
+ intval($arr['contact-id'])
+ );
+ }
+ // Now do the same for the system wide contacts with uid=0
+ if (!$arr['private']) {
+ q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+ dbesc($arr['received']),
+ dbesc($arr['received']),
+ intval($arr['owner-id'])
+ );
+
+ if ($arr['owner-id'] != $arr['author-id']) {
+ q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
+ dbesc($arr['received']),
+ dbesc($arr['received']),
+ intval($arr['author-id'])
+ );
+ }
+ }
+}
+