"post-reason" ends double usage of "post-type"

This commit is contained in:
Michael 2021-04-07 06:02:06 +00:00
parent 9a3a7793f0
commit 688e056ad1
13 changed files with 159 additions and 76 deletions

View file

@ -381,6 +381,7 @@ class Event
$item_arr['visible'] = 1;
$item_arr['verb'] = Activity::POST;
$item_arr['object-type'] = Activity\ObjectType::EVENT;
$item_arr['post-type'] = Item::PT_EVENT;
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
$item_arr['body'] = self::getBBCode($event);
$item_arr['event-id'] = $event['id'];

View file

@ -55,20 +55,23 @@ class Item
const PT_VIDEO = 18;
const PT_DOCUMENT = 19;
const PT_EVENT = 32;
const PT_TAG = 64;
const PT_TO = 65;
const PT_CC = 66;
const PT_BTO = 67;
const PT_BCC = 68;
const PT_FOLLOWER = 69;
const PT_ANNOUNCEMENT = 70;
const PT_COMMENT = 71;
const PT_STORED = 72;
const PT_GLOBAL = 73;
const PT_RELAY = 74;
const PT_FETCHED = 75;
const PT_PERSONAL_NOTE = 128;
// Posting reasons (Why had a post been stored for a user?)
const PR_NONE = 0;
const PR_TAG = 64;
const PR_TO = 65;
const PR_CC = 66;
const PR_BTO = 67;
const PR_BCC = 68;
const PR_FOLLOWER = 69;
const PR_ANNOUNCEMENT = 70;
const PR_COMMENT = 71;
const PR_STORED = 72;
const PR_GLOBAL = 73;
const PR_RELAY = 74;
const PR_FETCHED = 75;
// Field list that is used to display the items
const DISPLAY_FIELDLIST = [
'uid', 'id', 'parent', 'guid', 'network', 'gravity',
@ -92,7 +95,7 @@ class Item
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
'inform', 'deleted', 'extid', 'post-type', 'gravity',
'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
@ -107,7 +110,7 @@ class Item
'contact-id', 'wall', 'gravity', 'extid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb',
'postopts', 'plink', 'resource-id', 'event-id', 'inform',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason',
'private', 'pubmail', 'visible', 'starred',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
'title', 'content-warning', 'body', 'location', 'coord', 'app',
@ -744,6 +747,10 @@ class Item
return 0;
}
if (!isset($item['post-type'])) {
$item['post-type'] = empty($item['title']) ? self::PT_NOTE : self::PT_ARTICLE;
}
$item['wall'] = intval($item['wall'] ?? 0);
$item['extid'] = trim($item['extid'] ?? '');
$item['author-name'] = trim($item['author-name'] ?? '');
@ -762,7 +769,6 @@ class Item
$item['coord'] = trim($item['coord'] ?? '');
$item['visible'] = (isset($item['visible']) ? intval($item['visible']) : 1);
$item['deleted'] = 0;
$item['post-type'] = ($item['post-type'] ?? '') ?: self::PT_ARTICLE;
$item['verb'] = trim($item['verb'] ?? '');
$item['object-type'] = trim($item['object-type'] ?? '');
$item['object'] = trim($item['object'] ?? '');
@ -810,7 +816,7 @@ class Item
$actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
if (!$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
$item['post-type'] = self::PT_FOLLOWER;
$item['post-reason'] = self::PR_FOLLOWER;
}
// Ensure that there is an avatar cache
@ -1115,7 +1121,7 @@ class Item
*/
private static function setOwnerforResharedItem(array $item)
{
$parent = Post::selectFirst(['id', 'causer-id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-type'],
$parent = Post::selectFirst(['id', 'causer-id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-reason'],
['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
if (!DBA::isResult($parent)) {
Logger::error('Parent not found', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
@ -1135,7 +1141,7 @@ class Item
}
if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
if ($parent['post-type'] == self::PT_ANNOUNCEMENT) {
if ($parent['post-reason'] == self::PR_ANNOUNCEMENT) {
Logger::info('The parent is already marked as announced: quit', ['causer' => $parent['causer-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
return;
}
@ -1144,8 +1150,8 @@ class Item
Logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
return;
}
self::update(['post-type' => self::PT_ANNOUNCEMENT, 'causer-id' => $item['author-id']], ['id' => $parent['id']]);
Logger::info('Set announcement post-type', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
self::update(['post-reason' => self::PR_ANNOUNCEMENT, 'causer-id' => $item['author-id']], ['id' => $parent['id']]);
Logger::info('Set announcement post-reason', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
return;
}
@ -1169,7 +1175,7 @@ class Item
if (Contact::isSharing($item['author-id'], $uid)) {
$fields = [];
} else {
$fields = ['post-type' => self::PT_TAG];
$fields = ['post-reason' => self::PR_TAG];
}
$stored = self::storeForUserByUriId($item['uri-id'], $uid, $fields);
@ -1289,7 +1295,7 @@ class Item
return 0;
}
$item['post-type'] = self::PT_STORED;
$item['post-reason'] = self::PR_STORED;
$item = array_merge($item, $fields);
@ -1416,7 +1422,7 @@ class Item
unset($item['starred']);
unset($item['postopts']);
unset($item['inform']);
unset($item['post-type']);
unset($item['post-reason']);
if ($item['uri-id'] == $item['parent-uri-id']) {
$item['contact-id'] = $item['owner-id'];
} else {
@ -1479,7 +1485,7 @@ class Item
unset($item['starred']);
unset($item['postopts']);
unset($item['inform']);
unset($item['post-type']);
unset($item['post-reason']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']);
$public_shadow = self::insert($item, false, true);
@ -2157,7 +2163,7 @@ class Item
// Only expire posts, not photos and photo comments
if (!$expire_photos && (!empty($item['resource-id']) || ($item['post-type'] == self::PT_IMAGE))) {
if (!$expire_photos && !empty($item['resource-id'])) {
continue;
} elseif (!$expire_starred && intval($item['starred'])) {
continue;
@ -2696,21 +2702,31 @@ class Item
if (($filetype == 'video')) {
/// @todo Move the template to /content as well
$leading .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
'$video' => [
'id' => $item['author-id'],
'src' => $the_url,
'mime' => $mime,
],
]);
if ($item['post-type'] == Item::PT_VIDEO) {
$leading .= $media;
} else {
$trailing .= $media;
}
} elseif ($filetype == 'audio') {
$leading .= Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
'$audio' => [
'id' => $item['author-id'],
'src' => $the_url,
'mime' => $mime,
],
]);
if ($item['post-type'] == Item::PT_AUDIO) {
$leading .= $media;
} else {
$trailing .= $media;
}
} else {
$title = Strings::escapeHtml(trim(($attachment['description'] ?? '') ?: $attachment['url']));

View file

@ -198,31 +198,47 @@ class Processor
// image is the preview/thumbnail URL
if (!empty($attach['image'])) {
$trailing .= '[url=' . $attach['url'] . ']';
$media = '[url=' . $attach['url'] . ']';
$attach['url'] = $attach['image'];
} else {
$media = '';
}
if (empty($attach['name'])) {
$trailing .= '[img]' . $attach['url'] . '[/img]';
$media .= '[img]' . $attach['url'] . '[/img]';
} else {
$trailing .= '[img=' . $attach['url'] . ']' . $attach['name'] . '[/img]';
$media .= '[img=' . $attach['url'] . ']' . $attach['name'] . '[/img]';
}
if (!empty($attach['image'])) {
$trailing .= '[/url]';
$media .= '[/url]';
}
if ($item['post-type'] == Item::PT_IMAGE) {
$leading .= $media;
} else {
$trailing .= $media;
}
} elseif ($filetype == 'audio') {
if (!empty($activity['source']) && strpos($activity['source'], $attach['url'])) {
continue 2;
}
$leading .= '[audio]' . $attach['url'] . "[/audio]\n";
if ($item['post-type'] == Item::PT_AUDIO) {
$leading .= '[audio]' . $attach['url'] . "[/audio]\n";
} else {
$trailing .= '[audio]' . $attach['url'] . "[/audio]\n";
}
} elseif ($filetype == 'video') {
if (!empty($activity['source']) && strpos($activity['source'], $attach['url'])) {
continue 2;
}
$leading .= '[video]' . $attach['url'] . "[/video]\n";
if ($item['post-type'] == Item::PT_VIDEO) {
$leading .= '[video]' . $attach['url'] . "[/video]\n";
} else {
$trailing .= '[video]' . $attach['url'] . "[/video]\n";
}
}
}
}
@ -250,7 +266,7 @@ class Processor
*/
public static function updateItem($activity)
{
$item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
$item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]);
if (!DBA::isResult($item)) {
Logger::warning('No existing item, item will be created', ['uri' => $activity['id']]);
$item = self::createItem($activity);
@ -336,6 +352,24 @@ class Processor
$item['direction'] = Conversation::RELAY;
}
if ($activity['object_type'] == 'as:Article') {
$item['post-type'] = Item::PT_ARTICLE;
} elseif ($activity['object_type'] == 'as:Audio') {
$item['post-type'] = Item::PT_AUDIO;
} elseif ($activity['object_type'] == 'as:Document') {
$item['post-type'] = Item::PT_DOCUMENT;
} elseif ($activity['object_type'] == 'as:Event') {
$item['post-type'] = Item::PT_EVENT;
} elseif ($activity['object_type'] == 'as:Image') {
$item['post-type'] = Item::PT_IMAGE;
} elseif ($activity['object_type'] == 'as:Page') {
$item['post-type'] = Item::PT_PAGE;
} elseif ($activity['object_type'] == 'as:Video') {
$item['post-type'] = Item::PT_VIDEO;
} else {
$item['post-type'] = Item::PT_NOTE;
}
$item['isForum'] = false;
if (!empty($activity['thread-completion'])) {
@ -456,6 +490,7 @@ class Processor
$item['verb'] = $verb;
$item['thr-parent'] = $activity['object_id'];
$item['gravity'] = GRAVITY_ACTIVITY;
unset($item['post-type']);
$item['object-type'] = Activity\ObjectType::NOTE;
$item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
@ -629,34 +664,34 @@ class Processor
$type = $activity['reception_type'][$receiver] ?? Receiver::TARGET_UNKNOWN;
switch($type) {
case Receiver::TARGET_TO:
$item['post-type'] = Item::PT_TO;
$item['post-reason'] = Item::PR_TO;
break;
case Receiver::TARGET_CC:
$item['post-type'] = Item::PT_CC;
$item['post-reason'] = Item::PR_CC;
break;
case Receiver::TARGET_BTO:
$item['post-type'] = Item::PT_BTO;
$item['post-reason'] = Item::PR_BTO;
break;
case Receiver::TARGET_BCC:
$item['post-type'] = Item::PT_BCC;
$item['post-reason'] = Item::PR_BCC;
break;
case Receiver::TARGET_FOLLOWER:
$item['post-type'] = Item::PT_FOLLOWER;
$item['post-reason'] = Item::PR_FOLLOWER;
break;
case Receiver::TARGET_ANSWER:
$item['post-type'] = Item::PT_COMMENT;
$item['post-reason'] = Item::PR_COMMENT;
break;
case Receiver::TARGET_GLOBAL:
$item['post-type'] = Item::PT_GLOBAL;
$item['post-reason'] = Item::PR_GLOBAL;
break;
default:
$item['post-type'] = Item::PT_ARTICLE;
$item['post-reason'] = Item::PR_NONE;
}
if (!empty($activity['from-relay'])) {
$item['post-type'] = Item::PT_RELAY;
$item['post-reason'] = Item::PR_RELAY;
} elseif (!empty($activity['thread-completion'])) {
$item['post-type'] = Item::PT_FETCHED;
$item['post-reason'] = Item::PR_FETCHED;
}
if ($item['isForum'] ?? false) {

View file

@ -522,7 +522,7 @@ class Receiver
return;
}
$item['post-type'] = Item::PT_ANNOUNCEMENT;
$item['post-reason'] = Item::PR_ANNOUNCEMENT;
ActivityPub\Processor::postItem($object_data, $item);
$announce_object_data = self::processObject($activity);

View file

@ -2195,6 +2195,12 @@ class DFRN
$item["title"] = XML::getFirstNodeValue($xpath, "atom:title/text()", $entry);
if (!empty($item["title"])) {
$item["post-type"] = Item::PT_ARTICLE;
} else {
$item["post-type"] = Item::PT_NOTE;
}
$item["created"] = XML::getFirstNodeValue($xpath, "atom:published/text()", $entry);
$item["body"] = XML::getFirstNodeValue($xpath, "dfrn:env/text()", $entry);
@ -2426,8 +2432,8 @@ class DFRN
if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
// Will be overwritten for sharing accounts in Item::insert
if (empty($item['post-type']) && ($entrytype == DFRN::REPLY)) {
$item['post-type'] = Item::PT_COMMENT;
if (empty($item['post-reason']) && ($entrytype == DFRN::REPLY)) {
$item['post-reason'] = Item::PR_COMMENT;
}
$posted_id = Item::insert($item);
@ -2588,7 +2594,7 @@ class DFRN
$header["direction"] = $direction;
if ($direction === Conversation::RELAY) {
$header['post-type'] = Item::PT_RELAY;
$header['post-reason'] = Item::PR_RELAY;
}
// Update the contact table if the data has changed

View file

@ -1536,11 +1536,11 @@ class Diaspora
// Will be overwritten for sharing accounts in Item::insert
if ($fetched) {
$datarray["post-type"] = Item::PT_FETCHED;
$datarray["post-reason"] = Item::PR_FETCHED;
} elseif ($datarray["uid"] == 0) {
$datarray["post-type"] = Item::PT_GLOBAL;
$datarray["post-reason"] = Item::PR_GLOBAL;
} else {
$datarray["post-type"] = Item::PT_COMMENT;
$datarray["post-reason"] = Item::PR_COMMENT;
}
$datarray["guid"] = $guid;
@ -1553,6 +1553,7 @@ class Diaspora
$datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
$datarray["object-type"] = Activity\ObjectType::COMMENT;
$datarray["post-type"] = Item::PT_NOTE;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
@ -2737,8 +2738,10 @@ class Diaspora
}
$datarray["object-type"] = Activity\ObjectType::IMAGE;
$datarray["post-type"] = Item::PT_IMAGE;
} else {
$datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["post-type"] = Item::PT_NOTE;
// Add OEmbed and other information to the body
if (!self::isHubzilla($contact["url"])) {
@ -2773,9 +2776,9 @@ class Diaspora
$datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
if ($fetched) {
$datarray["post-type"] = Item::PT_FETCHED;
$datarray["post-reason"] = Item::PR_FETCHED;
} elseif ($datarray["uid"] == 0) {
$datarray["post-type"] = Item::PT_GLOBAL;
$datarray["post-reason"] = Item::PR_GLOBAL;
}
$datarray["body"] = self::replacePeopleGuid($body, $contact["url"]);

View file

@ -235,6 +235,7 @@ class Feed
$header["private"] = Item::PUBLIC;
$header["verb"] = Activity::POST;
$header["object-type"] = Activity\ObjectType::NOTE;
$header["post-type"] = Item::PT_ARTICLE;
$header["contact-id"] = $contact["id"] ?? 0;
@ -539,6 +540,10 @@ class Feed
}
}
if (empty($item['title'])) {
$item['post-type'] = Item::PT_NOTE;
}
Logger::info('Stored feed', ['item' => $item]);
$notify = Item::isRemoteSelf($contact, $item);

View file

@ -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` IN (?, ?)) AND `parent-uri-id` = `post-thread`.`uri-id`)
WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) 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, Item::PT_IMAGE]);
$expire_days, Item::PT_PERSONAL_NOTE]);
Logger::notice('Start deleting expired threads');
$affected_count = 0;