- moved constants GRAVITY_* from boot.php to Friendica\Model\Item
- also rewrote some array initialization:

From:
````
<?php
$arr = [];
$arr['foo'] = "FOO";
````

To:
````
<?php
$arr['foo'] = "FOO";
````
- added a few type-hints
This commit is contained in:
Roland Häder 2022-09-12 23:12:11 +02:00
parent e5ae5c7e67
commit da66730e4f
No known key found for this signature in database
GPG key ID: C82EDE5DDFA0BA77
77 changed files with 547 additions and 513 deletions

View file

@ -59,18 +59,6 @@ define('CP_USERS_AND_GLOBAL', 2);
* @} * @}
*/ */
/**
* @name Gravity
*
* Item weight for query ordering
* @{
*/
define('GRAVITY_PARENT', 0);
define('GRAVITY_ACTIVITY', 3);
define('GRAVITY_COMMENT', 6);
define('GRAVITY_UNKNOWN', 9);
/* @}*/
/** /**
* @name Priority * @name Priority
* *

View file

@ -106,7 +106,7 @@ function display_init(App $a)
displayShowFeed($item['uri-id'], $item['uid'], false); displayShowFeed($item['uri-id'], $item['uid'], false);
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
$parent = Post::selectFirstForUser($item_user, $fields, ['uid' => [0, $item_user], 'uri-id' => $item['parent-uri-id']], ['order' => ['uid' => true]]); $parent = Post::selectFirstForUser($item_user, $fields, ['uid' => [0, $item_user], 'uri-id' => $item['parent-uri-id']], ['order' => ['uid' => true]]);
$item = $parent ?: $item; $item = $parent ?: $item;
} }

View file

@ -122,7 +122,7 @@ function item_post(App $a) {
$thr_parent_uri = $parent_item['uri']; $thr_parent_uri = $parent_item['uri'];
$toplevel_item = $parent_item; $toplevel_item = $parent_item;
if ($parent_item['gravity'] != GRAVITY_PARENT) { if ($parent_item['gravity'] != Item::GRAVITY_PARENT) {
$toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $toplevel_item['parent']]); $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $toplevel_item['parent']]);
} }
} }
@ -385,7 +385,7 @@ function item_post(App $a) {
// Look for any tags and linkify them // Look for any tags and linkify them
$item = [ $item = [
'uid' => local_user() ? local_user() : $profile_uid, 'uid' => local_user() ? local_user() : $profile_uid,
'gravity' => $toplevel_item_id ? GRAVITY_COMMENT : GRAVITY_PARENT, 'gravity' => $toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT,
'network' => $network, 'network' => $network,
'body' => $body, 'body' => $body,
'postopts' => $postopts, 'postopts' => $postopts,
@ -513,7 +513,7 @@ function item_post(App $a) {
$network = Protocol::DFRN; $network = Protocol::DFRN;
} }
$gravity = ($toplevel_item_id ? GRAVITY_COMMENT : GRAVITY_PARENT); $gravity = ($toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT);
// even if the post arrived via API we are considering that it // even if the post arrived via API we are considering that it
// originated on this site by default for determining relayability. // originated on this site by default for determining relayability.
@ -705,7 +705,7 @@ function item_post(App $a) {
Tag::storeFromBody($datarray['uri-id'], $datarray['body']); Tag::storeFromBody($datarray['uri-id'], $datarray['body']);
if (!\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions') && ($datarray['gravity'] == GRAVITY_COMMENT)) { if (!\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions') && ($datarray['gravity'] == Item::GRAVITY_COMMENT)) {
Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']); Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']);
} }
@ -833,15 +833,15 @@ function item_content(App $a)
* @return string * @return string
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
*/ */
function drop_item(int $id, string $return = '') function drop_item(int $id, string $return = ''): string
{ {
// locate item to be deleted // Locate item to be deleted
$fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent']; $item = Post::selectFirstForUser(local_user(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]);
$item = Post::selectFirstForUser(local_user(), $fields, ['id' => $id]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
notice(DI::l10n()->t('Item not found.')); notice(DI::l10n()->t('Item not found.'));
DI::baseUrl()->redirect('network'); DI::baseUrl()->redirect('network');
//NOTREACHED
} }
if ($item['deleted']) { if ($item['deleted']) {
@ -860,6 +860,7 @@ function drop_item(int $id, string $return = '')
Item::deleteForUser(['id' => $item['id']], local_user()); Item::deleteForUser(['id' => $item['id']], local_user());
item_redirect_after_action($item, $return); item_redirect_after_action($item, $return);
//NOTREACHED
} else { } else {
Logger::warning('Permission denied.', ['local' => local_user(), 'uid' => $item['uid'], 'cid' => $contact_id]); Logger::warning('Permission denied.', ['local' => local_user(), 'uid' => $item['uid'], 'cid' => $contact_id]);
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
@ -870,15 +871,15 @@ function drop_item(int $id, string $return = '')
return ''; return '';
} }
function item_redirect_after_action($item, $returnUrlHex) function item_redirect_after_action(array $item, string $returnUrlHex)
{ {
$return_url = hex2bin($returnUrlHex); $return_url = hex2bin($returnUrlHex);
// removes update_* from return_url to ignore Ajax refresh // removes update_* from return_url to ignore Ajax refresh
$return_url = str_replace("update_", "", $return_url); $return_url = str_replace('update_', '', $return_url);
// Check if delete a comment // Check if delete a comment
if ($item['gravity'] == GRAVITY_COMMENT) { if ($item['gravity'] == Item::GRAVITY_COMMENT) {
if (!empty($item['parent'])) { if (!empty($item['parent'])) {
$parentitem = Post::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]); $parentitem = Post::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]);
} }

View file

@ -43,23 +43,23 @@ function message_init(App $a)
} }
$new = [ $new = [
'label' => DI::l10n()->t('New Message'), 'label' => DI::l10n()->t('New Message'),
'url' => 'message/new', 'url' => 'message/new',
'sel' => DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new', 'sel' => DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new',
'accesskey' => 'm', 'accesskey' => 'm',
]; ];
$tpl = Renderer::getMarkupTemplate('message_side.tpl'); $tpl = Renderer::getMarkupTemplate('message_side.tpl');
DI::page()['aside'] = Renderer::replaceMacros($tpl, [ DI::page()['aside'] = Renderer::replaceMacros($tpl, [
'$tabs' => $tabs, '$tabs' => $tabs,
'$new' => $new, '$new' => $new,
]); ]);
$base = DI::baseUrl(); $base = DI::baseUrl();
$head_tpl = Renderer::getMarkupTemplate('message-head.tpl'); $head_tpl = Renderer::getMarkupTemplate('message-head.tpl');
DI::page()['htmlhead'] .= Renderer::replaceMacros($head_tpl, [ DI::page()['htmlhead'] .= Renderer::replaceMacros($head_tpl, [
'$baseurl' => DI::baseUrl()->get(true), '$baseurl' => DI::baseUrl()->get(true),
'$base' => $base '$base' => $base
]); ]);
} }
@ -83,12 +83,15 @@ function message_post(App $a)
notice(DI::l10n()->t('No recipient selected.')); notice(DI::l10n()->t('No recipient selected.'));
$norecip = true; $norecip = true;
break; break;
case -2: case -2:
notice(DI::l10n()->t('Unable to locate contact information.')); notice(DI::l10n()->t('Unable to locate contact information.'));
break; break;
case -3: case -3:
notice(DI::l10n()->t('Message could not be sent.')); notice(DI::l10n()->t('Message could not be sent.'));
break; break;
case -4: case -4:
notice(DI::l10n()->t('Message collection failure.')); notice(DI::l10n()->t('Message collection failure.'));
break; break;
@ -118,20 +121,20 @@ function message_content(App $a)
if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new') { if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new') {
$button = [ $button = [
'label' => DI::l10n()->t('Discard'), 'label' => DI::l10n()->t('Discard'),
'url' => '/message', 'url' => '/message',
'sel' => 'close', 'sel' => 'close',
]; ];
} else { } else {
$button = [ $button = [
'label' => DI::l10n()->t('New Message'), 'label' => DI::l10n()->t('New Message'),
'url' => '/message/new', 'url' => '/message/new',
'sel' => 'new', 'sel' => 'new',
'accesskey' => 'm', 'accesskey' => 'm',
]; ];
} }
$header = Renderer::replaceMacros($tpl, [ $header = Renderer::replaceMacros($tpl, [
'$messages' => DI::l10n()->t('Messages'), '$messages' => DI::l10n()->t('Messages'),
'$button' => $button, '$button' => $button,
]); ]);
if ((DI::args()->getArgc() == 3) && (DI::args()->getArgv()[1] === 'drop' || DI::args()->getArgv()[1] === 'dropconv')) { if ((DI::args()->getArgc() == 3) && (DI::args()->getArgv()[1] === 'drop' || DI::args()->getArgv()[1] === 'dropconv')) {
@ -186,19 +189,19 @@ function message_content(App $a)
$tpl = Renderer::getMarkupTemplate('prv_message.tpl'); $tpl = Renderer::getMarkupTemplate('prv_message.tpl');
$o .= Renderer::replaceMacros($tpl, [ $o .= Renderer::replaceMacros($tpl, [
'$header' => DI::l10n()->t('Send Private Message'), '$header' => DI::l10n()->t('Send Private Message'),
'$to' => DI::l10n()->t('To:'), '$to' => DI::l10n()->t('To:'),
'$subject' => DI::l10n()->t('Subject:'), '$subject' => DI::l10n()->t('Subject:'),
'$subjtxt' => $_REQUEST['subject'] ?? '', '$subjtxt' => $_REQUEST['subject'] ?? '',
'$text' => $_REQUEST['body'] ?? '', '$text' => $_REQUEST['body'] ?? '',
'$readonly' => '', '$readonly' => '',
'$yourmessage'=> DI::l10n()->t('Your message:'), '$yourmessage' => DI::l10n()->t('Your message:'),
'$select' => $select, '$select' => $select,
'$parent' => '', '$parent' => '',
'$upload' => DI::l10n()->t('Upload photo'), '$upload' => DI::l10n()->t('Upload photo'),
'$insert' => DI::l10n()->t('Insert web link'), '$insert' => DI::l10n()->t('Insert web link'),
'$wait' => DI::l10n()->t('Please wait'), '$wait' => DI::l10n()->t('Please wait'),
'$submit' => DI::l10n()->t('Submit') '$submit' => DI::l10n()->t('Submit')
]); ]);
return $o; return $o;
} }
@ -312,18 +315,18 @@ function message_content(App $a)
$from_photo = Contact::getThumb($contact); $from_photo = Contact::getThumb($contact);
$mails[] = [ $mails[] = [
'id' => $message['id'], 'id' => $message['id'],
'from_name' => $from_name_e, 'from_name' => $from_name_e,
'from_url' => $from_url, 'from_url' => $from_url,
'from_addr' => $contact['addr'] ?? $from_url, 'from_addr' => $contact['addr'] ?? $from_url,
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'from_photo' => $from_photo, 'from_photo' => $from_photo,
'subject' => $subject_e, 'subject' => $subject_e,
'body' => $body_e, 'body' => $body_e,
'delete' => DI::l10n()->t('Delete message'), 'delete' => DI::l10n()->t('Delete message'),
'to_name' => $to_name_e, 'to_name' => $to_name_e,
'date' => DateTimeFormat::local($message['created'], DI::l10n()->t('D, d M Y - g:i A')), 'date' => DateTimeFormat::local($message['created'], DI::l10n()->t('D, d M Y - g:i A')),
'ago' => Temporal::getRelativeDate($message['created']), 'ago' => Temporal::getRelativeDate($message['created']),
]; ];
$seen = $message['seen']; $seen = $message['seen'];
@ -334,28 +337,27 @@ function message_content(App $a)
$tpl = Renderer::getMarkupTemplate('mail_display.tpl'); $tpl = Renderer::getMarkupTemplate('mail_display.tpl');
$o = Renderer::replaceMacros($tpl, [ $o = Renderer::replaceMacros($tpl, [
'$thread_id' => DI::args()->getArgv()[1], '$thread_id' => DI::args()->getArgv()[1],
'$thread_subject' => $message['title'], '$thread_subject' => $message['title'],
'$thread_seen' => $seen, '$thread_seen' => $seen,
'$delete' => DI::l10n()->t('Delete conversation'), '$delete' => DI::l10n()->t('Delete conversation'),
'$canreply' => (($unknown) ? false : '1'), '$canreply' => (($unknown) ? false : '1'),
'$unknown_text' => DI::l10n()->t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."), '$unknown_text' => DI::l10n()->t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."),
'$mails' => $mails, '$mails' => $mails,
// reply // reply
'$header' => DI::l10n()->t('Send Reply'), '$header' => DI::l10n()->t('Send Reply'),
'$to' => DI::l10n()->t('To:'), '$to' => DI::l10n()->t('To:'),
'$subject' => DI::l10n()->t('Subject:'), '$subject' => DI::l10n()->t('Subject:'),
'$subjtxt' => $message['title'], '$subjtxt' => $message['title'],
'$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
'$yourmessage' => DI::l10n()->t('Your message:'), '$yourmessage' => DI::l10n()->t('Your message:'),
'$text' => '', '$text' => '',
'$select' => $select, '$select' => $select,
'$parent' => $parent, '$parent' => $parent,
'$upload' => DI::l10n()->t('Upload photo'), '$upload' => DI::l10n()->t('Upload photo'),
'$insert' => DI::l10n()->t('Insert web link'), '$insert' => DI::l10n()->t('Insert web link'),
'$submit' => DI::l10n()->t('Submit'), '$submit' => DI::l10n()->t('Submit'),
'$wait' => DI::l10n()->t('Please wait') '$wait' => DI::l10n()->t('Please wait')
]); ]);
return $o; return $o;
@ -368,7 +370,7 @@ function message_content(App $a)
* @param int $limit * @param int $limit
* @return array * @return array
*/ */
function get_messages(int $uid, int $start, int $limit) function get_messages(int $uid, int $start, int $limit): array
{ {
return DBA::toArray(DBA::p('SELECT return DBA::toArray(DBA::p('SELECT
m.`id`, m.`id`,
@ -392,21 +394,21 @@ function get_messages(int $uid, int $start, int $limit)
c.`url`, c.`url`,
c.`thumb`, c.`thumb`,
c.`network`, c.`network`,
m2.`count`, m2.`count`,
m2.`mailcreated`, m2.`mailcreated`,
m2.`mailseen` m2.`mailseen`
FROM `mail` m FROM `mail` m
JOIN ( JOIN (
SELECT SELECT
`parent-uri`, `parent-uri`,
MIN(`id`) AS `id`, MIN(`id`) AS `id`,
COUNT(*) AS `count`, COUNT(*) AS `count`,
MAX(`created`) AS `mailcreated`, MAX(`created`) AS `mailcreated`,
MIN(`seen`) AS `mailseen` MIN(`seen`) AS `mailseen`
FROM `mail` FROM `mail`
WHERE `uid` = ? WHERE `uid` = ?
GROUP BY `parent-uri` GROUP BY `parent-uri`
) m2 ON m.`parent-uri` = m2.`parent-uri` AND m.`id` = m2.`id` ) m2 ON m.`parent-uri` = m2.`parent-uri` AND m.`id` = m2.`id`
LEFT JOIN `contact` c ON m.`contact-id` = c.`id` LEFT JOIN `contact` c ON m.`contact-id` = c.`id`
WHERE m.`uid` = ? WHERE m.`uid` = ?
ORDER BY m2.`mailcreated` DESC ORDER BY m2.`mailcreated` DESC
@ -414,7 +416,7 @@ function get_messages(int $uid, int $start, int $limit)
, $uid, $uid, $start, $limit)); , $uid, $uid, $start, $limit));
} }
function render_messages(array $msg, $t) function render_messages(array $msg, string $t): string
{ {
$a = DI::app(); $a = DI::app();
@ -444,20 +446,20 @@ function render_messages(array $msg, $t)
$from_photo = Contact::getThumb($contact); $from_photo = Contact::getThumb($contact);
$rslt .= Renderer::replaceMacros($tpl, [ $rslt .= Renderer::replaceMacros($tpl, [
'$id' => $rr['id'], '$id' => $rr['id'],
'$from_name' => $participants, '$from_name' => $participants,
'$from_url' => Contact::magicLink($rr['url']), '$from_url' => Contact::magicLink($rr['url']),
'$from_addr' => $contact['addr'] ?? '', '$from_addr' => $contact['addr'] ?? '',
'$sparkle' => ' sparkle', '$sparkle' => ' sparkle',
'$from_photo' => $from_photo, '$from_photo' => $from_photo,
'$subject' => $rr['title'], '$subject' => $rr['title'],
'$delete' => DI::l10n()->t('Delete conversation'), '$delete' => DI::l10n()->t('Delete conversation'),
'$body' => $body_e, '$body' => $body_e,
'$to_name' => $to_name_e, '$to_name' => $to_name_e,
'$date' => DateTimeFormat::local($rr['mailcreated'], DI::l10n()->t('D, d M Y - g:i A')), '$date' => DateTimeFormat::local($rr['mailcreated'], DI::l10n()->t('D, d M Y - g:i A')),
'$ago' => Temporal::getRelativeDate($rr['mailcreated']), '$ago' => Temporal::getRelativeDate($rr['mailcreated']),
'$seen' => $rr['mailseen'], '$seen' => $rr['mailseen'],
'$count' => DI::l10n()->tt('%d message', '%d messages', $rr['count']), '$count' => DI::l10n()->tt('%d message', '%d messages', $rr['count']),
]); ]);
} }

View file

@ -38,7 +38,7 @@ function notes_init(App $a)
} }
function notes_content(App $a, $update = false) function notes_content(App $a, bool $update = false)
{ {
if (!local_user()) { if (!local_user()) {
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
@ -60,7 +60,7 @@ function notes_content(App $a, $update = false)
$o .= DI::conversation()->statusEditor($x, $a->getContactId()); $o .= DI::conversation()->statusEditor($x, $a->getContactId());
} }
$condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT, $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT,
'contact-id'=> $a->getContactId()]; 'contact-id'=> $a->getContactId()];
if (DI::mode()->isMobile()) { if (DI::mode()->isMobile()) {

View file

@ -93,8 +93,8 @@ function oexchange_init(App $a)
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml'); System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
} }
function oexchange_content(App $a) { function oexchange_content(App $a)
{
if (!local_user()) { if (!local_user()) {
$o = Login::form(); $o = Login::form();
return $o; return $o;
@ -109,7 +109,7 @@ function oexchange_content(App $a) {
$description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : ''; $description = !empty($_REQUEST['description']) ? trim($_REQUEST['description']) : '';
$tags = !empty($_REQUEST['tags']) ? trim($_REQUEST['tags']) : ''; $tags = !empty($_REQUEST['tags']) ? trim($_REQUEST['tags']) : '';
$s = \Friendica\Content\Text\BBCode::embedURL($url, true, $title, $description, $tags); $s = BBCode::embedURL($url, true, $title, $description, $tags);
if (!strlen($s)) { if (!strlen($s)) {
return; return;
@ -119,9 +119,9 @@ function oexchange_content(App $a) {
$post['profile_uid'] = local_user(); $post['profile_uid'] = local_user();
$post['return'] = '/oexchange/done'; $post['return'] = '/oexchange/done';
$post['body'] = Friendica\Content\Text\HTML::toBBCode($s); $post['body'] = HTML::toBBCode($s);
$_REQUEST = $post; $_REQUEST = $post;
require_once('mod/item.php'); require_once 'mod/item.php';
item_post($a); item_post($a);
} }

View file

@ -27,7 +27,7 @@ use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
function ostatus_subscribe_content(App $a) function ostatus_subscribe_content(App $a): string
{ {
if (!local_user()) { if (!local_user()) {
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
@ -42,7 +42,6 @@ function ostatus_subscribe_content(App $a)
$counter = intval($_REQUEST['counter'] ?? 0); $counter = intval($_REQUEST['counter'] ?? 0);
if (DI::pConfig()->get($uid, 'ostatus', 'legacy_friends') == '') { if (DI::pConfig()->get($uid, 'ostatus', 'legacy_friends') == '') {
if ($_REQUEST['url'] == '') { if ($_REQUEST['url'] == '') {
DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
return $o . DI::l10n()->t('No contact provided.'); return $o . DI::l10n()->t('No contact provided.');

View file

@ -55,8 +55,8 @@ use Friendica\Util\Temporal;
use Friendica\Util\XML; use Friendica\Util\XML;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
function photos_init(App $a) { function photos_init(App $a)
{
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
return; return;
} }
@ -526,44 +526,40 @@ function photos_post(App $a)
foreach ($taginfo as $tagged) { foreach ($taginfo as $tagged) {
$uri = Item::newURI(); $uri = Item::newURI();
$arr = []; $arr = [
$arr['guid'] = System::createUUID(); 'guid' => System::createUUID(),
$arr['uid'] = $page_owner_uid; 'uid' => $page_owner_uid,
$arr['uri'] = $uri; 'uri' => $uri,
$arr['wall'] = 1; 'wall' => 1,
$arr['contact-id'] = $owner_record['id']; 'contact-id' => $owner_record['id'],
$arr['owner-name'] = $owner_record['name']; 'owner-name' => $owner_record['name'],
$arr['owner-link'] = $owner_record['url']; 'owner-link' => $owner_record['url'],
$arr['owner-avatar'] = $owner_record['thumb']; 'owner-avatar' => $owner_record['thumb'],
$arr['author-name'] = $owner_record['name']; 'author-name' => $owner_record['name'],
$arr['author-link'] = $owner_record['url']; 'author-link' => $owner_record['url'],
$arr['author-avatar'] = $owner_record['thumb']; 'author-avatar' => $owner_record['thumb'],
$arr['title'] = ''; 'title' => '',
$arr['allow_cid'] = $photo['allow_cid']; 'allow_cid' => $photo['allow_cid'],
$arr['allow_gid'] = $photo['allow_gid']; 'allow_gid' => $photo['allow_gid'],
$arr['deny_cid'] = $photo['deny_cid']; 'deny_cid' => $photo['deny_cid'],
$arr['deny_gid'] = $photo['deny_gid']; 'deny_gid' => $photo['deny_gid'],
$arr['visible'] = 0; 'visible' => 0,
$arr['verb'] = Activity::TAG; 'verb' => Activity::TAG,
$arr['gravity'] = GRAVITY_PARENT; 'gravity' => Item::GRAVITY_PARENT,
$arr['object-type'] = Activity\ObjectType::PERSON; 'object-type' => Activity\ObjectType::PERSON,
$arr['target-type'] = Activity\ObjectType::IMAGE; 'target-type' => Activity\ObjectType::IMAGE,
$arr['inform'] = $tagged[2]; 'inform' => $tagged[2],
$arr['origin'] = 1; 'origin' => 1,
$arr['body'] = DI::l10n()->t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . DI::l10n()->t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ; 'body' => DI::l10n()->t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . DI::l10n()->t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') . "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n",
$arr['body'] .= "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ; 'object' => '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id><link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n"),
'target' => '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id><link>' . XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>',
];
$arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
$arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
if ($tagged[3]) { if ($tagged[3]) {
$arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n"); $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
} }
$arr['object'] .= '</link></object>' . "\n"; $arr['object'] .= '</link></object>' . "\n";
$arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
. DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
$arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
Item::insert($arr); Item::insert($arr);
} }
} }
@ -1233,7 +1229,7 @@ function photos_content(App $a)
$link_item = Post::selectFirst([], ["`resource-id` = ?" . $sql_extra, $datum]); $link_item = Post::selectFirst([], ["`resource-id` = ?" . $sql_extra, $datum]);
if (!empty($link_item['parent']) && !empty($link_item['uid'])) { if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
$condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT]; $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], Item::GRAVITY_COMMENT];
$total = Post::count($condition); $total = Post::count($condition);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
@ -1404,7 +1400,7 @@ function photos_content(App $a)
if (($activity->match($item['verb'], Activity::LIKE) || if (($activity->match($item['verb'], Activity::LIKE) ||
$activity->match($item['verb'], Activity::DISLIKE)) && $activity->match($item['verb'], Activity::DISLIKE)) &&
($item['gravity'] != GRAVITY_PARENT)) { ($item['gravity'] != Item::GRAVITY_PARENT)) {
continue; continue;
} }
@ -1421,25 +1417,25 @@ function photos_content(App $a)
$drop = [ $drop = [
'dropping' => $dropping, 'dropping' => $dropping,
'pagedrop' => false, 'pagedrop' => false,
'select' => DI::l10n()->t('Select'), 'select' => DI::l10n()->t('Select'),
'delete' => DI::l10n()->t('Delete'), 'delete' => DI::l10n()->t('Delete'),
]; ];
$title_e = $item['title']; $title_e = $item['title'];
$body_e = BBCode::convertForUriId($item['uri-id'], $item['body']); $body_e = BBCode::convertForUriId($item['uri-id'], $item['body']);
$comments .= Renderer::replaceMacros($template,[ $comments .= Renderer::replaceMacros($template,[
'$id' => $item['id'], '$id' => $item['id'],
'$profile_url' => $profile_url, '$profile_url' => $profile_url,
'$name' => $item['author-name'], '$name' => $item['author-name'],
'$thumb' => $item['author-avatar'], '$thumb' => $item['author-avatar'],
'$sparkle' => $sparkle, '$sparkle' => $sparkle,
'$title' => $title_e, '$title' => $title_e,
'$body' => $body_e, '$body' => $body_e,
'$ago' => Temporal::getRelativeDate($item['created']), '$ago' => Temporal::getRelativeDate($item['created']),
'$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''), '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
'$drop' => $drop, '$drop' => $drop,
'$comment' => $comment '$comment' => $comment
]); ]);
if (($can_post || Security::canWriteToUserWall($owner_uid))) { if (($can_post || Security::canWriteToUserWall($owner_uid))) {

View file

@ -123,7 +123,7 @@ EOT;
$arr['uid'] = $owner_uid; $arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id']; $arr['contact-id'] = $contact['id'];
$arr['wall'] = $item['wall']; $arr['wall'] = $item['wall'];
$arr['gravity'] = GRAVITY_COMMENT; $arr['gravity'] = Item::GRAVITY_COMMENT;
$arr['parent'] = $item['id']; $arr['parent'] = $item['id'];
$arr['thr-parent'] = $item['uri']; $arr['thr-parent'] = $item['uri'];
$arr['owner-name'] = $item['author-name']; $arr['owner-name'] = $item['author-name'];

View file

@ -36,7 +36,7 @@ use Friendica\Core\Session;
use Friendica\Core\Theme; use Friendica\Core\Theme;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item as ItemModel; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
@ -135,7 +135,7 @@ class Conversation
return; return;
} }
if (!empty($activity['verb']) && $this->activity->match($activity['verb'], $verb) && ($activity['gravity'] != GRAVITY_PARENT)) { if (!empty($activity['verb']) && $this->activity->match($activity['verb'], $verb) && ($activity['gravity'] != Item::GRAVITY_PARENT)) {
$author = [ $author = [
'uid' => 0, 'uid' => 0,
'id' => $activity['author-id'], 'id' => $activity['author-id'],
@ -369,7 +369,7 @@ class Conversation
'$permset' => $this->l10n->t('Permission settings'), '$permset' => $this->l10n->t('Permission settings'),
'$shortpermset' => $this->l10n->t('Permissions'), '$shortpermset' => $this->l10n->t('Permissions'),
'$wall' => $notes_cid ? 0 : 1, '$wall' => $notes_cid ? 0 : 1,
'$posttype' => $notes_cid ? ItemModel::PT_PERSONAL_NOTE : ItemModel::PT_ARTICLE, '$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
'$content' => $x['content'] ?? '', '$content' => $x['content'] ?? '',
'$post_id' => $x['post_id'] ?? '', '$post_id' => $x['post_id'] ?? '',
'$baseurl' => $this->baseURL->get(true), '$baseurl' => $this->baseURL->get(true),
@ -641,7 +641,7 @@ class Conversation
unset($likebuttons['dislike']); unset($likebuttons['dislike']);
} }
$body_html = ItemModel::prepareBody($item, true, $preview); $body_html = Item::prepareBody($item, true, $preview);
[$categories, $folders] = $this->item->determineCategoriesTerms($item, local_user()); [$categories, $folders] = $this->item->determineCategoriesTerms($item, local_user());
@ -698,7 +698,7 @@ class Conversation
'owner_name' => '', 'owner_name' => '',
'owner_url' => '', 'owner_url' => '',
'owner_photo' => $this->baseURL->remove($this->item->getOwnerAvatar($item)), 'owner_photo' => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
'plink' => ItemModel::getPlink($item), 'plink' => Item::getPlink($item),
'edpost' => false, 'edpost' => false,
'pinned' => $pinned, 'pinned' => $pinned,
'isstarred' => 'unstarred', 'isstarred' => 'unstarred',
@ -755,7 +755,7 @@ class Conversation
$item['pagedrop'] = $page_dropping; $item['pagedrop'] = $page_dropping;
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$item_object = new PostObject($item); $item_object = new PostObject($item);
$conv->addParent($item_object); $conv->addParent($item_object);
} }
@ -825,8 +825,8 @@ class Conversation
} }
if (!empty($activity)) { if (!empty($activity)) {
if (($row['gravity'] == GRAVITY_PARENT)) { if (($row['gravity'] == Item::GRAVITY_PARENT)) {
$row['post-reason'] = ItemModel::PR_ANNOUNCEMENT; $row['post-reason'] = Item::PR_ANNOUNCEMENT;
$row = array_merge($row, $activity); $row = array_merge($row, $activity);
$contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']); $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
@ -834,32 +834,32 @@ class Conversation
$row['causer-link'] = $contact['url']; $row['causer-link'] = $contact['url'];
$row['causer-avatar'] = $contact['thumb']; $row['causer-avatar'] = $contact['thumb'];
$row['causer-name'] = $contact['name']; $row['causer-name'] = $contact['name'];
} elseif (($row['gravity'] == GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) && } elseif (($row['gravity'] == Item::GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
($row['author-id'] == $activity['causer-id'])) { ($row['author-id'] == $activity['causer-id'])) {
return $row; return $row;
} }
} }
switch ($row['post-reason']) { switch ($row['post-reason']) {
case ItemModel::PR_TO: case Item::PR_TO:
$row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'to')]; $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'to')];
break; break;
case ItemModel::PR_CC: case Item::PR_CC:
$row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'cc')]; $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'cc')];
break; break;
case ItemModel::PR_BTO: case Item::PR_BTO:
$row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bto')]; $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bto')];
break; break;
case ItemModel::PR_BCC: case Item::PR_BCC:
$row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bcc')]; $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bcc')];
break; break;
case ItemModel::PR_FOLLOWER: case Item::PR_FOLLOWER:
$row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])]; $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])];
break; break;
case ItemModel::PR_TAG: case Item::PR_TAG:
$row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')];
break; break;
case ItemModel::PR_ANNOUNCEMENT: case Item::PR_ANNOUNCEMENT:
if (!empty($row['causer-id']) && $this->pConfig->get(local_user(), 'system', 'display_resharer')) { if (!empty($row['causer-id']) && $this->pConfig->get(local_user(), 'system', 'display_resharer')) {
$row['owner-id'] = $row['causer-id']; $row['owner-id'] = $row['causer-id'];
$row['owner-link'] = $row['causer-link']; $row['owner-link'] = $row['causer-link'];
@ -867,41 +867,41 @@ class Conversation
$row['owner-name'] = $row['causer-name']; $row['owner-name'] = $row['causer-name'];
} }
if (in_array($row['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]) && !empty($row['causer-id'])) { if (in_array($row['gravity'], [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]) && !empty($row['causer-id'])) {
$causer = ['uid' => 0, 'id' => $row['causer-id'], 'network' => $row['causer-network'], 'url' => $row['causer-link']]; $causer = ['uid' => 0, 'id' => $row['causer-id'], 'network' => $row['causer-network'], 'url' => $row['causer-link']];
$row['reshared'] = $this->l10n->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>'); $row['reshared'] = $this->l10n->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>');
} }
$row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Reshared') : $this->l10n->t('Reshared by %s <%s>', $row['causer-name'], $row['causer-link']))]; $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Reshared') : $this->l10n->t('Reshared by %s <%s>', $row['causer-name'], $row['causer-link']))];
break; break;
case ItemModel::PR_COMMENT: case Item::PR_COMMENT:
$row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])]; $row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])];
break; break;
case ItemModel::PR_STORED: case Item::PR_STORED:
$row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')]; $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')];
break; break;
case ItemModel::PR_GLOBAL: case Item::PR_GLOBAL:
$row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')]; $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')];
break; break;
case ItemModel::PR_RELAY: case Item::PR_RELAY:
$row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Sent via an relay server') : $this->l10n->t('Sent via the relay server %s <%s>', $row['causer-name'], $row['causer-link']))]; $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Sent via an relay server') : $this->l10n->t('Sent via the relay server %s <%s>', $row['causer-name'], $row['causer-link']))];
break; break;
case ItemModel::PR_FETCHED: case Item::PR_FETCHED:
$row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Fetched') : $this->l10n->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))]; $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Fetched') : $this->l10n->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))];
break; break;
case ItemModel::PR_COMPLETION: case Item::PR_COMPLETION:
$row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')]; $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')];
break; break;
case ItemModel::PR_DIRECT: case Item::PR_DIRECT:
$row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')]; $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')];
break; break;
case ItemModel::PR_ACTIVITY: case Item::PR_ACTIVITY:
$row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')]; $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')];
break; break;
case ItemModel::PR_DISTRIBUTE: case Item::PR_DISTRIBUTE:
$row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')]; $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')];
break; break;
case ItemModel::PR_PUSHED: case Item::PR_PUSHED:
$row['direction'] = ['direction' => 1, 'title' => $this->l10n->t('Pushed to us')]; $row['direction'] = ['direction' => 1, 'title' => $this->l10n->t('Pushed to us')];
break; break;
} }
@ -941,7 +941,7 @@ class Conversation
$activitycounter = []; $activitycounter = [];
foreach ($parents as $parent) { foreach ($parents as $parent) {
if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) { if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == Item::GRAVITY_ACTIVITY)) {
$uriid = $parent['thr-parent-id']; $uriid = $parent['thr-parent-id'];
if (!empty($parent['author-id'])) { if (!empty($parent['author-id'])) {
$activities[$uriid] = ['causer-id' => $parent['author-id']]; $activities[$uriid] = ['causer-id' => $parent['author-id']];
@ -979,7 +979,7 @@ class Conversation
$params = ['order' => ['uri-id' => true, 'uid' => true]]; $params = ['order' => ['uri-id' => true, 'uid' => true]];
$thread_items = Post::selectForUser($uid, array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params); $thread_items = Post::selectForUser($uid, array_merge(Item::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
$items = []; $items = [];
@ -993,10 +993,10 @@ class Conversation
} }
if ($max_comments > 0) { if ($max_comments > 0) {
if (($row['gravity'] == GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) { if (($row['gravity'] == Item::GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
continue; continue;
} }
if (($row['gravity'] == GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) { if (($row['gravity'] == Item::GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) {
continue; continue;
} }
} }
@ -1025,7 +1025,7 @@ class Conversation
$this->profiler->startRecording('rendering'); $this->profiler->startRecording('rendering');
$children = []; $children = [];
foreach ($item_list as $i => $item) { foreach ($item_list as $i => $item) {
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
if ($recursive) { if ($recursive) {
// Fallback to parent-uri if thr-parent is not set // Fallback to parent-uri if thr-parent is not set
$thr_parent = $item['thr-parent-id']; $thr_parent = $item['thr-parent-id'];
@ -1182,7 +1182,7 @@ class Conversation
// Extract the top level items // Extract the top level items
foreach ($item_array as $item) { foreach ($item_array as $item) {
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$parents[] = $item; $parents[] = $item;
} }
} }

View file

@ -331,7 +331,7 @@ class Item
$sub_link = $contact_url = $pm_url = $status_link = ''; $sub_link = $contact_url = $pm_url = $status_link = '';
$photos_link = $posts_link = $block_link = $ignore_link = ''; $photos_link = $posts_link = $block_link = $ignore_link = '';
if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) { if (local_user() && local_user() == $item['uid'] && $item['gravity'] == ModelItem::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;'; $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
} }
@ -470,7 +470,7 @@ class Item
} }
$item['inform'] .= 'cid:' . $contact['id']; $item['inform'] .= 'cid:' . $contact['id'];
if (($item['gravity'] == GRAVITY_COMMENT) || empty($contact['cid']) || ($contact['contact-type'] != Contact::TYPE_COMMUNITY)) { if (($item['gravity'] == ModelItem::GRAVITY_COMMENT) || empty($contact['cid']) || ($contact['contact-type'] != Contact::TYPE_COMMUNITY)) {
continue; continue;
} }
@ -492,7 +492,7 @@ class Item
} }
Logger::info('Got inform', ['inform' => $item['inform']]); Logger::info('Got inform', ['inform' => $item['inform']]);
if (($item['gravity'] == GRAVITY_PARENT) && !empty($forum_contact) && ($private_forum || $only_to_forum)) { if (($item['gravity'] == ModelItem::GRAVITY_PARENT) && !empty($forum_contact) && ($private_forum || $only_to_forum)) {
// we tagged a forum in a top level post. Now we change the post // we tagged a forum in a top level post. Now we change the post
$item['private'] = $private_forum ? ModelItem::PRIVATE : ModelItem::UNLISTED; $item['private'] = $private_forum ? ModelItem::PRIVATE : ModelItem::UNLISTED;
@ -510,7 +510,7 @@ class Item
$item['allow_cid'] = ''; $item['allow_cid'] = '';
$item['allow_gid'] = ''; $item['allow_gid'] = '';
} }
} elseif ($setPermissions && ($item['gravity'] == GRAVITY_PARENT)) { } elseif ($setPermissions && ($item['gravity'] == ModelItem::GRAVITY_PARENT)) {
if (empty($receivers)) { if (empty($receivers)) {
// For security reasons direct posts without any receiver will be posts to yourself // For security reasons direct posts without any receiver will be posts to yourself
$self = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]); $self = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);

View file

@ -22,6 +22,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -139,7 +140,7 @@ class Protocol
// create a follow slap // create a follow slap
$item = [ $item = [
'verb' => Activity::FOLLOW, 'verb' => Activity::FOLLOW,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'follow' => $contact['url'], 'follow' => $contact['url'],
'body' => '', 'body' => '',
'title' => '', 'title' => '',
@ -191,14 +192,16 @@ class Protocol
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) { if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create an unfollow slap // create an unfollow slap
$item = []; $item = [
$item['verb'] = Activity::O_UNFOLLOW; 'verb' => Activity::O_UNFOLLOW,
$item['gravity'] = GRAVITY_ACTIVITY; 'gravity' => Item::GRAVITY_ACTIVITY,
$item['follow'] = $contact['url']; 'follow' => $contact['url'],
$item['body'] = ''; 'body' => '',
$item['title'] = ''; 'title' => '',
$item['guid'] = ''; 'guid' => '',
$item['uri-id'] = 0; 'uri-id' => 0,
];
$slap = OStatus::salmon($item, $user); $slap = OStatus::salmon($item, $user);
if (empty($contact['notify'])) { if (empty($contact['notify'])) {

View file

@ -48,19 +48,19 @@ class Renderer
* beyond are used. * beyond are used.
*/ */
public static $theme = [ public static $theme = [
'videowidth' => 425, 'videowidth' => 425,
'videoheight' => 350, 'videoheight' => 350,
'stylesheet' => '', 'stylesheet' => '',
'template_engine' => 'smarty3', 'template_engine' => 'smarty3',
]; ];
private static $ldelim = [ private static $ldelim = [
'internal' => '', 'internal' => '',
'smarty3' => '{{' 'smarty3' => '{{'
]; ];
private static $rdelim = [ private static $rdelim = [
'internal' => '', 'internal' => '',
'smarty3' => '}}' 'smarty3' => '}}'
]; ];
/** /**
@ -101,10 +101,10 @@ class Renderer
* @param string $file Template to load. * @param string $file Template to load.
* @param string $subDir Subdirectory (Optional) * @param string $subDir Subdirectory (Optional)
* *
* @return string template. * @return string Template
* @throws ServiceUnavailableException * @throws ServiceUnavailableException
*/ */
public static function getMarkupTemplate($file, $subDir = '') public static function getMarkupTemplate(string $file, string $subDir = ''): string
{ {
DI::profiler()->startRecording('file'); DI::profiler()->startRecording('file');
$t = self::getTemplateEngine(); $t = self::getTemplateEngine();
@ -128,9 +128,11 @@ class Renderer
* Register template engine class * Register template engine class
* *
* @param string $class * @param string $class
*
* @return void
* @throws ServiceUnavailableException * @throws ServiceUnavailableException
*/ */
public static function registerTemplateEngine($class) public static function registerTemplateEngine(string $class)
{ {
$v = get_class_vars($class); $v = get_class_vars($class);
@ -156,7 +158,7 @@ class Renderer
* @return TemplateEngine Template Engine instance * @return TemplateEngine Template Engine instance
* @throws ServiceUnavailableException * @throws ServiceUnavailableException
*/ */
public static function getTemplateEngine() public static function getTemplateEngine(): TemplateEngine
{ {
$template_engine = (self::$theme['template_engine'] ?? '') ?: 'smarty3'; $template_engine = (self::$theme['template_engine'] ?? '') ?: 'smarty3';
@ -185,7 +187,7 @@ class Renderer
* *
* @return string the active template engine * @return string the active template engine
*/ */
public static function getActiveTemplateEngine() public static function getActiveTemplateEngine(): string
{ {
return self::$theme['template_engine']; return self::$theme['template_engine'];
} }
@ -194,8 +196,10 @@ class Renderer
* sets the active template engine * sets the active template engine
* *
* @param string $engine the template engine (default is Smarty3) * @param string $engine the template engine (default is Smarty3)
*
* @return void
*/ */
public static function setActiveTemplateEngine($engine = 'smarty3') public static function setActiveTemplateEngine(string $engine = 'smarty3')
{ {
self::$theme['template_engine'] = $engine; self::$theme['template_engine'] = $engine;
} }
@ -211,7 +215,7 @@ class Renderer
* *
* @return string the right delimiter * @return string the right delimiter
*/ */
public static function getTemplateLeftDelimiter($engine = 'smarty3') public static function getTemplateLeftDelimiter(string $engine = 'smarty3'): string
{ {
return self::$ldelim[$engine]; return self::$ldelim[$engine];
} }
@ -227,7 +231,7 @@ class Renderer
* *
* @return string the left delimiter * @return string the left delimiter
*/ */
public static function getTemplateRightDelimiter($engine = 'smarty3') public static function getTemplateRightDelimiter(string $engine = 'smarty3'): string
{ {
return self::$rdelim[$engine]; return self::$rdelim[$engine];
} }

View file

@ -563,7 +563,7 @@ class PostUpdate
$items = DBA::p("SELECT `item`.`id`, `item`.`verb` AS `item-verb`, `item-content`.`verb`, `item-activity`.`activity` $items = DBA::p("SELECT `item`.`id`, `item`.`verb` AS `item-verb`, `item-content`.`verb`, `item-activity`.`activity`
FROM `item` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` FROM `item` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id` AND `item`.`gravity` = ? LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id` AND `item`.`gravity` = ?
WHERE `item`.`id` >= ? AND `item`.`vid` IS NULL ORDER BY `item`.`id` LIMIT 10000", GRAVITY_ACTIVITY, $id); WHERE `item`.`id` >= ? AND `item`.`vid` IS NULL ORDER BY `item`.`id` LIMIT 10000", Item::GRAVITY_ACTIVITY, $id);
if (DBA::errorNo() != 0) { if (DBA::errorNo() != 0) {
Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]); Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);

View file

@ -23,6 +23,7 @@ namespace Friendica\Factory\Api\Friendica;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -62,7 +63,7 @@ class Activities extends BaseFactory
'announce' => [], 'announce' => [],
]; ];
$condition = ['uid' => $uid, 'thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY]; $condition = ['uid' => $uid, 'thr-parent-id' => $uriId, 'gravity' => Item::GRAVITY_ACTIVITY];
$ret = Post::selectForUser($uid, ['author-id', 'verb'], $condition); $ret = Post::selectForUser($uid, ['author-id', 'verb'], $condition);

View file

@ -25,6 +25,7 @@ use Friendica\App\BaseURL;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Factory\Api\Twitter\Status; use Friendica\Factory\Api\Twitter\Status;
use Friendica\Model\Item;
use Friendica\Model\Photo as ModelPhoto; use Friendica\Model\Photo as ModelPhoto;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -116,7 +117,7 @@ class Photo extends BaseFactory
// retrieve comments on photo // retrieve comments on photo
$condition = ["`parent` = ? AND `uid` = ? AND `gravity` IN (?, ?)", $condition = ["`parent` = ? AND `uid` = ? AND `gravity` IN (?, ?)",
$item['parent'], $uid, GRAVITY_PARENT, GRAVITY_COMMENT]; $item['parent'], $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT];
$statuses = Post::selectForUser($uid, [], $condition); $statuses = Post::selectForUser($uid, [], $condition);

View file

@ -24,6 +24,7 @@ namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory; use Friendica\BaseFactory;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
@ -69,7 +70,7 @@ class ScheduledStatus extends BaseFactory
$media_attachments[] = DI::mstdnAttachment()->createFromPhoto($id); $media_attachments[] = DI::mstdnAttachment()->createFromPhoto($id);
} }
if (isset($parameters['item']['thr-parent']) && ($parameters['item']['gravity'] ?? GRAVITY_PARENT != GRAVITY_PARENT)) { if (isset($parameters['item']['thr-parent']) && ($parameters['item']['gravity'] ?? Item::GRAVITY_PARENT != Item::GRAVITY_PARENT)) {
$in_reply_to_id = ItemURI::getIdByURI($parameters['item']['thr-parent']); $in_reply_to_id = ItemURI::getIdByURI($parameters['item']['thr-parent']);
} else { } else {
$in_reply_to_id = null; $in_reply_to_id = null;

View file

@ -26,6 +26,7 @@ use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag as TagModel; use Friendica\Model\Tag as TagModel;
use Friendica\Model\Verb; use Friendica\Model\Verb;
@ -94,19 +95,19 @@ class Status extends BaseFactory
$count_announce = Post::countPosts([ $count_announce = Post::countPosts([
'thr-parent-id' => $uriId, 'thr-parent-id' => $uriId,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::ANNOUNCE), 'vid' => Verb::getID(Activity::ANNOUNCE),
'deleted' => false 'deleted' => false
], []); ], []);
$count_like = Post::countPosts([ $count_like = Post::countPosts([
'thr-parent-id' => $uriId, 'thr-parent-id' => $uriId,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::LIKE), 'vid' => Verb::getID(Activity::LIKE),
'deleted' => false 'deleted' => false
], []); ], []);
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts( $counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], []), Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => Item::GRAVITY_COMMENT, 'deleted' => false], []),
$count_announce, $count_announce,
$count_like $count_like
); );
@ -115,7 +116,7 @@ class Status extends BaseFactory
'thr-parent-id' => $uriId, 'thr-parent-id' => $uriId,
'uid' => $uid, 'uid' => $uid,
'origin' => true, 'origin' => true,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::LIKE), 'vid' => Verb::getID(Activity::LIKE),
'deleted' => false 'deleted' => false
]); ]);
@ -123,7 +124,7 @@ class Status extends BaseFactory
'thr-parent-id' => $uriId, 'thr-parent-id' => $uriId,
'uid' => $uid, 'uid' => $uid,
'origin' => true, 'origin' => true,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::ANNOUNCE), 'vid' => Verb::getID(Activity::ANNOUNCE),
'deleted' => false 'deleted' => false
]); ]);
@ -131,7 +132,7 @@ class Status extends BaseFactory
$origin_like, $origin_like,
$origin_announce, $origin_announce,
Post\ThreadUser::getIgnored($uriId, $uid), Post\ThreadUser::getIgnored($uriId, $uid),
(bool)($item['starred'] && ($item['gravity'] == GRAVITY_PARENT)), (bool)($item['starred'] && ($item['gravity'] == Item::GRAVITY_PARENT)),
$item['featured'] $item['featured']
); );

View file

@ -128,7 +128,7 @@ class Status extends BaseFactory
$owner = $this->twitterUser->createFromContactId($item['owner-id'], $uid, true); $owner = $this->twitterUser->createFromContactId($item['owner-id'], $uid, true);
} }
$friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]); $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
$text = ''; $text = '';
$title = ''; $title = '';
@ -162,7 +162,7 @@ class Status extends BaseFactory
'thr-parent-id' => $item['uri-id'], 'thr-parent-id' => $item['uri-id'],
'uid' => $uid, 'uid' => $uid,
'origin' => true, 'origin' => true,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::LIKE), 'vid' => Verb::getID(Activity::LIKE),
'deleted' => false 'deleted' => false
]); ]);

View file

@ -69,7 +69,7 @@ class User extends BaseFactory
if (!$skip_status) { if (!$skip_status) {
$post = Post::selectFirstPost(['uri-id'], $post = Post::selectFirstPost(['uri-id'],
['author-id' => $publicContact['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_PARENT], 'private' => [Item::PUBLIC, Item::UNLISTED]], ['author-id' => $publicContact['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_PARENT], 'private' => [Item::PUBLIC, Item::UNLISTED]],
['order' => ['uri-id' => true]]); ['order' => ['uri-id' => true]]);
if (!empty($post['uri-id'])) { if (!empty($post['uri-id'])) {
$status = $this->status->createFromUriId($post['uri-id'], $uid)->toArray(); $status = $this->status->createFromUriId($post['uri-id'], $uid)->toArray();

View file

@ -28,6 +28,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\Probe; use Friendica\Network\Probe;
@ -495,13 +496,13 @@ class APContact
private static function getStatusesCount(array $owner): int private static function getStatusesCount(array $owner): int
{ {
$condition = [ $condition = [
'private' => [Item::PUBLIC, Item::UNLISTED], 'private' => [Item::PUBLIC, Item::UNLISTED],
'author-id' => Contact::getIdForURL($owner['url'], 0, false), 'author-id' => Contact::getIdForURL($owner['url'], 0, false),
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'parent-network' => Protocol::FEDERATED, 'parent-network' => Protocol::FEDERATED,
'deleted' => false, 'deleted' => false,
'visible' => true 'visible' => true,
]; ];
$count = Post::countPosts($condition); $count = Post::countPosts($condition);

View file

@ -1506,10 +1506,10 @@ class Contact
if ($thread_mode) { if ($thread_mode) {
$condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql, $condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
$cid, GRAVITY_PARENT, $cid, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()]; $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()];
} else { } else {
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql, $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
$cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, local_user()];
} }
if (!empty($parent)) { if (!empty($parent)) {

View file

@ -26,6 +26,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -105,27 +106,27 @@ class FContact
$interacted = DBA::count('contact-relation', ["`cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]); $interacted = DBA::count('contact-relation', ["`cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
$interacting = DBA::count('contact-relation', ["`relation-cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]); $interacting = DBA::count('contact-relation', ["`relation-cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
$posts = DBA::count('post', ['author-id' => $contact['id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]); $posts = DBA::count('post', ['author-id' => $contact['id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]]);
} }
$fields = [ $fields = [
'name' => $arr['name'], 'name' => $arr['name'],
'photo' => $arr['photo'], 'photo' => $arr['photo'],
'request' => $arr['request'], 'request' => $arr['request'],
'nick' => $arr['nick'], 'nick' => $arr['nick'],
'addr' => strtolower($arr['addr']), 'addr' => strtolower($arr['addr']),
'guid' => $arr['guid'], 'guid' => $arr['guid'],
'batch' => $arr['batch'], 'batch' => $arr['batch'],
'notify' => $arr['notify'], 'notify' => $arr['notify'],
'poll' => $arr['poll'], 'poll' => $arr['poll'],
'confirm' => $arr['confirm'], 'confirm' => $arr['confirm'],
'alias' => $arr['alias'], 'alias' => $arr['alias'],
'pubkey' => $arr['pubkey'], 'pubkey' => $arr['pubkey'],
'uri-id' => $uriid, 'uri-id' => $uriid,
'interacting_count' => $interacting ?? 0, 'interacting_count' => $interacting ?? 0,
'interacted_count' => $interacted ?? 0, 'interacted_count' => $interacted ?? 0,
'post_count' => $posts ?? 0, 'post_count' => $posts ?? 0,
'updated' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(),
]; ];
if (empty($fcontact['created'])) { if (empty($fcontact['created'])) {

View file

@ -146,6 +146,12 @@ class Item
const PRIVATE = 1; const PRIVATE = 1;
const UNLISTED = 2; const UNLISTED = 2;
// Item weight for query ordering
const GRAVITY_PARENT = 0;
const GRAVITY_ACTIVITY = 3;
const GRAVITY_COMMENT = 6;
const GRAVITY_UNKNOWN = 9;
/** /**
* Update existing item entries * Update existing item entries
* *
@ -356,7 +362,7 @@ class Item
Post\DeliveryData::delete($item['uri-id']); Post\DeliveryData::delete($item['uri-id']);
// If it's the parent of a comment thread, kill all the kids // If it's the parent of a comment thread, kill all the kids
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
self::markForDeletion(['parent' => $item['parent'], 'deleted' => false], $priority); self::markForDeletion(['parent' => $item['parent'], 'deleted' => false], $priority);
} }
@ -463,7 +469,7 @@ class Item
} }
} }
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
if (Contact::isSharingByURL($item['owner-link'], $item['uid'], true)) { if (Contact::isSharingByURL($item['owner-link'], $item['uid'], true)) {
$contact_id = Contact::getIdForURL($item['owner-link'], $item['uid']); $contact_id = Contact::getIdForURL($item['owner-link'], $item['uid']);
} else { } else {
@ -714,7 +720,7 @@ class Item
return 0; return 0;
} }
if ($thread_parent['gravity'] == GRAVITY_PARENT) { if ($thread_parent['gravity'] == Item::GRAVITY_PARENT) {
return $uriid; return $uriid;
} }
@ -791,17 +797,17 @@ class Item
if (isset($item['gravity'])) { if (isset($item['gravity'])) {
return intval($item['gravity']); return intval($item['gravity']);
} elseif ($item['parent-uri-id'] === $item['uri-id']) { } elseif ($item['parent-uri-id'] === $item['uri-id']) {
return GRAVITY_PARENT; return self::GRAVITY_PARENT;
} elseif ($activity->match($item['verb'], Activity::POST)) { } elseif ($activity->match($item['verb'], Activity::POST)) {
return GRAVITY_COMMENT; return self::GRAVITY_COMMENT;
} elseif ($activity->match($item['verb'], Activity::FOLLOW)) { } elseif ($activity->match($item['verb'], Activity::FOLLOW)) {
return GRAVITY_ACTIVITY; return self::GRAVITY_ACTIVITY;
} elseif ($activity->match($item['verb'], Activity::ANNOUNCE)) { } elseif ($activity->match($item['verb'], Activity::ANNOUNCE)) {
return GRAVITY_ACTIVITY; return self::GRAVITY_ACTIVITY;
} }
Logger::info('Unknown gravity for verb', ['verb' => $item['verb']]); Logger::info('Unknown gravity for verb', ['verb' => $item['verb']]);
return GRAVITY_UNKNOWN; // Should not happen return self::GRAVITY_UNKNOWN; // Should not happen
} }
/** /**
@ -965,7 +971,7 @@ class Item
return 0; return 0;
} }
if ($item['gravity'] !== GRAVITY_PARENT) { if ($item['gravity'] !== self::GRAVITY_PARENT) {
$toplevel_parent = self::getTopLevelParent($item); $toplevel_parent = self::getTopLevelParent($item);
if (empty($toplevel_parent)) { if (empty($toplevel_parent)) {
return 0; return 0;
@ -1178,7 +1184,7 @@ class Item
Post::insert($item['uri-id'], $item); Post::insert($item['uri-id'], $item);
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
Post\Thread::insert($item['uri-id'], $item); Post\Thread::insert($item['uri-id'], $item);
} }
@ -1187,7 +1193,7 @@ class Item
} }
// Create Diaspora signature // Create Diaspora signature
if ($item['origin'] && empty($item['diaspora_signed_text']) && ($item['gravity'] != GRAVITY_PARENT)) { if ($item['origin'] && empty($item['diaspora_signed_text']) && ($item['gravity'] != self::GRAVITY_PARENT)) {
$signed = Diaspora::createCommentSignature($item); $signed = Diaspora::createCommentSignature($item);
if (!empty($signed)) { if (!empty($signed)) {
$item['diaspora_signed_text'] = json_encode($signed); $item['diaspora_signed_text'] = json_encode($signed);
@ -1227,7 +1233,7 @@ class Item
return 0; return 0;
} }
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
$item['post-user-id'] = $post_user_id; $item['post-user-id'] = $post_user_id;
Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item);
} }
@ -1245,7 +1251,7 @@ class Item
// update the commented timestamp on the parent // update the commented timestamp on the parent
if (DI::config()->get('system', 'like_no_comment')) { if (DI::config()->get('system', 'like_no_comment')) {
// Update when it is a comment // Update when it is a comment
$update_commented = in_array($posted_item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]); $update_commented = in_array($posted_item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]);
} else { } else {
// Update when it isn't a follow or tag verb // Update when it isn't a follow or tag verb
$update_commented = !in_array($posted_item['verb'], [Activity::FOLLOW, Activity::TAG]); $update_commented = !in_array($posted_item['verb'], [Activity::FOLLOW, Activity::TAG]);
@ -1269,7 +1275,7 @@ class Item
} }
if ($notify) { if ($notify) {
if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) { if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == self::GRAVITY_COMMENT)) {
Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']); Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
} }
Hook::callAll('post_local_end', $posted_item); Hook::callAll('post_local_end', $posted_item);
@ -1277,7 +1283,7 @@ class Item
Hook::callAll('post_remote_end', $posted_item); Hook::callAll('post_remote_end', $posted_item);
} }
if ($posted_item['gravity'] === GRAVITY_PARENT) { if ($posted_item['gravity'] === self::GRAVITY_PARENT) {
self::addShadow($post_user_id); self::addShadow($post_user_id);
} else { } else {
self::addShadowPost($post_user_id); self::addShadowPost($post_user_id);
@ -1312,7 +1318,7 @@ class Item
} }
// Fill the cache with the rendered content. // Fill the cache with the rendered content.
if (in_array($posted_item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]) && ($posted_item['uid'] == 0)) { if (in_array($posted_item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) && ($posted_item['uid'] == 0)) {
self::updateDisplayCache($posted_item['uri-id']); self::updateDisplayCache($posted_item['uri-id']);
} }
@ -1328,7 +1334,7 @@ class Item
*/ */
public static function getPostReason(array $item): int public static function getPostReason(array $item): int
{ {
$actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id']; $actor = ($item['gravity'] == self::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
if (empty($item['origin']) && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) { if (empty($item['origin']) && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
return self::PR_FOLLOWER; return self::PR_FOLLOWER;
} }
@ -1409,7 +1415,7 @@ class Item
*/ */
private static function distributeByTags(array $item) private static function distributeByTags(array $item)
{ {
if (($item['uid'] != 0) || ($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], Protocol::FEDERATED)) { if (($item['uid'] != 0) || ($item['gravity'] != self::GRAVITY_PARENT) || !in_array($item['network'], Protocol::FEDERATED)) {
return; return;
} }
@ -1535,7 +1541,7 @@ class Item
return 0; return 0;
} }
if (($uid != 0) && ($item['gravity'] == GRAVITY_PARENT)) { if (($uid != 0) && ($item['gravity'] == self::GRAVITY_PARENT)) {
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
if (($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY) && !Tag::isMentioned($uri_id, $owner['url'])) { if (($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY) && !Tag::isMentioned($uri_id, $owner['url'])) {
Logger::info('Target user is a forum but is not mentioned here, thread will not be stored', ['uid' => $uid, 'uri-id' => $uri_id]); Logger::info('Target user is a forum but is not mentioned here, thread will not be stored', ['uid' => $uid, 'uri-id' => $uri_id]);
@ -1552,13 +1558,13 @@ class Item
$item = array_merge($item, $fields); $item = array_merge($item, $fields);
if (($uid != 0) && Contact::isSharing(($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'], $uid)) { if (($uid != 0) && Contact::isSharing(($item['gravity'] == Item::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'], $uid)) {
$item['post-reason'] = self::PR_FOLLOWER; $item['post-reason'] = self::PR_FOLLOWER;
} }
$is_reshare = ($item['gravity'] == GRAVITY_ACTIVITY) && ($item['verb'] == Activity::ANNOUNCE); $is_reshare = ($item['gravity'] == self::GRAVITY_ACTIVITY) && ($item['verb'] == Activity::ANNOUNCE);
if (($uid != 0) && (($item['gravity'] == GRAVITY_PARENT) || $is_reshare) && if (($uid != 0) && (($item['gravity'] == self::GRAVITY_PARENT) || $is_reshare) &&
DI::pConfig()->get($uid, 'system', 'accept_only_sharer') == self::COMPLETION_NONE && DI::pConfig()->get($uid, 'system', 'accept_only_sharer') == self::COMPLETION_NONE &&
!in_array($item['post-reason'], [self::PR_FOLLOWER, self::PR_TAG, self::PR_TO, self::PR_CC])) { !in_array($item['post-reason'], [self::PR_FOLLOWER, self::PR_TAG, self::PR_TO, self::PR_CC])) {
Logger::info('Contact is not a follower, thread will not be stored', ['author' => $item['author-link'], 'uid' => $uid, 'uri-id' => $uri_id, 'post-reason' => $item['post-reason']]); Logger::info('Contact is not a follower, thread will not be stored', ['author' => $item['author-link'], 'uid' => $uid, 'uri-id' => $uri_id, 'post-reason' => $item['post-reason']]);
@ -1567,7 +1573,7 @@ class Item
$causer = $item['causer-id'] ?: $item['author-id']; $causer = $item['causer-id'] ?: $item['author-id'];
if (($uri_id != $item['parent-uri-id']) && ($item['gravity'] == GRAVITY_COMMENT) && !Post::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) { if (($uri_id != $item['parent-uri-id']) && ($item['gravity'] == self::GRAVITY_COMMENT) && !Post::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) {
if (!self::fetchParent($item['parent-uri-id'], $uid, $causer)) { if (!self::fetchParent($item['parent-uri-id'], $uid, $causer)) {
Logger::info('Parent post had not been added', ['uri-id' => $item['parent-uri-id'], 'uid' => $uid, 'causer' => $causer]); Logger::info('Parent post had not been added', ['uri-id' => $item['parent-uri-id'], 'uid' => $uid, 'causer' => $causer]);
return 0; return 0;
@ -1708,7 +1714,7 @@ class Item
$item['contact-id'] = self::contactId($item); $item['contact-id'] = self::contactId($item);
$notify = false; $notify = false;
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]); $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$notify = self::isRemoteSelf($contact, $item); $notify = self::isRemoteSelf($contact, $item);
@ -1738,7 +1744,7 @@ class Item
private static function addShadow(int $itemid) private static function addShadow(int $itemid)
{ {
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id']; $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
$condition = ['id' => $itemid, 'gravity' => GRAVITY_PARENT]; $condition = ['id' => $itemid, 'gravity' => self::GRAVITY_PARENT];
$item = Post::selectFirst($fields, $condition); $item = Post::selectFirst($fields, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -1806,7 +1812,7 @@ class Item
} }
// Is it a toplevel post? // Is it a toplevel post?
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
self::addShadow($itemid); self::addShadow($itemid);
return; return;
} }
@ -1868,7 +1874,7 @@ class Item
return $item['language']; return $item['language'];
} }
if (!in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]) || empty($item['body'])) { if (!in_array($item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) || empty($item['body'])) {
return ''; return '';
} }
@ -2148,13 +2154,13 @@ class Item
return false; return false;
} }
$item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'origin' => false]); $item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id, 'gravity' => [self::GRAVITY_PARENT, self::GRAVITY_COMMENT], 'origin' => false]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
Logger::debug('Post is an activity or origin or not found at all, quitting here.', ['id' => $item_id]); Logger::debug('Post is an activity or origin or not found at all, quitting here.', ['id' => $item_id]);
return false; return false;
} }
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == self::GRAVITY_PARENT) {
if (Tag::isMentioned($item['uri-id'], $owner['url'])) { if (Tag::isMentioned($item['uri-id'], $owner['url'])) {
Logger::info('Mention found in tag.', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); Logger::info('Mention found in tag.', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
} else { } else {
@ -2199,7 +2205,7 @@ class Item
*/ */
private static function autoReshare(array $item) private static function autoReshare(array $item)
{ {
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != self::GRAVITY_PARENT) {
return; return;
} }
@ -2460,7 +2466,7 @@ class Item
} }
$condition = ["`uid` = ? AND NOT `deleted` AND `gravity` = ?", $condition = ["`uid` = ? AND NOT `deleted` AND `gravity` = ?",
$uid, GRAVITY_PARENT]; $uid, self::GRAVITY_PARENT];
/* /*
* $expire_network_only = save your own wall posts * $expire_network_only = save your own wall posts
@ -2667,7 +2673,7 @@ class Item
$vids = Verb::getID($activity); $vids = Verb::getID($activity);
} }
$condition = ['vid' => $vids, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY, $condition = ['vid' => $vids, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
'author-id' => $author_id, 'uid' => $item['uid'], 'thr-parent-id' => $uri_id]; 'author-id' => $author_id, 'uid' => $item['uid'], 'thr-parent-id' => $uri_id];
$like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition); $like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition);
@ -2721,7 +2727,7 @@ class Item
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'protocol' => Conversation::PARCEL_DIRECT, 'protocol' => Conversation::PARCEL_DIRECT,
'direction' => Conversation::PUSH, 'direction' => Conversation::PUSH,
'gravity' => GRAVITY_ACTIVITY, 'gravity' => self::GRAVITY_ACTIVITY,
'parent' => $item['id'], 'parent' => $item['id'],
'thr-parent' => $item['uri'], 'thr-parent' => $item['uri'],
'owner-id' => $author_id, 'owner-id' => $author_id,
@ -2846,9 +2852,9 @@ class Item
return $l10n->t('event'); return $l10n->t('event');
} elseif (!empty($item['resource-id'])) { } elseif (!empty($item['resource-id'])) {
return $l10n->t('photo'); return $l10n->t('photo');
} elseif ($item['gravity'] == GRAVITY_ACTIVITY) { } elseif ($item['gravity'] == self::GRAVITY_ACTIVITY) {
return $l10n->t('activity'); return $l10n->t('activity');
} elseif ($item['gravity'] == GRAVITY_COMMENT) { } elseif ($item['gravity'] == self::GRAVITY_COMMENT) {
return $l10n->t('comment'); return $l10n->t('comment');
} }
@ -3593,7 +3599,7 @@ class Item
return false; return false;
} }
if (!empty($item['causer-id']) && ($item['gravity'] === GRAVITY_PARENT) && Contact\User::isIgnored($item['causer-id'], $user_id)) { if (!empty($item['causer-id']) && ($item['gravity'] === self::GRAVITY_PARENT) && Contact\User::isIgnored($item['causer-id'], $user_id)) {
Logger::notice('Causer is ignored by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]); Logger::notice('Causer is ignored by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false; return false;
} }

View file

@ -25,6 +25,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use stdClass; use stdClass;
/** /**
@ -62,8 +63,8 @@ class Nodeinfo
$logger->info('user statistics', $userStats); $logger->info('user statistics', $userStats);
$posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]); $posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
$comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", GRAVITY_COMMENT]); $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]);
$config->set('nodeinfo', 'local_posts', $posts); $config->set('nodeinfo', 'local_posts', $posts);
$config->set('nodeinfo', 'local_comments', $comments); $config->set('nodeinfo', 'local_comments', $comments);
$logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]); $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);

View file

@ -28,6 +28,7 @@ use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
class Post class Post
@ -405,7 +406,7 @@ class Post
AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`) AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`)
AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`)) AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))
AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))", AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))",
0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT, $uid]); 0, Contact::SHARING, Contact::FRIEND, Item::GRAVITY_PARENT, 0, $uid, $uid, $uid, Item::GRAVITY_PARENT, $uid, Item::GRAVITY_PARENT, $uid]);
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected)); $select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
@ -520,7 +521,7 @@ class Post
unset($fields['parent-uri']); unset($fields['parent-uri']);
unset($fields['parent-uri-id']); unset($fields['parent-uri-id']);
$thread_condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $thread_condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
// To ensure the data integrity we do it in an transaction // To ensure the data integrity we do it in an transaction
DBA::transaction(); DBA::transaction();

View file

@ -30,6 +30,7 @@ use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Subscription; use Friendica\Model\Subscription;
use Friendica\Model\Tag; use Friendica\Model\Tag;
@ -288,7 +289,7 @@ class UserNotification
} }
// Only create notifications for posts and comments, not for activities // Only create notifications for posts and comments, not for activities
if (($item['gravity'] == GRAVITY_ACTIVITY) && ($item['verb'] != Activity::ANNOUNCE)) { if (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($item['verb'] != Activity::ANNOUNCE)) {
return; return;
} }
@ -310,7 +311,7 @@ class UserNotification
*/ */
private static function insertNotificationByItem(int $type, int $uid, array $item): void private static function insertNotificationByItem(int $type, int $uid, array $item): void
{ {
if (($item['verb'] != Activity::ANNOUNCE) && ($item['gravity'] == GRAVITY_ACTIVITY) && if (($item['verb'] != Activity::ANNOUNCE) && ($item['gravity'] == Item::GRAVITY_ACTIVITY) &&
!in_array($type, [self::TYPE_DIRECT_COMMENT, self::TYPE_DIRECT_THREAD_COMMENT])) { !in_array($type, [self::TYPE_DIRECT_COMMENT, self::TYPE_DIRECT_THREAD_COMMENT])) {
// Activities are only stored when performed on the user's post or comment // Activities are only stored when performed on the user's post or comment
return; return;
@ -321,7 +322,7 @@ class UserNotification
$item['vid'], $item['vid'],
$type, $type,
$item['author-id'], $item['author-id'],
$item['gravity'] == GRAVITY_ACTIVITY ? $item['thr-parent-id'] : $item['uri-id'], $item['gravity'] == Item::GRAVITY_ACTIVITY ? $item['thr-parent-id'] : $item['uri-id'],
$item['parent-uri-id'] $item['parent-uri-id']
); );
@ -423,14 +424,14 @@ class UserNotification
private static function checkShared(array $item, int $uid): bool private static function checkShared(array $item, int $uid): bool
{ {
// Only check on original posts and reshare ("announce") activities, otherwise return // Only check on original posts and reshare ("announce") activities, otherwise return
if (($item['gravity'] != GRAVITY_PARENT) && ($item['verb'] != Activity::ANNOUNCE)) { if (($item['gravity'] != Item::GRAVITY_PARENT) && ($item['verb'] != Activity::ANNOUNCE)) {
return false; return false;
} }
// Don't notify about reshares by communities of our own posts or each time someone comments // Don't notify about reshares by communities of our own posts or each time someone comments
if (($item['verb'] == Activity::ANNOUNCE) && DBA::exists('contact', ['id' => $item['contact-id'], 'contact-type' => Contact::TYPE_COMMUNITY])) { if (($item['verb'] == Activity::ANNOUNCE) && DBA::exists('contact', ['id' => $item['contact-id'], 'contact-type' => Contact::TYPE_COMMUNITY])) {
$post = Post::selectFirst(['origin', 'gravity'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]); $post = Post::selectFirst(['origin', 'gravity'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]);
if ($post['origin'] || ($post['gravity'] != GRAVITY_PARENT)) { if ($post['origin'] || ($post['gravity'] != Item::GRAVITY_PARENT)) {
return false; return false;
} }
} }
@ -497,7 +498,7 @@ class UserNotification
*/ */
private static function checkCommentedThread(array $item, array $contacts): bool private static function checkCommentedThread(array $item, array $contacts): bool
{ {
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_PARENT]; $condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_PARENT];
return Post::exists($condition); return Post::exists($condition);
} }
@ -511,7 +512,7 @@ class UserNotification
*/ */
private static function checkDirectComment(array $item, array $contacts): bool private static function checkDirectComment(array $item, array $contacts): bool
{ {
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_COMMENT]; $condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_COMMENT];
return Post::exists($condition); return Post::exists($condition);
} }
@ -525,7 +526,7 @@ class UserNotification
*/ */
private static function checkDirectCommentedThread(array $item, array $contacts): bool private static function checkDirectCommentedThread(array $item, array $contacts): bool
{ {
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_PARENT]; $condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_PARENT];
return Post::exists($condition); return Post::exists($condition);
} }
@ -539,7 +540,7 @@ class UserNotification
*/ */
private static function checkCommentedParticipation(array $item, array $contacts): bool private static function checkCommentedParticipation(array $item, array $contacts): bool
{ {
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_COMMENT]; $condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_COMMENT];
return Post::exists($condition); return Post::exists($condition);
} }
@ -553,7 +554,7 @@ class UserNotification
*/ */
private static function checkFollowParticipation(array $item, array $contacts): bool private static function checkFollowParticipation(array $item, array $contacts): bool
{ {
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::FOLLOW]; $condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::FOLLOW];
return Post::exists($condition); return Post::exists($condition);
} }
@ -567,7 +568,7 @@ class UserNotification
*/ */
private static function checkActivityParticipation(array $item, array $contacts): bool private static function checkActivityParticipation(array $item, array $contacts): bool
{ {
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY]; $condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => Item::GRAVITY_ACTIVITY];
return Post::exists($condition); return Post::exists($condition);
} }
} }

View file

@ -97,7 +97,7 @@ class Objects extends BaseModule
$last_modified = $item['changed']; $last_modified = $item['changed'];
Network::checkEtagModified($etag, $last_modified); Network::checkEtagModified($etag, $last_modified);
if (empty($this->parameters['activity']) && ($item['gravity'] != GRAVITY_ACTIVITY)) { if (empty($this->parameters['activity']) && ($item['gravity'] != Item::GRAVITY_ACTIVITY)) {
$activity = ActivityPub\Transmitter::createCachedActivityFromItem($item['id'], false, true); $activity = ActivityPub\Transmitter::createCachedActivityFromItem($item['id'], false, true);
if (empty($activity['type'])) { if (empty($activity['type'])) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();

View file

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\BadRequestException;
@ -69,7 +70,7 @@ class Conversation extends BaseApi
$id = $parent['id']; $id = $parent['id'];
$condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `uri-id` > ?", $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `uri-id` > ?",
$id, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id]; $id, $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `uri-id` <= ?"; $condition[0] .= " AND `uri-id` <= ?";

View file

@ -78,7 +78,7 @@ class Statuses extends BaseApi
if (!$request['pinned']) { if (!$request['pinned']) {
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))", $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]); Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
} }
if ($request['only_media']) { if ($request['only_media']) {
@ -100,7 +100,7 @@ class Statuses extends BaseApi
} }
if ($request['exclude_replies']) { if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
} }
if ($request['pinned']) { if ($request['pinned']) {

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -51,7 +52,7 @@ class Favourited extends BaseApi
$params = ['order' => ['thr-parent-id' => true], 'limit' => $request['limit']]; $params = ['order' => ['thr-parent-id' => true], 'limit' => $request['limit']];
$condition = ['gravity' => GRAVITY_ACTIVITY, 'origin' => true, 'verb' => Activity::LIKE, 'uid' => $uid]; $condition = ['gravity' => Item::GRAVITY_ACTIVITY, 'origin' => true, 'verb' => Activity::LIKE, 'uid' => $uid];
if (!empty($request['max_id'])) { if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`thr-parent-id` < ?", $request['max_id']]); $condition = DBA::mergeConditions($condition, ["`thr-parent-id` < ?", $request['max_id']]);

View file

@ -151,13 +151,13 @@ class Statuses extends BaseApi
$parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]); $parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
$item['thr-parent'] = $parent['uri']; $item['thr-parent'] = $parent['uri'];
$item['gravity'] = GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
$item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body']; $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body'];
} else { } else {
self::checkThrottleLimit(); self::checkThrottleLimit();
$item['gravity'] = GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
$item['title'] = $request['spoiler_text']; $item['title'] = $request['spoiler_text'];
} }

View file

@ -47,7 +47,7 @@ class Bookmark extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked')); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked'));
} }

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Statuses;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
@ -55,7 +56,7 @@ class Context extends BaseApi
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]); $parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
if (DBA::isResult($parent)) { if (DBA::isResult($parent)) {
$posts = Post::selectPosts(['uri-id', 'thr-parent-id'], $posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]); ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]]);
while ($post = Post::fetch($posts)) { while ($post = Post::fetch($posts)) {
if ($post['uri-id'] == $post['thr-parent-id']) { if ($post['uri-id'] == $post['thr-parent-id']) {
continue; continue;

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Mastodon\Statuses;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -48,7 +49,7 @@ class FavouritedBy extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::LIKE]); $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE]);
$accounts = []; $accounts = [];

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Statuses;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
@ -46,7 +47,7 @@ class Mute extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted')); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
} }

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Mastodon\Statuses;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -48,7 +49,7 @@ class RebloggedBy extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]); $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
$accounts = []; $accounts = [];

View file

@ -47,7 +47,7 @@ class Unbookmark extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked')); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked'));
} }

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Statuses;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
@ -46,7 +47,7 @@ class Unmute extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted')); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
} }

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -55,7 +56,7 @@ class Home extends BaseApi
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
$condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'uid' => $uid]; $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'uid' => $uid];
if ($request['local']) { if ($request['local']) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]); $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
@ -85,7 +86,7 @@ class Home extends BaseApi
} }
if ($request['exclude_replies']) { if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
} }
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params); $items = Post::selectForUser($uid, ['uri-id'], $condition, $params);

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -60,7 +61,7 @@ class ListTimeline extends BaseApi
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)",
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $this->parameters['id']]; $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $this->parameters['id']];
if (!empty($request['max_id'])) { if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]); $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
@ -82,7 +83,7 @@ class ListTimeline extends BaseApi
} }
if ($request['exclude_replies']) { if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
} }
if ($request['local']) { if ($request['local']) {

View file

@ -57,7 +57,7 @@ class PublicTimeline extends BaseApi
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
$condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC, $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'private' => Item::PUBLIC,
'network' => Protocol::FEDERATED, 'parent-author-blocked' => false, 'parent-author-hidden' => false]; 'network' => Protocol::FEDERATED, 'parent-author-blocked' => false, 'parent-author-hidden' => false];
if ($request['local']) { if ($request['local']) {
@ -87,7 +87,7 @@ class PublicTimeline extends BaseApi
} }
if ($request['exclude_replies']) { if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
} }
if (!empty($uid)) { if (!empty($uid)) {

View file

@ -25,6 +25,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -85,7 +86,7 @@ class Tag extends BaseApi
} }
if ($request['exclude_replies']) { if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]); $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
} }
if (!empty($request['max_id'])) { if (!empty($request['max_id'])) {

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Twitter;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -54,7 +55,7 @@ class Favorites extends BaseApi
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ? AND `starred`", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ? AND `starred`",
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id]; $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id];
$params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];

View file

@ -26,10 +26,11 @@ use Friendica\Core\L10n;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Factory\Api\Twitter\Status as TwitterStatus; use Friendica\Factory\Api\Twitter\Status as TwitterStatus;
use Friendica\Module\BaseApi;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\Api\ApiResponse; use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -77,7 +78,7 @@ class Statuses extends BaseApi
$groups = $this->dba->selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]); $groups = $this->dba->selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
$gids = array_column($groups, 'contact-id'); $gids = array_column($groups, 'contact-id');
$condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids]; $condition = ['uid' => $uid, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'contact-id' => $gids];
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]); $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
if ($max_id > 0) { if ($max_id > 0) {
@ -86,7 +87,7 @@ class Statuses extends BaseApi
} }
if ($exclude_replies) { if ($exclude_replies) {
$condition[0] .= ' AND `gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = Item::GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `parent-uri-id` = ?"; $condition[0] .= " AND `parent-uri-id` = ?";

View file

@ -78,13 +78,13 @@ class Tweets extends BaseApi
$condition = ['uri-id' => $uriids]; $condition = ['uri-id' => $uriids];
if ($exclude_replies) { if ($exclude_replies) {
$condition['gravity'] = GRAVITY_PARENT; $condition['gravity'] = Item::GRAVITY_PARENT;
} }
$params['group_by'] = ['uri-id']; $params['group_by'] = ['uri-id'];
} else { } else {
$condition = ["`uri-id` > ? $condition = ["`uri-id` > ?
" . ($exclude_replies ? " AND `gravity` = " . GRAVITY_PARENT : ' ') . " " . ($exclude_replies ? " AND `gravity` = " . Item::GRAVITY_PARENT : ' ') . "
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `body` LIKE CONCAT('%',?,'%')", AND `body` LIKE CONCAT('%',?,'%')",
$since_id, $uid, $_REQUEST['q']]; $since_id, $uid, $_REQUEST['q']];

View file

@ -54,7 +54,7 @@ class HomeTimeline extends BaseApi
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ?", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ?",
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id]; $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `uri-id` <= ?"; $condition[0] .= " AND `uri-id` <= ?";
@ -62,7 +62,7 @@ class HomeTimeline extends BaseApi
} }
if ($exclude_replies) { if ($exclude_replies) {
$condition[0] .= ' AND `gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = Item::GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `parent-uri-id` = ?"; $condition[0] .= " AND `parent-uri-id` = ?";

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Twitter\Statuses;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Post; use Friendica\Model\Post;
@ -55,7 +56,7 @@ class Mentions extends BaseApi
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `uri-id` > ?"; AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `uri-id` > ?";
$condition = [ $condition = [
GRAVITY_PARENT, GRAVITY_COMMENT, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT,
$uid, $uid,
Post\UserNotification::TYPE_EXPLICIT_TAGGED | Post\UserNotification::TYPE_IMPLICIT_TAGGED | Post\UserNotification::TYPE_EXPLICIT_TAGGED | Post\UserNotification::TYPE_IMPLICIT_TAGGED |
Post\UserNotification::TYPE_THREAD_COMMENT | Post\UserNotification::TYPE_DIRECT_COMMENT | Post\UserNotification::TYPE_THREAD_COMMENT | Post\UserNotification::TYPE_DIRECT_COMMENT |

View file

@ -47,7 +47,7 @@ class NetworkPublicTimeline extends BaseApi
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ?", $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ?",
GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id, Item::PUBLIC];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `uri-id` <= ?"; $condition[0] .= " AND `uri-id` <= ?";

View file

@ -53,7 +53,7 @@ class PublicTimeline extends BaseApi
if ($exclude_replies && !$conversation_id) { if ($exclude_replies && !$conversation_id) {
$condition = ["`gravity` = ? AND `uri-id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`", $condition = ["`gravity` = ? AND `uri-id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`",
GRAVITY_PARENT, $since_id, Item::PUBLIC]; Item::GRAVITY_PARENT, $since_id, Item::PUBLIC];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `uri-id` <= ?"; $condition[0] .= " AND `uri-id` <= ?";
@ -64,7 +64,7 @@ class PublicTimeline extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
} else { } else {
$condition = ["`gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`", $condition = ["`gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id, Item::PUBLIC];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `uri-id` <= ?"; $condition[0] .= " AND `uri-id` <= ?";

View file

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\BadRequestException;
@ -60,10 +61,10 @@ class Show extends BaseApi
$item_id = $item['id']; $item_id = $item['id'];
if ($conversation) { if ($conversation) {
$condition = ['parent' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]; $condition = ['parent' => $item_id, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
$params = ['order' => ['uri-id' => true]]; $params = ['order' => ['uri-id' => true]];
} else { } else {
$condition = ['id' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]; $condition = ['id' => $item_id, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
$params = []; $params = [];
} }

View file

@ -113,12 +113,12 @@ class Update extends BaseApi
$parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_status_id'], 'uid' => [0, $uid]]); $parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_status_id'], 'uid' => [0, $uid]]);
$item['thr-parent'] = $parent['uri']; $item['thr-parent'] = $parent['uri'];
$item['gravity'] = GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
} else { } else {
self::checkThrottleLimit(); self::checkThrottleLimit();
$item['gravity'] = GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
} }

View file

@ -23,10 +23,11 @@ namespace Friendica\Module\Api\Twitter\Statuses;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Module\BaseApi;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseApi;
/** /**
* Returns the most recent statuses posted by the user. * Returns the most recent statuses posted by the user.
@ -54,11 +55,11 @@ class UserTimeline extends BaseApi
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`)) AND `gravity` IN (?, ?) AND `uri-id` > ? AND `author-id` = ?", $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`)) AND `gravity` IN (?, ?) AND `uri-id` > ? AND `author-id` = ?",
0, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $cid]; 0, $uid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, $since_id, $cid];
if ($exclude_replies) { if ($exclude_replies) {
$condition[0] .= ' AND `gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = Item::GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {

View file

@ -29,6 +29,7 @@ use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Api\ApiResponse; use Friendica\Module\Api\ApiResponse;
@ -233,7 +234,7 @@ class BaseApi extends BaseModule
if ($throttle_day > 0) { if ($throttle_day > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", Item::GRAVITY_PARENT, $uid, $datefrom];
$posts_day = Post::countThread($condition); $posts_day = Post::countThread($condition);
if ($posts_day > $throttle_day) { if ($posts_day > $throttle_day) {
@ -249,7 +250,7 @@ class BaseApi extends BaseModule
if ($throttle_week > 0) { if ($throttle_week > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", Item::GRAVITY_PARENT, $uid, $datefrom];
$posts_week = Post::countThread($condition); $posts_week = Post::countThread($condition);
if ($posts_week > $throttle_week) { if ($posts_week > $throttle_week) {
@ -265,7 +266,7 @@ class BaseApi extends BaseModule
if ($throttle_month > 0) { if ($throttle_month > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30); $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
$condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, $uid, $datefrom]; $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", Item::GRAVITY_PARENT, $uid, $datefrom];
$posts_month = Post::countThread($condition); $posts_month = Post::countThread($condition);
if ($posts_month > $throttle_month) { if ($posts_month > $throttle_month) {

View file

@ -414,7 +414,7 @@ class Network extends BaseModule
} elseif (self::$forumContactId) { } elseif (self::$forumContactId) {
$conditionStrings = DBA::mergeConditions($conditionStrings, $conditionStrings = DBA::mergeConditions($conditionStrings,
["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))", ["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
self::$forumContactId, self::$forumContactId, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()]); self::$forumContactId, self::$forumContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()]);
} }
// Currently only the order modes "received" and "commented" are in use // Currently only the order modes "received" and "commented" are in use

View file

@ -49,7 +49,7 @@ class Fetch extends BaseModule
// Fetch the item // Fetch the item
$condition = ['origin' => true, 'private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $guid, $condition = ['origin' => true, 'private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $guid,
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$item = Post::selectFirst([], $condition); $item = Post::selectFirst([], $condition);
if (empty($item)) { if (empty($item)) {
$condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
@ -76,7 +76,7 @@ class Fetch extends BaseModule
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$status = Diaspora::buildStatus($item, $user); $status = Diaspora::buildStatus($item, $user);
} else { } else {
$status = ['type' => 'comment', 'message' => Diaspora::createCommentSignature($item)]; $status = ['type' => 'comment', 'message' => Diaspora::createCommentSignature($item)];

View file

@ -25,6 +25,7 @@ use Friendica\BaseModule;
use Friendica\Core\Session; use Friendica\Core\Session;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -49,7 +50,7 @@ class Ignore extends BaseModule
$dba = DI::dba(); $dba = DI::dba();
$thread = Post::selectFirst(['uri-id', 'uid'], ['id' => $itemId, 'gravity' => GRAVITY_PARENT]); $thread = Post::selectFirst(['uri-id', 'uid'], ['id' => $itemId, 'gravity' => Item::GRAVITY_PARENT]);
if (!$dba->isResult($thread)) { if (!$dba->isResult($thread)) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }

View file

@ -176,7 +176,7 @@ class Status extends BaseProfile
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
(`gravity` = ? AND `vid` = ? AND `origin` (`gravity` = ? AND `vid` = ? AND `origin`
AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` = ?)))", AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` = ?)))",
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT, Protocol::ACTIVITYPUB]); GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB]);
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED, $condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
'visible' => true, 'deleted' => false]); 'visible' => true, 'deleted' => false]);

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Update;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\Conversation\Network as NetworkModule; use Friendica\Module\Conversation\Network as NetworkModule;
@ -55,7 +56,7 @@ class Network extends NetworkModule
} elseif (self::$order === 'received') { } elseif (self::$order === 'received') {
// Only load new toplevel posts // Only load new toplevel posts
$conditionFields['unseen'] = true; $conditionFields['unseen'] = true;
$conditionFields['gravity'] = GRAVITY_PARENT; $conditionFields['gravity'] = Item::GRAVITY_PARENT;
} else { } else {
// Load all unseen items // Load all unseen items
$conditionFields['unseen'] = true; $conditionFields['unseen'] = true;

View file

@ -72,7 +72,7 @@ class Profile extends BaseModule
$condition = ["`uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending` $condition = ["`uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
AND `visible` AND (NOT `deleted` OR `gravity` = ?) AND `visible` AND (NOT `deleted` OR `gravity` = ?)
AND `wall` " . $sql_extra, $a->getProfileOwner(), GRAVITY_ACTIVITY]; AND `wall` " . $sql_extra, $a->getProfileOwner(), Item::GRAVITY_ACTIVITY];
if ($_GET['force'] && !empty($_GET['item'])) { if ($_GET['force'] && !empty($_GET['item'])) {
// When the parent is provided, we only fetch this // When the parent is provided, we only fetch this

View file

@ -29,6 +29,7 @@ use Friendica\Core\L10n;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\BaseNotifications; use Friendica\Module\BaseNotifications;
use Friendica\Navigation\Notifications\Collection\FormattedNotifies; use Friendica\Navigation\Notifications\Collection\FormattedNotifies;
@ -363,13 +364,13 @@ class FormattedNotify extends BaseFactory
$item['author-avatar'] = $item['contact-avatar']; $item['author-avatar'] = $item['contact-avatar'];
} }
$item['label'] = (($item['gravity'] == GRAVITY_PARENT) ? 'post' : 'comment'); $item['label'] = (($item['gravity'] == Item::GRAVITY_PARENT) ? 'post' : 'comment');
$item['link'] = $this->baseUrl->get(true) . '/display/' . $item['parent-guid']; $item['link'] = $this->baseUrl->get(true) . '/display/' . $item['parent-guid'];
$item['image'] = $item['author-avatar']; $item['image'] = $item['author-avatar'];
$item['url'] = $item['author-link']; $item['url'] = $item['author-link'];
$item['when'] = DateTimeFormat::local($item['created'], 'r'); $item['when'] = DateTimeFormat::local($item['created'], 'r');
$item['ago'] = Temporal::getRelativeDate($item['created']); $item['ago'] = Temporal::getRelativeDate($item['created']);
$item['text'] = (($item['gravity'] == GRAVITY_PARENT) $item['text'] = (($item['gravity'] == Item::GRAVITY_PARENT)
? $this->l10n->t("%s created a new post", $item['author-name']) ? $this->l10n->t("%s created a new post", $item['author-name'])
: $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name'])); : $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name']));

View file

@ -23,6 +23,7 @@ namespace Friendica\Object\Api\Mastodon;
use Friendica\BaseDataTransferObject; use Friendica\BaseDataTransferObject;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Model\Item;
use Friendica\Object\Api\Mastodon\Status\Counts; use Friendica\Object\Api\Mastodon\Status\Counts;
use Friendica\Object\Api\Mastodon\Status\UserAttributes; use Friendica\Object\Api\Mastodon\Status\UserAttributes;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -102,7 +103,7 @@ class Status extends BaseDataTransferObject
$this->id = (string)$item['uri-id']; $this->id = (string)$item['uri-id'];
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON); $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON);
if ($item['gravity'] == GRAVITY_COMMENT) { if ($item['gravity'] == Item::GRAVITY_COMMENT) {
$this->in_reply_to_id = (string)$item['thr-parent-id']; $this->in_reply_to_id = (string)$item['thr-parent-id'];
$this->in_reply_to_account_id = (string)$item['parent-author-id']; $this->in_reply_to_account_id = (string)$item['parent-author-id'];
} }

View file

@ -106,7 +106,7 @@ class Status extends BaseDataTransferObject
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API); $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
if ($item['gravity'] == GRAVITY_COMMENT) { if ($item['gravity'] == Item::GRAVITY_COMMENT) {
$this->in_reply_to_status_id = (int)$item['thr-parent-id']; $this->in_reply_to_status_id = (int)$item['thr-parent-id'];
$this->in_reply_to_status_id_str = (string)$item['thr-parent-id']; $this->in_reply_to_status_id_str = (string)$item['thr-parent-id'];
$this->in_reply_to_user_id = (int)$item['parent-author-id']; $this->in_reply_to_user_id = (int)$item['parent-author-id'];

View file

@ -210,7 +210,7 @@ class Post
$announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]); $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
// On Diaspora only toplevel posts can be reshared // On Diaspora only toplevel posts can be reshared
if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != GRAVITY_PARENT)) { if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != Item::GRAVITY_PARENT)) {
$announceable = false; $announceable = false;
} }
@ -915,7 +915,7 @@ class Post
return $text; return $text;
} }
if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) { if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != Item::GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
$text .= '@' . $item['author-addr'] . ' '; $text .= '@' . $item['author-addr'] . ' ';
} }

View file

@ -308,10 +308,10 @@ class Processor
$item['thr-parent'] = $activity['reply-to-id']; $item['thr-parent'] = $activity['reply-to-id'];
if ($activity['reply-to-id'] == $activity['id']) { if ($activity['reply-to-id'] == $activity['id']) {
$item['gravity'] = GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
} else { } else {
$item['gravity'] = GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
} }
@ -356,7 +356,7 @@ class Processor
$item['diaspora_signed_text'] = $activity['diaspora:comment'] ?? ''; $item['diaspora_signed_text'] = $activity['diaspora:comment'] ?? '';
if (empty($conversation) && empty($activity['directmessage']) && ($item['gravity'] != GRAVITY_PARENT) && !Post::exists(['uri' => $item['thr-parent']])) { if (empty($conversation) && empty($activity['directmessage']) && ($item['gravity'] != Item::GRAVITY_PARENT) && !Post::exists(['uri' => $item['thr-parent']])) {
Logger::notice('Parent not found, message will be discarded.', ['thr-parent' => $item['thr-parent']]); Logger::notice('Parent not found, message will be discarded.', ['thr-parent' => $item['thr-parent']]);
if (!$fetch_parents) { if (!$fetch_parents) {
Queue::remove($activity); Queue::remove($activity);
@ -663,7 +663,7 @@ class Processor
$item['verb'] = $verb; $item['verb'] = $verb;
$item['thr-parent'] = $activity['object_id']; $item['thr-parent'] = $activity['object_id'];
$item['gravity'] = GRAVITY_ACTIVITY; $item['gravity'] = Item::GRAVITY_ACTIVITY;
unset($item['post-type']); unset($item['post-type']);
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
@ -833,7 +833,7 @@ class Processor
$item['body'] = Item::improveSharedDataInBody($item); $item['body'] = Item::improveSharedDataInBody($item);
} else { } else {
$parent_uri = $item['parent-uri'] ?? $item['thr-parent']; $parent_uri = $item['parent-uri'] ?? $item['thr-parent'];
if (empty($activity['directmessage']) && ($parent_uri != $item['uri']) && ($item['gravity'] == GRAVITY_COMMENT)) { if (empty($activity['directmessage']) && ($parent_uri != $item['uri']) && ($item['gravity'] == Item::GRAVITY_COMMENT)) {
$parent = Post::selectFirst(['id', 'uri-id', 'private', 'author-link', 'alias'], ['uri' => $parent_uri]); $parent = Post::selectFirst(['id', 'uri-id', 'private', 'author-link', 'alias'], ['uri' => $parent_uri]);
if (!DBA::isResult($parent)) { if (!DBA::isResult($parent)) {
Logger::warning('Unknown parent item.', ['uri' => $parent_uri]); Logger::warning('Unknown parent item.', ['uri' => $parent_uri]);
@ -937,7 +937,7 @@ class Processor
return true; return true;
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
// We cannot reliably check at this point if a comment or activity belongs to an accepted post or needs to be fetched // We cannot reliably check at this point if a comment or activity belongs to an accepted post or needs to be fetched
// This can possibly be improved in the future. // This can possibly be improved in the future.
Logger::debug('Message is no parent - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]); Logger::debug('Message is no parent - accepted', ['uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
@ -1035,7 +1035,7 @@ class Processor
// When a post arrives via a relay and we follow the author, we have to override the causer. // When a post arrives via a relay and we follow the author, we have to override the causer.
// Otherwise the system assumes that we follow the relay. (See "addRowInformation") // Otherwise the system assumes that we follow the relay. (See "addRowInformation")
Logger::debug('Relay post for follower', ['receiver' => $receiver, 'guid' => $item['guid'], 'relay' => $activity['from-relay']]); Logger::debug('Relay post for follower', ['receiver' => $receiver, 'guid' => $item['guid'], 'relay' => $activity['from-relay']]);
$item['causer-id'] = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id']; $item['causer-id'] = ($item['gravity'] == Item::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
} }
if ($item['isForum'] ?? false) { if ($item['isForum'] ?? false) {
@ -1053,7 +1053,7 @@ class Processor
continue; continue;
} }
if (($receiver != 0) && ($item['gravity'] == GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC])) { if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC])) {
if (!($item['isForum'] ?? false)) { if (!($item['isForum'] ?? false)) {
if ($item['post-reason'] == Item::PR_BCC) { if ($item['post-reason'] == Item::PR_BCC) {
Logger::info('Top level post via BCC from a non sharer, ignoring', ['uid' => $receiver, 'contact' => $item['contact-id'], 'url' => $item['uri']]); Logger::info('Top level post via BCC from a non sharer, ignoring', ['uid' => $receiver, 'contact' => $item['contact-id'], 'url' => $item['uri']]);
@ -1088,7 +1088,7 @@ class Processor
continue; continue;
} }
if (($item['gravity'] != GRAVITY_ACTIVITY) && ($activity['object_type'] == 'as:Event')) { if (($item['gravity'] != Item::GRAVITY_ACTIVITY) && ($activity['object_type'] == 'as:Event')) {
$event_id = self::createEvent($activity, $item); $event_id = self::createEvent($activity, $item);
$item = Event::getItemArrayForImportedId($event_id, $item); $item = Event::getItemArrayForImportedId($event_id, $item);
@ -1118,7 +1118,7 @@ class Processor
} }
// Store send a follow request for every reshare - but only when the item had been stored // Store send a follow request for every reshare - but only when the item had been stored
if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == GRAVITY_PARENT) && !empty($item['author-link']) && ($item['author-link'] != $item['owner-link'])) { if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == Item::GRAVITY_PARENT) && !empty($item['author-link']) && ($item['author-link'] != $item['owner-link'])) {
$author = APContact::getByURL($item['owner-link'], false); $author = APContact::getByURL($item['owner-link'], false);
// We send automatic follow requests for reshared messages. (We don't need though for forum posts) // We send automatic follow requests for reshared messages. (We don't need though for forum posts)
if ($author['type'] != 'Group') { if ($author['type'] != 'Group') {
@ -1138,7 +1138,7 @@ class Processor
*/ */
private static function hasParents(array $item, int $receiver) private static function hasParents(array $item, int $receiver)
{ {
if (($receiver == 0) || ($item['gravity'] == GRAVITY_PARENT)) { if (($receiver == 0) || ($item['gravity'] == Item::GRAVITY_PARENT)) {
return true; return true;
} }
@ -1149,7 +1149,7 @@ class Processor
if ($item['verb'] != Activity::ANNOUNCE) { if ($item['verb'] != Activity::ANNOUNCE) {
switch (DI::pConfig()->get($receiver, 'system', 'accept_only_sharer')) { switch (DI::pConfig()->get($receiver, 'system', 'accept_only_sharer')) {
case Item::COMPLETION_COMMENT: case Item::COMPLETION_COMMENT:
$add_parent = ($item['gravity'] != GRAVITY_ACTIVITY); $add_parent = ($item['gravity'] != Item::GRAVITY_ACTIVITY);
break; break;
case Item::COMPLETION_NONE: case Item::COMPLETION_NONE:
@ -1283,7 +1283,7 @@ class Processor
*/ */
private static function postMail(array $activity, array $item) private static function postMail(array $activity, array $item)
{ {
if (($item['gravity'] != GRAVITY_PARENT) && !DBA::exists('mail', ['uri' => $item['thr-parent'], 'uid' => $item['uid']])) { if (($item['gravity'] != Item::GRAVITY_PARENT) && !DBA::exists('mail', ['uri' => $item['thr-parent'], 'uid' => $item['uid']])) {
Logger::info('Parent not found, mail will be discarded.', ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); Logger::info('Parent not found, mail will be discarded.', ['uid' => $item['uid'], 'uri' => $item['thr-parent']]);
return false; return false;
} }
@ -1859,7 +1859,7 @@ class Processor
return; return;
} }
Item::markForDeletion(['uri' => $activity['object_id'], 'author-id' => $author_id, 'gravity' => GRAVITY_ACTIVITY]); Item::markForDeletion(['uri' => $activity['object_id'], 'author-id' => $author_id, 'gravity' => Item::GRAVITY_ACTIVITY]);
Queue::remove($activity); Queue::remove($activity);
} }

View file

@ -264,7 +264,7 @@ class Receiver
} }
} }
if (Post::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) { if (Post::exists(['uri' => $object_id, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]])) {
// We just assume "note" since it doesn't make a difference for the further processing // We just assume "note" since it doesn't make a difference for the further processing
return 'as:Note'; return 'as:Note';
} }

View file

@ -266,7 +266,7 @@ class Transmitter
$condition = array_merge($condition, [ $condition = array_merge($condition, [
'uid' => $owner['uid'], 'uid' => $owner['uid'],
'author-id' => Contact::getIdForURL($owner['url'], 0, false), 'author-id' => Contact::getIdForURL($owner['url'], 0, false),
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
'network' => Protocol::FEDERATED, 'network' => Protocol::FEDERATED,
'parent-network' => Protocol::FEDERATED, 'parent-network' => Protocol::FEDERATED,
'origin' => true, 'origin' => true,
@ -351,7 +351,7 @@ class Transmitter
'uid' => $owner['uid'], 'uid' => $owner['uid'],
'author-id' => $owner_cid, 'author-id' => $owner_cid,
'private' => [Item::PUBLIC, Item::UNLISTED], 'private' => [Item::PUBLIC, Item::UNLISTED],
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
'network' => Protocol::FEDERATED, 'network' => Protocol::FEDERATED,
'parent-network' => Protocol::FEDERATED, 'parent-network' => Protocol::FEDERATED,
'origin' => true, 'origin' => true,
@ -577,7 +577,7 @@ class Transmitter
$item_profile = APContact::getByURL($item['author-link']); $item_profile = APContact::getByURL($item['author-link']);
$exclude[] = $item['author-link']; $exclude[] = $item['author-link'];
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$exclude[] = $item['owner-link']; $exclude[] = $item['owner-link'];
} }
@ -665,7 +665,7 @@ class Transmitter
$data = ['to' => [], 'cc' => [], 'bcc' => []]; $data = ['to' => [], 'cc' => [], 'bcc' => []];
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$actor_profile = APContact::getByURL($item['owner-link']); $actor_profile = APContact::getByURL($item['owner-link']);
} else { } else {
$actor_profile = APContact::getByURL($item['author-link']); $actor_profile = APContact::getByURL($item['author-link']);
@ -753,10 +753,10 @@ class Transmitter
if (!empty($item['parent'])) { if (!empty($item['parent'])) {
$parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']], ['order' => ['id']]); $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']], ['order' => ['id']]);
while ($parent = Post::fetch($parents)) { while ($parent = Post::fetch($parents)) {
if ($parent['gravity'] == GRAVITY_PARENT) { if ($parent['gravity'] == Item::GRAVITY_PARENT) {
$profile = APContact::getByURL($parent['owner-link'], false); $profile = APContact::getByURL($parent['owner-link'], false);
if (!empty($profile)) { if (!empty($profile)) {
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
// Comments to forums are directed to the forum // Comments to forums are directed to the forum
// But comments to forums aren't directed to the followers collection // But comments to forums aren't directed to the followers collection
// This rule is only valid when the actor isn't the forum. // This rule is only valid when the actor isn't the forum.
@ -971,7 +971,7 @@ class Transmitter
$inboxes = []; $inboxes = [];
if ($item['gravity'] == GRAVITY_ACTIVITY) { if ($item['gravity'] == Item::GRAVITY_ACTIVITY) {
$item_profile = APContact::getByURL($item['author-link'], false); $item_profile = APContact::getByURL($item['author-link'], false);
} else { } else {
$item_profile = APContact::getByURL($item['owner-link'], false); $item_profile = APContact::getByURL($item['owner-link'], false);
@ -1060,7 +1060,7 @@ class Transmitter
$mail['parent-uri'] = $reply['uri']; $mail['parent-uri'] = $reply['uri'];
$mail['parent-uri-id'] = $reply['uri-id']; $mail['parent-uri-id'] = $reply['uri-id'];
$mail['parent-author-id'] = Contact::getIdForURL($reply['from-url'], 0, false); $mail['parent-author-id'] = Contact::getIdForURL($reply['from-url'], 0, false);
$mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT); $mail['gravity'] = ($mail['reply'] ? Item::GRAVITY_COMMENT: Item::GRAVITY_PARENT);
$mail['event-type'] = ''; $mail['event-type'] = '';
$mail['language'] = ''; $mail['language'] = '';
$mail['parent'] = 0; $mail['parent'] = 0;
@ -1245,7 +1245,7 @@ class Transmitter
if (!$object_mode) { if (!$object_mode) {
$data = ['@context' => $context ?? ActivityPub::CONTEXT]; $data = ['@context' => $context ?? ActivityPub::CONTEXT];
if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) { if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
$type = 'Undo'; $type = 'Undo';
} elseif ($item['deleted']) { } elseif ($item['deleted']) {
$type = 'Delete'; $type = 'Delete';
@ -1256,7 +1256,7 @@ class Transmitter
if ($type == 'Delete') { if ($type == 'Delete') {
$data['id'] = Item::newURI($item['guid']) . '/' . $type;; $data['id'] = Item::newURI($item['guid']) . '/' . $type;;
} elseif (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) { } elseif (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($type != 'Undo')) {
$data['id'] = $item['uri']; $data['id'] = $item['uri'];
} else { } else {
$data['id'] = $item['uri'] . '/' . $type; $data['id'] = $item['uri'] . '/' . $type;
@ -1264,7 +1264,7 @@ class Transmitter
$data['type'] = $type; $data['type'] = $type;
if (($type != 'Announce') || ($item['gravity'] != GRAVITY_PARENT)) { if (($type != 'Announce') || ($item['gravity'] != Item::GRAVITY_PARENT)) {
$data['actor'] = $item['author-link']; $data['actor'] = $item['author-link'];
} else { } else {
$data['actor'] = $item['owner-link']; $data['actor'] = $item['owner-link'];
@ -1557,7 +1557,7 @@ class Transmitter
// We are treating posts differently when they are directed to a community. // We are treating posts differently when they are directed to a community.
// This is done to better support Lemmy. Most of the changes should work with other systems as well. // This is done to better support Lemmy. Most of the changes should work with other systems as well.
// But to not risk compatibility issues we currently perform the changes only for communities. // But to not risk compatibility issues we currently perform the changes only for communities.
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$isCommunityPost = !empty(Tag::getByURIId($item['uri-id'], [Tag::EXCLUSIVE_MENTION])); $isCommunityPost = !empty(Tag::getByURIId($item['uri-id'], [Tag::EXCLUSIVE_MENTION]));
$links = Post\Media::getByURIId($item['uri-id'], [Post\Media::HTML]); $links = Post\Media::getByURIId($item['uri-id'], [Post\Media::HTML]);
if ($isCommunityPost && (count($links) == 1)) { if ($isCommunityPost && (count($links) == 1)) {

View file

@ -799,7 +799,7 @@ class DFRN
$dfrnowner = self::addEntryAuthor($doc, "dfrn:owner", $item["owner-link"], $item); $dfrnowner = self::addEntryAuthor($doc, "dfrn:owner", $item["owner-link"], $item);
$entry->appendChild($dfrnowner); $entry->appendChild($dfrnowner);
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
$parent = Post::selectFirst(['guid', 'plink'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]); $parent = Post::selectFirst(['guid', 'plink'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
if (DBA::isResult($parent)) { if (DBA::isResult($parent)) {
$attributes = ["ref" => $item['thr-parent'], "type" => "text/html", $attributes = ["ref" => $item['thr-parent'], "type" => "text/html",
@ -888,7 +888,7 @@ class DFRN
if ($item['object-type'] != '') { if ($item['object-type'] != '') {
XML::addElement($doc, $entry, 'activity:object-type', $item['object-type']); XML::addElement($doc, $entry, 'activity:object-type', $item['object-type']);
} elseif ($item['gravity'] == GRAVITY_PARENT) { } elseif ($item['gravity'] == Item::GRAVITY_PARENT) {
XML::addElement($doc, $entry, 'activity:object-type', Activity\ObjectType::NOTE); XML::addElement($doc, $entry, 'activity:object-type', Activity\ObjectType::NOTE);
} else { } else {
XML::addElement($doc, $entry, 'activity:object-type', Activity\ObjectType::COMMENT); XML::addElement($doc, $entry, 'activity:object-type', Activity\ObjectType::COMMENT);
@ -1612,21 +1612,21 @@ class DFRN
|| ($item['verb'] == Activity::ATTENDMAYBE) || ($item['verb'] == Activity::ATTENDMAYBE)
|| ($item['verb'] == Activity::ANNOUNCE) || ($item['verb'] == Activity::ANNOUNCE)
) { ) {
$item['gravity'] = GRAVITY_ACTIVITY; $item['gravity'] = Item::GRAVITY_ACTIVITY;
// only one like or dislike per person // only one like or dislike per person
// split into two queries for performance issues // split into two queries for performance issues
$condition = [ $condition = [
'uid' => $item['uid'], 'uid' => $item['uid'],
'author-id' => $item['author-id'], 'author-id' => $item['author-id'],
'gravity' => GRAVITY_ACTIVITY, 'gravity' => Item::GRAVITY_ACTIVITY,
'verb' => $item['verb'], 'verb' => $item['verb'],
'parent-uri' => $item['thr-parent'], 'parent-uri' => $item['thr-parent'],
]; ];
if (Post::exists($condition)) { if (Post::exists($condition)) {
return false; return false;
} }
$condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'gravity' => GRAVITY_ACTIVITY, $condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'gravity' => Item::GRAVITY_ACTIVITY,
'verb' => $item['verb'], 'thr-parent' => $item['thr-parent']]; 'verb' => $item['verb'], 'thr-parent' => $item['thr-parent']];
if (Post::exists($condition)) { if (Post::exists($condition)) {
return false; return false;
@ -1938,7 +1938,7 @@ class DFRN
// Now assign the rest of the values that depend on the type of the message // Now assign the rest of the values that depend on the type of the message
if (in_array($entrytype, [self::REPLY, self::REPLY_RC])) { if (in_array($entrytype, [self::REPLY, self::REPLY_RC])) {
$item['gravity'] = GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
if (!isset($item['object-type'])) { if (!isset($item['object-type'])) {
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
@ -1964,7 +1964,7 @@ class DFRN
if ($entrytype == self::REPLY_RC) { if ($entrytype == self::REPLY_RC) {
$item['wall'] = 1; $item['wall'] = 1;
} elseif ($entrytype == self::TOP_LEVEL) { } elseif ($entrytype == self::TOP_LEVEL) {
$item['gravity'] = GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
if (!isset($item['object-type'])) { if (!isset($item['object-type'])) {
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
@ -2034,7 +2034,7 @@ class DFRN
Logger::info('Contact is not sharing with the user', ['uid' => $item['uid'], 'owner-id' => $item['owner-id'], 'author-id' => $item['author-id'], 'gravity' => $item['gravity'], 'uri' => $item['uri']]); Logger::info('Contact is not sharing with the user', ['uid' => $item['uid'], 'owner-id' => $item['owner-id'], 'author-id' => $item['author-id'], 'gravity' => $item['gravity'], 'uri' => $item['uri']]);
return; return;
} }
if (($item['gravity'] == GRAVITY_ACTIVITY) && DI::pConfig()->get($item['uid'], 'system', 'accept_only_sharer') == Item::COMPLETION_COMMENT) { if (($item['gravity'] == Item::GRAVITY_ACTIVITY) && DI::pConfig()->get($item['uid'], 'system', 'accept_only_sharer') == Item::COMPLETION_COMMENT) {
Logger::info('Completion is set to "comment", but this is an activity. so we stop here.', ['uid' => $item['uid'], 'owner-id' => $item['owner-id'], 'author-id' => $item['author-id'], 'gravity' => $item['gravity'], 'uri' => $item['uri']]); Logger::info('Completion is set to "comment", but this is an activity. so we stop here.', ['uid' => $item['uid'], 'owner-id' => $item['owner-id'], 'author-id' => $item['author-id'], 'gravity' => $item['gravity'], 'uri' => $item['uri']]);
return; return;
} }
@ -2119,13 +2119,13 @@ class DFRN
} }
// When it is a starting post it has to belong to the person that wants to delete it // When it is a starting post it has to belong to the person that wants to delete it
if (($item['gravity'] == GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) { if (($item['gravity'] == Item::GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
Logger::info('Item with URI ' . $uri . ' do not belong to contact ' . $importer['id'] . ' - ignoring deletion.'); Logger::info('Item with URI ' . $uri . ' do not belong to contact ' . $importer['id'] . ' - ignoring deletion.');
return; return;
} }
// Comments can be deleted by the thread owner or comment owner // Comments can be deleted by the thread owner or comment owner
if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) { if (($item['gravity'] != Item::GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
$condition = ['id' => $item['parent'], 'contact-id' => $importer['id']]; $condition = ['id' => $item['parent'], 'contact-id' => $importer['id']];
if (!Post::exists($condition)) { if (!Post::exists($condition)) {
Logger::info('Item with URI ' . $uri . ' was not found or must not be deleted by contact ' . $importer['id'] . ' - ignoring deletion.'); Logger::info('Item with URI ' . $uri . ' was not found or must not be deleted by contact ' . $importer['id'] . ' - ignoring deletion.');

View file

@ -83,7 +83,7 @@ class Diaspora
} }
$items = Post::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'], $items = Post::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
['parent' => $item['parent'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]); ['parent' => $item['parent'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
while ($item = Post::fetch($items)) { while ($item = Post::fetch($items)) {
$contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'], $contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
['id' => $item['author-id']]); ['id' => $item['author-id']]);
@ -1548,7 +1548,7 @@ class Diaspora
$datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]); $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
$datarray['verb'] = Activity::POST; $datarray['verb'] = Activity::POST;
$datarray['gravity'] = GRAVITY_COMMENT; $datarray['gravity'] = Item::GRAVITY_COMMENT;
$datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri']; $datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
@ -1801,7 +1801,7 @@ class Diaspora
$datarray['uri'] = self::getUriFromGuid($author, $guid); $datarray['uri'] = self::getUriFromGuid($author, $guid);
$datarray['verb'] = $verb; $datarray['verb'] = $verb;
$datarray['gravity'] = GRAVITY_ACTIVITY; $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['thr-parent'] = $toplevel_parent_item['uri']; $datarray['thr-parent'] = $toplevel_parent_item['uri'];
$datarray['object-type'] = Activity\ObjectType::NOTE; $datarray['object-type'] = Activity\ObjectType::NOTE;
@ -1812,7 +1812,7 @@ class Diaspora
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = DateTimeFormat::utcNow(); $datarray['changed'] = $datarray['created'] = $datarray['edited'] = DateTimeFormat::utcNow();
// like on comments have the comment as parent. So we need to fetch the toplevel parent // like on comments have the comment as parent. So we need to fetch the toplevel parent
if ($toplevel_parent_item['gravity'] != GRAVITY_PARENT) { if ($toplevel_parent_item['gravity'] != Item::GRAVITY_PARENT) {
$toplevel = Post::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]); $toplevel = Post::selectFirst(['origin'], ['id' => $toplevel_parent_item['parent']]);
$origin = $toplevel['origin']; $origin = $toplevel['origin'];
} else { } else {
@ -1981,7 +1981,7 @@ class Diaspora
$datarray['uri'] = self::getUriFromGuid($author, $guid); $datarray['uri'] = self::getUriFromGuid($author, $guid);
$datarray['verb'] = Activity::FOLLOW; $datarray['verb'] = Activity::FOLLOW;
$datarray['gravity'] = GRAVITY_ACTIVITY; $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['thr-parent'] = $toplevel_parent_item['uri']; $datarray['thr-parent'] = $toplevel_parent_item['uri'];
$datarray['object-type'] = Activity\ObjectType::NOTE; $datarray['object-type'] = Activity\ObjectType::NOTE;
@ -2002,9 +2002,9 @@ class Diaspora
// Send all existing comments and likes to the requesting server // Send all existing comments and likes to the requesting server
$comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'], $comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'],
['parent' => $toplevel_parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]); ['parent' => $toplevel_parent_item['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
while ($comment = Post::fetch($comments)) { while ($comment = Post::fetch($comments)) {
if (($comment['gravity'] == GRAVITY_ACTIVITY) && !in_array($comment['verb'], [Activity::LIKE, Activity::DISLIKE])) { if (($comment['gravity'] == Item::GRAVITY_ACTIVITY) && !in_array($comment['verb'], [Activity::LIKE, Activity::DISLIKE])) {
Logger::info('Unsupported activities are not relayed', ['item' => $comment['id'], 'verb' => $comment['verb']]); Logger::info('Unsupported activities are not relayed', ['item' => $comment['id'], 'verb' => $comment['verb']]);
continue; continue;
} }
@ -2302,7 +2302,7 @@ class Diaspora
$datarray['thr-parent'] = $parent['uri']; $datarray['thr-parent'] = $parent['uri'];
$datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE; $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
$datarray['gravity'] = GRAVITY_ACTIVITY; $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
$datarray['object-type'] = Activity\ObjectType::NOTE; $datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['protocol'] = $item['protocol']; $datarray['protocol'] = $item['protocol'];
@ -2387,7 +2387,7 @@ class Diaspora
$datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]); $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
$datarray['verb'] = Activity::POST; $datarray['verb'] = Activity::POST;
$datarray['gravity'] = GRAVITY_PARENT; $datarray['gravity'] = Item::GRAVITY_PARENT;
$datarray['protocol'] = Conversation::PARCEL_DIASPORA; $datarray['protocol'] = Conversation::PARCEL_DIASPORA;
$datarray['source'] = $xml; $datarray['source'] = $xml;
@ -2706,7 +2706,7 @@ class Diaspora
$datarray['owner-id'] = $datarray['author-id']; $datarray['owner-id'] = $datarray['author-id'];
$datarray['verb'] = Activity::POST; $datarray['verb'] = Activity::POST;
$datarray['gravity'] = GRAVITY_PARENT; $datarray['gravity'] = Item::GRAVITY_PARENT;
$datarray['protocol'] = Conversation::PARCEL_DIASPORA; $datarray['protocol'] = Conversation::PARCEL_DIASPORA;
$datarray['source'] = $xml; $datarray['source'] = $xml;
@ -3596,7 +3596,7 @@ class Diaspora
// - Implicit mentions are enabled // - Implicit mentions are enabled
if ( if (
$item['author-id'] != $thread_parent_item['author-id'] $item['author-id'] != $thread_parent_item['author-id']
&& ($thread_parent_item['gravity'] != GRAVITY_PARENT) && ($thread_parent_item['gravity'] != Item::GRAVITY_PARENT)
&& (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) && (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
&& !DI::config()->get('system', 'disable_implicit_mentions') && !DI::config()->get('system', 'disable_implicit_mentions')
) { ) {
@ -3729,7 +3729,7 @@ class Diaspora
$msg_type = 'retraction'; $msg_type = 'retraction';
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == Item::GRAVITY_PARENT) {
$target_type = 'Post'; $target_type = 'Post';
} elseif (in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE])) { } elseif (in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE])) {
$target_type = 'Like'; $target_type = 'Like';
@ -4069,12 +4069,12 @@ class Diaspora
return false; return false;
} }
if (($parent_post['gravity'] == GRAVITY_COMMENT) && empty($parent_post['signed_text'])) { if (($parent_post['gravity'] == Item::GRAVITY_COMMENT) && empty($parent_post['signed_text'])) {
Logger::info('Parent comment has got no Diaspora signature.', ['parent-id' => $parent_id]); Logger::info('Parent comment has got no Diaspora signature.', ['parent-id' => $parent_id]);
return false; return false;
} }
if ($parent_post['gravity'] == GRAVITY_COMMENT) { if ($parent_post['gravity'] == Item::GRAVITY_COMMENT) {
return self::parentSupportDiaspora($parent_post['thr-parent-id']); return self::parentSupportDiaspora($parent_post['thr-parent-id']);
} }

View file

@ -252,20 +252,21 @@ class Feed
$author['owner-avatar'] = $contact['thumb']; $author['owner-avatar'] = $contact['thumb'];
} }
$header = []; $header = [
$header['uid'] = $importer['uid'] ?? 0; 'uid' => $importer['uid'] ?? 0,
$header['network'] = Protocol::FEED; 'network' => Protocol::FEED,
'wall' => 0,
'origin' => 0,
'gravity' => Item::GRAVITY_PARENT,
'private' => Item::PUBLIC,
'verb' => Activity::POST,
'object-type' => Activity\ObjectType::NOTE,
'post-type' => Item::PT_ARTICLE,
'contact-id' => $contact['id'] ?? 0,
];
$datarray['protocol'] = $protocol; $datarray['protocol'] = $protocol;
$datarray['direction'] = Conversation::PULL; $datarray['direction'] = Conversation::PULL;
$header['wall'] = 0;
$header['origin'] = 0;
$header['gravity'] = GRAVITY_PARENT;
$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;
if (!is_object($entries)) { if (!is_object($entries)) {
Logger::info("There are no entries in this feed."); Logger::info("There are no entries in this feed.");
@ -954,13 +955,13 @@ class Feed
$condition = ["`uid` = ? AND `received` > ? AND NOT `deleted` AND `gravity` IN (?, ?) $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted` AND `gravity` IN (?, ?)
AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?, ?, ?)", AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?, ?, ?)",
$owner['uid'], $check_date, GRAVITY_PARENT, GRAVITY_COMMENT, $owner['uid'], $check_date, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT,
Item::PRIVATE, Protocol::ACTIVITYPUB, Item::PRIVATE, Protocol::ACTIVITYPUB,
Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA]; Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA];
if ($filter === 'comments') { if ($filter === 'comments') {
$condition[0] .= " AND `gravity` = ? "; $condition[0] .= " AND `gravity` = ? ";
$condition[] = GRAVITY_COMMENT; $condition[] = Item::GRAVITY_COMMENT;
} }
if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) { if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
@ -1087,7 +1088,7 @@ class Feed
*/ */
private static function noteEntry(DOMDocument $doc, array $item, array $owner): DOMElement private static function noteEntry(DOMDocument $doc, array $item, array $owner): DOMElement
{ {
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) { if (($item['gravity'] != Item::GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
Logger::info('Feed entry author does not match feed owner', ['owner' => $owner['url'], 'author' => $item['author-link']]); Logger::info('Feed entry author does not match feed owner', ['owner' => $owner['url'], 'author' => $item['author-link']]);
} }
@ -1151,7 +1152,7 @@ class Feed
{ {
$mentioned = []; $mentioned = [];
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
$parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
$thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]); $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]);

View file

@ -391,7 +391,7 @@ class OStatus
$header['network'] = Protocol::OSTATUS; $header['network'] = Protocol::OSTATUS;
$header['wall'] = 0; $header['wall'] = 0;
$header['origin'] = 0; $header['origin'] = 0;
$header['gravity'] = GRAVITY_COMMENT; $header['gravity'] = Item::GRAVITY_COMMENT;
if (!is_object($doc->firstChild) || empty($doc->firstChild->tagName)) { if (!is_object($doc->firstChild) || empty($doc->firstChild->tagName)) {
return false; return false;
@ -499,7 +499,7 @@ class OStatus
$item['verb'] = Activity::LIKE; $item['verb'] = Activity::LIKE;
$item['thr-parent'] = $orig_uri; $item['thr-parent'] = $orig_uri;
$item['gravity'] = GRAVITY_ACTIVITY; $item['gravity'] = Item::GRAVITY_ACTIVITY;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
} }
@ -714,7 +714,7 @@ class OStatus
} }
} else { } else {
$item['thr-parent'] = $item['uri']; $item['thr-parent'] = $item['uri'];
$item['gravity'] = GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
} }
self::$itemlist[] = $item; self::$itemlist[] = $item;
@ -1359,7 +1359,7 @@ class OStatus
*/ */
private static function likeEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement private static function likeEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
{ {
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) { if (($item['gravity'] != Item::GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.'); Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.');
} }
@ -1509,7 +1509,7 @@ class OStatus
*/ */
private static function noteEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement private static function noteEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
{ {
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) { if (($item['gravity'] != Item::GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.'); Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.');
} }
@ -1639,7 +1639,7 @@ class OStatus
{ {
$mentioned = []; $mentioned = [];
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
$parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
$thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]); $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]);

View file

@ -25,18 +25,21 @@ use Friendica\Contact\FriendSuggest\Collection\FriendSuggests;
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException; use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model\Contact;
use Friendica\Model\FContact;
use Friendica\Model\GServer;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Protocol\Activity;
use Friendica\Util\Network;
use Friendica\Core\Worker;
use Friendica\Model\FContact;
use Friendica\Model\Item;
use Friendica\Protocol\Relay; use Friendica\Protocol\Relay;
use Friendica\Util\Network;
class Delivery class Delivery
{ {
@ -75,7 +78,7 @@ class Delivery
$uid = $post_uriid; $uid = $post_uriid;
$target_item = []; $target_item = [];
} else { } else {
$item = Model\Post::selectFirst(['id', 'parent'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]); $item = Post::selectFirst(['id', 'parent'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
if (!DBA::isResult($item) || empty($item['parent'])) { if (!DBA::isResult($item) || empty($item['parent'])) {
Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]); Logger::warning('Post not found', ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
return; return;
@ -85,9 +88,9 @@ class Delivery
$condition = ['id' => [$target_id, $parent_id], 'visible' => true]; $condition = ['id' => [$target_id, $parent_id], 'visible' => true];
$params = ['order' => ['id']]; $params = ['order' => ['id']];
$itemdata = Model\Post::select(Item::DELIVER_FIELDLIST, $condition, $params); $itemdata = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
while ($item = Model\Post::fetch($itemdata)) { while ($item = Post::fetch($itemdata)) {
if ($item['verb'] == Activity::ANNOUNCE) { if ($item['verb'] == Activity::ANNOUNCE) {
continue; continue;
} }
@ -124,14 +127,14 @@ class Delivery
} }
$condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']]; $condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']];
$thr_parent = Model\Post::selectFirst(['network', 'object'], $condition); $thr_parent = Post::selectFirst(['network', 'object'], $condition);
if (!DBA::isResult($thr_parent)) { if (!DBA::isResult($thr_parent)) {
// Shouldn't happen. But when this does, we just take the parent as thread parent. // Shouldn't happen. But when this does, we just take the parent as thread parent.
// That's totally okay for what we use this variable here. // That's totally okay for what we use this variable here.
$thr_parent = $parent; $thr_parent = $parent;
} }
if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) { if (!empty($contact_id) && Contact::isArchived($contact_id)) {
Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]); Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]);
self::setFailedQueue($cmd, $target_item); self::setFailedQueue($cmd, $target_item);
return; return;
@ -144,7 +147,7 @@ class Delivery
} }
} }
$top_level = $target_item['gravity'] == GRAVITY_PARENT; $top_level = $target_item['gravity'] == Item::GRAVITY_PARENT;
// This is IMPORTANT!!!! // This is IMPORTANT!!!!
@ -176,7 +179,7 @@ class Delivery
&& empty($parent['allow_gid']) && empty($parent['allow_gid'])
&& empty($parent['deny_cid']) && empty($parent['deny_cid'])
&& empty($parent['deny_gid']) && empty($parent['deny_gid'])
&& ($parent["private"] != Model\Item::PRIVATE)) { && ($parent['private'] != Item::PRIVATE)) {
$public_message = true; $public_message = true;
} }
} }
@ -185,7 +188,7 @@ class Delivery
Logger::warning('No delivery data', ['command' => $cmd, 'uri-id' => $post_uriid, 'cid' => $contact_id]); Logger::warning('No delivery data', ['command' => $cmd, 'uri-id' => $post_uriid, 'cid' => $contact_id]);
} }
$owner = Model\User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
if (!DBA::isResult($owner)) { if (!DBA::isResult($owner)) {
self::setFailedQueue($cmd, $target_item); self::setFailedQueue($cmd, $target_item);
return; return;
@ -205,7 +208,7 @@ class Delivery
return; return;
} }
$protocol = Model\GServer::getProtocol($contact['gsid'] ?? 0); $protocol = GServer::getProtocol($contact['gsid'] ?? 0);
// Transmit via Diaspora if the thread had started as Diaspora post. // Transmit via Diaspora if the thread had started as Diaspora post.
// Also transmit via Diaspora if this is a direct answer to a Diaspora comment. // Also transmit via Diaspora if this is a direct answer to a Diaspora comment.
@ -250,7 +253,7 @@ class Delivery
return; return;
} }
Model\Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? $item['id']); Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? $item['id']);
} }
/** /**
@ -281,7 +284,7 @@ class Delivery
if ($cmd == self::MAIL) { if ($cmd == self::MAIL) {
$item = $target_item; $item = $target_item;
$item['body'] = Model\Item::fixPrivatePhotos($item['body'], $owner['uid'], null, $item['contact-id']); $item['body'] = Item::fixPrivatePhotos($item['body'], $owner['uid'], null, $item['contact-id']);
$atom = DFRN::mail($item, $owner); $atom = DFRN::mail($item, $owner);
} elseif ($cmd == self::SUGGESTION) { } elseif ($cmd == self::SUGGESTION) {
$item = $target_item; $item = $target_item;
@ -311,13 +314,13 @@ class Delivery
Logger::debug('Notifier entry: ' . $contact["url"] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom); Logger::debug('Notifier entry: ' . $contact["url"] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom);
$protocol = Model\Post\DeliveryData::DFRN; $protocol = Post\DeliveryData::DFRN;
// We don't have a relationship with contacts on a public post. // We don't have a relationship with contacts on a public post.
// Se we transmit with the new method and via Diaspora as a fallback // Se we transmit with the new method and via Diaspora as a fallback
if (!empty($items) && (($items[0]['uid'] == 0) || ($contact['uid'] == 0))) { if (!empty($items) && (($items[0]['uid'] == 0) || ($contact['uid'] == 0))) {
// Transmit in public if it's a relay post // Transmit in public if it's a relay post
$public_dfrn = ($contact['contact-type'] == Model\Contact::TYPE_RELAY); $public_dfrn = ($contact['contact-type'] == Contact::TYPE_RELAY);
$deliver_status = DFRN::transmit($owner, $contact, $atom, $public_dfrn); $deliver_status = DFRN::transmit($owner, $contact, $atom, $public_dfrn);
@ -327,17 +330,17 @@ class Delivery
if ($cmd == Delivery::POST) { if ($cmd == Delivery::POST) {
if (($deliver_status >= 200) && ($deliver_status <= 299)) { if (($deliver_status >= 200) && ($deliver_status <= 299)) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol); Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
Model\GServer::setProtocol($contact['gsid'] ?? 0, $protocol); GServer::setProtocol($contact['gsid'] ?? 0, $protocol);
} else { } else {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']); Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
return; return;
} }
if ((($deliver_status < 200) || ($deliver_status > 299)) && (empty($server_protocol) || ($server_protocol == Model\Post\DeliveryData::LEGACY_DFRN))) { if ((($deliver_status < 200) || ($deliver_status > 299)) && (empty($server_protocol) || ($server_protocol == Post\DeliveryData::LEGACY_DFRN))) {
// Transmit via Diaspora if not possible via Friendica // Transmit via Diaspora if not possible via Friendica
self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return; return;
@ -351,20 +354,20 @@ class Delivery
if (($deliver_status >= 200) && ($deliver_status <= 299)) { if (($deliver_status >= 200) && ($deliver_status <= 299)) {
// We successfully delivered a message, the contact is alive // We successfully delivered a message, the contact is alive
Model\Contact::unmarkForArchival($contact); Contact::unmarkForArchival($contact);
Model\GServer::setProtocol($contact['gsid'] ?? 0, $protocol); GServer::setProtocol($contact['gsid'] ?? 0, $protocol);
if ($cmd == Delivery::POST) { if ($cmd == Delivery::POST) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol); Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
} }
} else { } else {
// The message could not be delivered. We mark the contact as "dead" // The message could not be delivered. We mark the contact as "dead"
Model\Contact::markForArchival($contact); Contact::markForArchival($contact);
Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]); Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
if (!Worker::defer() && $cmd == Delivery::POST) { if (!Worker::defer() && $cmd == Delivery::POST) {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']); Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
} }
@ -386,7 +389,7 @@ class Delivery
private static function deliverDiaspora(string $cmd, array $contact, array $owner, array $items, array $target_item, bool $public_message, bool $top_level, bool $followup) private static function deliverDiaspora(string $cmd, array $contact, array $owner, array $items, array $target_item, bool $public_message, bool $top_level, bool $followup)
{ {
// We don't treat Forum posts as "wall-to-wall" to be able to post them via Diaspora // We don't treat Forum posts as "wall-to-wall" to be able to post them via Diaspora
$walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != Model\User::ACCOUNT_TYPE_COMMUNITY); $walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY);
if ($public_message) { if ($public_message) {
$loc = 'public batch ' . $contact['batch']; $loc = 'public batch ' . $contact['batch'];
@ -438,30 +441,30 @@ class Delivery
if (($deliver_status >= 200) && ($deliver_status <= 299)) { if (($deliver_status >= 200) && ($deliver_status <= 299)) {
// We successfully delivered a message, the contact is alive // We successfully delivered a message, the contact is alive
Model\Contact::unmarkForArchival($contact); Contact::unmarkForArchival($contact);
Model\GServer::setProtocol($contact['gsid'] ?? 0, Model\Post\DeliveryData::DIASPORA); GServer::setProtocol($contact['gsid'] ?? 0, Post\DeliveryData::DIASPORA);
if ($cmd == Delivery::POST) { if ($cmd == Delivery::POST) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA); Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Post\DeliveryData::DIASPORA);
} }
} else { } else {
// The message could not be delivered. We mark the contact as "dead" // The message could not be delivered. We mark the contact as "dead"
Model\Contact::markForArchival($contact); Contact::markForArchival($contact);
// When it is delivered to the public endpoint, we do mark the relay contact for archival as well // When it is delivered to the public endpoint, we do mark the relay contact for archival as well
if ($public_message) { if ($public_message) {
Relay::markForArchival($contact); Relay::markForArchival($contact);
} }
if (empty($contact['contact-type']) || ($contact['contact-type'] != Model\Contact::TYPE_RELAY)) { if (empty($contact['contact-type']) || ($contact['contact-type'] != Contact::TYPE_RELAY)) {
Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]); Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
// defer message for redelivery // defer message for redelivery
if (!Worker::defer() && $cmd == Delivery::POST) { if (!Worker::defer() && $cmd == Delivery::POST) {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']); Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} elseif ($cmd == Delivery::POST) { } elseif ($cmd == Delivery::POST) {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']); Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
} }
} }
} }
@ -525,7 +528,7 @@ class Delivery
// only expose our real email address to true friends // only expose our real email address to true friends
if (($contact['rel'] == Model\Contact::FRIEND) && !$contact['blocked']) { if (($contact['rel'] == Contact::FRIEND) && !$contact['blocked']) {
if ($reply_to) { if ($reply_to) {
$headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $reply_to . '>' . "\n"; $headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $reply_to . '>' . "\n";
$headers .= 'Sender: ' . $local_user['email'] . "\n"; $headers .= 'Sender: ' . $local_user['email'] . "\n";
@ -551,13 +554,13 @@ class Delivery
if (empty($target_item['title'])) { if (empty($target_item['title'])) {
$condition = ['uri' => $target_item['parent-uri'], 'uid' => $owner['uid']]; $condition = ['uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
$title = Model\Post::selectFirst(['title'], $condition); $title = Post::selectFirst(['title'], $condition);
if (DBA::isResult($title) && ($title['title'] != '')) { if (DBA::isResult($title) && ($title['title'] != '')) {
$subject = $title['title']; $subject = $title['title'];
} else { } else {
$condition = ['parent-uri' => $target_item['parent-uri'], 'uid' => $owner['uid']]; $condition = ['parent-uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
$title = Model\Post::selectFirst(['title'], $condition); $title = Post::selectFirst(['title'], $condition);
if (DBA::isResult($title) && ($title['title'] != '')) { if (DBA::isResult($title) && ($title['title'] != '')) {
$subject = $title['title']; $subject = $title['title'];
@ -575,7 +578,7 @@ class Delivery
if ($success) { if ($success) {
// Success // Success
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::MAIL); Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Post\DeliveryData::MAIL);
Logger::info('Delivered via mail', ['guid' => $target_item['guid'], 'to' => $addr, 'subject' => $subject]); Logger::info('Delivered via mail', ['guid' => $target_item['guid'], 'to' => $addr, 'subject' => $subject]);
} else { } else {
// Failed // Failed

View file

@ -68,7 +68,7 @@ class ExpirePosts
{ {
Logger::notice('Delete expired posts'); Logger::notice('Delete expired posts');
// physically remove anything that has been deleted for more than two months // physically remove anything that has been deleted for more than two months
$condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')]; $condition = ["`gravity` = ? AND `deleted` AND `changed` < ?", Item::GRAVITY_PARENT, DateTimeFormat::utc('now - 60 days')];
$rows = Post::select(['guid', 'uri-id', 'uid'], $condition); $rows = Post::select(['guid', 'uri-id', 'uid'], $condition);
while ($row = Post::fetch($rows)) { while ($row = Post::fetch($rows)) {
Logger::info('Delete expired item', ['uri-id' => $row['uri-id'], 'guid' => $row['guid']]); Logger::info('Delete expired item', ['uri-id' => $row['uri-id'], 'guid' => $row['guid']]);
@ -134,7 +134,7 @@ class ExpirePosts
} }
$rows = 0; $rows = 0;
$userposts = DBA::select('post-user', [], ["`gravity` = ? AND `uri-id` not in (select `uri-id` from `post-thread`)", GRAVITY_PARENT]); $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `uri-id` not in (select `uri-id` from `post-thread`)", Item::GRAVITY_PARENT]);
while ($fields = DBA::fetch($userposts)) { while ($fields = DBA::fetch($userposts)) {
$post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $fields); $post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $fields);
$post_fields['commented'] = $post_fields['changed'] = $post_fields['created']; $post_fields['commented'] = $post_fields['changed'] = $post_fields['created'];
@ -149,7 +149,7 @@ class ExpirePosts
} }
$rows = 0; $rows = 0;
$userposts = DBA::select('post-user', [], ["`gravity` = ? AND `id` not in (select `post-user-id` from `post-thread-user`)", GRAVITY_PARENT]); $userposts = DBA::select('post-user', [], ["`gravity` = ? AND `id` not in (select `post-user-id` from `post-thread-user`)", Item::GRAVITY_PARENT]);
while ($fields = DBA::fetch($userposts)) { while ($fields = DBA::fetch($userposts)) {
$post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $fields); $post_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $fields);
$post_fields['commented'] = $post_fields['changed'] = $post_fields['created']; $post_fields['commented'] = $post_fields['changed'] = $post_fields['created'];
@ -264,7 +264,7 @@ class ExpirePosts
AND `i`.`parent-uri-id` = `post-user`.`uri-id`) AND `i`.`parent-uri-id` = `post-user`.`uri-id`)
AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` = ? AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` AS `i` WHERE `i`.`uid` = ?
AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > ?))", AND `i`.`parent-uri-id` = `post-user`.`uri-id` AND `i`.`received` > ?))",
GRAVITY_PARENT, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days'), 0, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days')]); Item::GRAVITY_PARENT, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days'), 0, 0, DateTimeFormat::utc('now - ' . (int)$expire_days_unclaimed . ' days')]);
Logger::notice('Start deleting unclaimed public items'); Logger::notice('Start deleting unclaimed public items');
$affected_count = 0; $affected_count = 0;

View file

@ -143,7 +143,7 @@ class Notifier
} }
} }
$top_level = $target_item['gravity'] == GRAVITY_PARENT; $top_level = $target_item['gravity'] == Item::GRAVITY_PARENT;
} }
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);

View file

@ -387,7 +387,7 @@ return [
'uri-id' => 1, 'uri-id' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -402,7 +402,7 @@ return [
'uri-id' => 2, 'uri-id' => 2,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -417,7 +417,7 @@ return [
'uri-id' => 3, 'uri-id' => 3,
'parent-uri-id' => 3, 'parent-uri-id' => 3,
'thr-parent-id' => 3, 'thr-parent-id' => 3,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 43, 'author-id' => 43,
@ -432,7 +432,7 @@ return [
'uri-id' => 4, 'uri-id' => 4,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -447,7 +447,7 @@ return [
'uri-id' => 5, 'uri-id' => 5,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -462,7 +462,7 @@ return [
'uri-id' => 6, 'uri-id' => 6,
'parent-uri-id' => 6, 'parent-uri-id' => 6,
'thr-parent-id' => 6, 'thr-parent-id' => 6,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -477,7 +477,7 @@ return [
'uri-id' => 7, 'uri-id' => 7,
'parent-uri-id' => 7, 'parent-uri-id' => 7,
'thr-parent-id' => 7, 'thr-parent-id' => 7,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -505,7 +505,7 @@ return [
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true, 'global' => true,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'wall' => 1, 'wall' => 1,
'origin' => 1, 'origin' => 1,
@ -519,7 +519,7 @@ return [
'origin' => 1, 'origin' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -540,7 +540,7 @@ return [
'origin' => 1, 'origin' => 1,
'parent-uri-id' => 3, 'parent-uri-id' => 3,
'thr-parent-id' => 3, 'thr-parent-id' => 3,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 43, 'author-id' => 43,
@ -561,7 +561,7 @@ return [
'origin' => 1, 'origin' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -582,7 +582,7 @@ return [
'origin' => 1, 'origin' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -603,7 +603,7 @@ return [
'origin' => 1, 'origin' => 1,
'parent-uri-id' => 6, 'parent-uri-id' => 6,
'thr-parent-id' => 6, 'thr-parent-id' => 6,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -624,7 +624,7 @@ return [
'origin' => 0, 'origin' => 0,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -645,7 +645,7 @@ return [
'origin' => 0, 'origin' => 0,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -666,7 +666,7 @@ return [
'origin' => 0, 'origin' => 0,
'parent-uri-id' => 3, 'parent-uri-id' => 3,
'thr-parent-id' => 3, 'thr-parent-id' => 3,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 43, 'author-id' => 43,
@ -687,7 +687,7 @@ return [
'origin' => 0, 'origin' => 0,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 44, 'author-id' => 44,
@ -708,7 +708,7 @@ return [
'origin' => 0, 'origin' => 0,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'gravity' => GRAVITY_COMMENT, 'gravity' => Item::GRAVITY_COMMENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'owner-id' => 42, 'owner-id' => 42,
'author-id' => 42, 'author-id' => 42,
@ -735,7 +735,7 @@ return [
'thr-parent-id' => 6, 'thr-parent-id' => 6,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true, 'global' => true,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'origin' => 0, 'origin' => 0,
'deleted' => 0, 'deleted' => 0,
@ -756,7 +756,7 @@ return [
'thr-parent-id' => 7, 'thr-parent-id' => 7,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true, 'global' => true,
'gravity' => GRAVITY_PARENT, 'gravity' => Item::GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'origin' => 0, 'origin' => 0,
'deleted' => 0, 'deleted' => 0,

View file

@ -299,7 +299,7 @@ function update_1349()
} }
if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id` if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) { SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", Item::GRAVITY_ACTIVITY)) {
return Update::FAILED; return Update::FAILED;
} }

View file

@ -33,7 +33,9 @@ use Friendica\Core\Session;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model;
use Friendica\Model\Item;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module; use Friendica\Module;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -203,7 +205,7 @@ function frio_remote_nav(App $a, array &$nav_info)
{ {
if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
// get the homelink from $_SESSION // get the homelink from $_SESSION
$homelink = Model\Profile::getMyURL(); $homelink = Profile::getMyURL();
if (!$homelink) { if (!$homelink) {
$homelink = Session::get('visitor_home', ''); $homelink = Session::get('visitor_home', '');
} }
@ -216,7 +218,7 @@ function frio_remote_nav(App $a, array &$nav_info)
} elseif (!local_user() && remote_user()) { } elseif (!local_user() && remote_user()) {
$remoteUser = Contact::getById(remote_user(), $fields); $remoteUser = Contact::getById(remote_user(), $fields);
$nav_info['nav']['remote'] = DI::l10n()->t('Guest'); $nav_info['nav']['remote'] = DI::l10n()->t('Guest');
} elseif (Model\Profile::getMyURL()) { } elseif (Profile::getMyURL()) {
$remoteUser = Contact::getByURL($homelink, null, $fields); $remoteUser = Contact::getByURL($homelink, null, $fields);
$nav_info['nav']['remote'] = DI::l10n()->t('Visitor'); $nav_info['nav']['remote'] = DI::l10n()->t('Visitor');
} else { } else {
@ -257,7 +259,7 @@ function frio_display_item(App $a, &$arr)
if ( if (
local_user() local_user()
&& in_array($arr['item']['uid'], [0, local_user()]) && in_array($arr['item']['uid'], [0, local_user()])
&& $arr['item']['gravity'] == GRAVITY_PARENT && $arr['item']['gravity'] == Item::GRAVITY_PARENT
&& !$arr['item']['self'] && !$arr['item']['self']
&& !$arr['item']['mention'] && !$arr['item']['mention']
) { ) {