*/
use Friendica\App;
+use Friendica\Content\Conversation;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
$post['body'] = BBCode::removeSharedData(Item::setHashtags($post['body']));
$post['writable'] = true;
- $o = DI::conversation()->create([$post], 'search', false, true);
+ $o = DI::conversation()->create([$post], Conversation::MODE_SEARCH, false, true);
System::jsonExit(['preview' => $o]);
}
*/
use Friendica\App;
+use Friendica\Content\Conversation;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Database\DBA;
$count = count($notes);
- $o .= DI::conversation()->create($notes, 'notes', $update);
+ $o .= DI::conversation()->create($notes, Conversation::MODE_NOTES, $update);
}
$o .= $pager->renderMinimal($count);
class Conversation
{
+ const MODE_COMMUNITY = 'community';
+ const MODE_CONTACTS = 'contacts';
+ const MODE_CONTACT_POSTS = 'contact-posts';
+ const MODE_DISPLAY = 'display';
+ const MODE_FILED = 'filed';
+ const MODE_NETWORK = 'network';
+ const MODE_NOTES = 'notes';
+ const MODE_SEARCH = 'search';
+ const MODE_PROFILE = 'profile';
+
/** @var Activity */
private $activity;
/** @var L10n */
$previewing = (($preview) ? ' preview ' : '');
- if ($mode === 'network') {
+ if ($mode === self::MODE_NETWORK) {
$items = $this->addChildren($items, false, $order, $uid, $mode);
if (!$update) {
/*
. "'; </script>\r\n";
}
- } elseif ($mode === 'profile') {
+ } elseif ($mode === self::MODE_PROFILE) {
$items = $this->addChildren($items, false, $order, $uid, $mode);
if (!$update) {
. "; var netargs = '?f='; </script>\r\n";
}
}
- } elseif ($mode === 'notes') {
+ } elseif ($mode === self::MODE_NOTES) {
$items = $this->addChildren($items, false, $order, $this->session->getLocalUserId(), $mode);
if (!$update) {
. "<script> var profile_uid = " . $this->session->getLocalUserId()
. "; var netargs = '?f='; </script>\r\n";
}
- } elseif ($mode === 'display') {
+ } elseif ($mode === self::MODE_DISPLAY) {
$items = $this->addChildren($items, false, $order, $uid, $mode);
if (!$update) {
. "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
. "</script>";
}
- } elseif ($mode === 'community') {
+ } elseif ($mode === self::MODE_COMMUNITY) {
$items = $this->addChildren($items, true, $order, $uid, $mode);
if (!$update) {
. (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
. "'; </script>\r\n";
}
- } elseif ($mode === 'contacts') {
+ } elseif ($mode === self::MODE_CONTACTS) {
$items = $this->addChildren($items, false, $order, $uid, $mode);
if (!$update) {
. "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
."?f='; </script>\r\n";
}
- } elseif ($mode === 'search') {
+ } elseif ($mode === self::MODE_SEARCH) {
$live_update_div = '<div id="live-search"></div>' . "\r\n";
}
- $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != 'search';
+ $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH;
if (!$update) {
$_SESSION['return_path'] = $this->args->getQueryString();
$formSecurityToken = BaseModule::getFormSecurityToken('contact_action');
if (!empty($items)) {
- if (in_array($mode, ['community', 'contacts', 'profile'])) {
+ if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
$writable = true;
} else {
$writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
$writable = false;
}
- if (in_array($mode, ['filed', 'search', 'contact-posts'])) {
+ if (in_array($mode, [self::MODE_FILED, self::MODE_SEARCH, self::MODE_CONTACT_POSTS])) {
/*
* "New Item View" on network page or search page results
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
$this->item->localize($item);
- if ($mode === 'filed') {
+ if ($mode === self::MODE_FILED) {
$dropping = true;
} else {
$dropping = false;
$condition = DBA::mergeConditions($condition,
["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]);
+ $condition = DBA::mergeConditions($condition,
+ ["`visible` AND NOT `deleted` AND NOT `author-blocked` AND NOT `owner-blocked`
+ AND ((NOT `contact-pending` AND (`contact-rel` IN (?, ?))) OR `self` OR `contact-uid` = ?)",
+ Contact::SHARING, Contact::FRIEND, 0]);
+
$thread_parents = Post::select(['uri-id', 'causer-id'], $condition, ['order' => ['uri-id' => false, 'uid']]);
$thr_parent = [];
$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::select(array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
$items = [];
$quote_uri_ids = [];
+ $authors = [];
while ($row = Post::fetch($thread_items)) {
if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
continue;
}
- if (($mode != 'contacts') && !$row['origin']) {
+ if (($mode != self::MODE_CONTACTS) && !$row['origin']) {
$row['featured'] = false;
}
}
}
+ $authors[] = $row['author-id'];
+ $authors[] = $row['owner-id'];
+
if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT])) {
$quote_uri_ids[$row['uri-id']] = [
'uri-id' => $row['uri-id'],
$row['thr-parent'] = $quote_uri_ids[$quote['quote-uri-id']]['uri'];
$row['thr-parent-id'] = $quote_uri_ids[$quote['quote-uri-id']]['uri-id'];
+ $authors[] = $row['author-id'];
+ $authors[] = $row['owner-id'];
+
$items[$row['uri-id']] = $this->addRowInformation($row, [], []);
}
DBA::close($quotes);
+ $authors = array_unique($authors);
+
+ $blocks = [];
+ $ignores = [];
+ $collapses = [];
+ if (!empty($authors)) {
+ $usercontacts = DBA::select('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $uid, 'cid' => $authors]);
+ while ($usercontact = DBA::fetch($usercontacts)) {
+ if ($usercontact['blocked']) {
+ $blocks[] = $usercontact['cid'];
+ }
+ if ($usercontact['ignored']) {
+ $ignores[] = $usercontact['cid'];
+ }
+ if ($usercontact['collapsed']) {
+ $collapses[] = $usercontact['cid'];
+ }
+ }
+ DBA::close($usercontacts);
+ }
+
+ foreach ($items as $key => $row) {
+ $always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]);
+
+ $items[$key]['user-blocked-author'] = !$always_display && in_array($row['author-id'], $blocks);
+ $items[$key]['user-ignored-author'] = !$always_display && in_array($row['author-id'], $ignores);
+ $items[$key]['user-blocked-owner'] = !$always_display && in_array($row['owner-id'], $blocks);
+ $items[$key]['user-ignored-owner'] = !$always_display && in_array($row['owner-id'], $ignores);
+ $items[$key]['user-collapsed-author'] = !$always_display && in_array($row['author-id'], $collapses);
+ $items[$key]['user-collapsed-owner'] = !$always_display && in_array($row['owner-id'], $collapses);
+
+ if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
+ (in_array($row['author-id'], $blocks) || in_array($row['owner-id'], $blocks) || in_array($row['author-id'], $ignores) || in_array($row['owner-id'], $ignores))) {
+ unset($items[$key]);
+ }
+ }
+
$items = $this->convSort($items, $order);
$this->profiler->stopRecording();
use Friendica\Contact\Avatar;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
+use Friendica\Content\Conversation;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
}
}
- $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
+ $o .= DI::conversation()->create($items, Conversation::MODE_CONTACTS, $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
} else {
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
}
}
- $o .= DI::conversation()->create($items, 'contact-posts', $update);
+ $o .= DI::conversation()->create($items, Conversation::MODE_CONTACT_POSTS, $update);
}
if (!$update) {
return false;
}
- if (!empty($item['uid']) && !self::isAllowedByUser($item, $item['uid'])) {
- return false;
- }
-
if ($item['verb'] == Activity::FOLLOW) {
if (!$item['origin'] && ($item['author-id'] == Contact::getPublicIdByUserId($item['uid']))) {
// Our own follow request can be relayed to us. We don't store it to avoid notification chaos.
return 0;
}
- // If the thread originated from this node, we check the permission against the thread starter
- $condition = ['uri-id' => $toplevel_parent['uri-id'], 'wall' => true];
- $localTopLevelParent = Post::selectFirst(['uid'], $condition);
- if (!empty($localTopLevelParent['uid']) && !self::isAllowedByUser($item, $localTopLevelParent['uid'])) {
- return 0;
- }
-
$parent_id = $toplevel_parent['id'];
$item['parent-uri'] = $toplevel_parent['uri'];
$item['parent-uri-id'] = $toplevel_parent['uri-id'];
// Compile eventual content filter reasons
$filter_reasons = [];
if (!$is_preview && DI::userSession()->getPublicContactId() != $item['author-id']) {
- if (Contact\User::isCollapsed($item['author-id'], $item['uid'])) {
+ if (!empty($item['user-blocked-author']) || !empty($item['user-blocked-owner'])) {
+ $filter_reasons[] = DI::l10n()->t('%s is blocked', $item['author-name']);
+ } elseif (!empty($item['user-ignored-author']) || !empty($item['user-ignored-owner'])) {
+ $filter_reasons[] = DI::l10n()->t('%s is ignored', $item['author-name']);
+ } elseif (!empty($item['user-collapsed-author']) || !empty($item['user-collapsed-owner'])) {
$filter_reasons[] = DI::l10n()->t('Content from %s is collapsed', $item['author-name']);
}
return 0;
}
- /**
- * Check a prospective item array against user-level permissions
- *
- * @param array $item Expected keys: uri, gravity, and
- * author-link if is author-id is set,
- * owner-link if is owner-id is set,
- * causer-link if is causer-id is set.
- * @param int $user_id Local user ID
- * @return bool
- * @throws \Exception
- */
- protected static function isAllowedByUser(array $item, int $user_id): bool
- {
- if (!empty($item['author-id']) && Contact\User::isBlocked($item['author-id'], $user_id)) {
- Logger::notice('Author is blocked by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
- return false;
- }
-
- if (!empty($item['owner-id']) && Contact\User::isBlocked($item['owner-id'], $user_id)) {
- Logger::notice('Owner is blocked by user', ['owner-link' => $item['owner-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
- return false;
- }
-
- // The causer is set during a thread completion, for example because of a reshare. It countains the responsible actor.
- if (!empty($item['causer-id']) && Contact\User::isBlocked($item['causer-id'], $user_id)) {
- Logger::notice('Causer is blocked by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
- return false;
- }
-
- if (!empty($item['author-id']) && Contact\User::isIgnored($item['author-id'], $user_id)) {
- Logger::notice('Author is ignored by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
- return false;
- }
-
- if (!empty($item['owner-id']) && Contact\User::isIgnored($item['owner-id'], $user_id)) {
- Logger::notice('Owner is ignored by user', ['owner-link' => $item['owner-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
- return false;
- }
-
- if (!empty($item['causer-id']) && 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']]);
- return false;
- }
-
- return true;
- }
-
/**
* Fetch the uri-id of a quote
*
use Friendica\BaseModule;
use Friendica\Content\BoundariesPager;
+use Friendica\Content\Conversation;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Text\HTML;
return $o;
}
- $o .= DI::conversation()->create($items, 'community', false, false, 'commented', DI::userSession()->getLocalUserId());
+ $o .= DI::conversation()->create($items, Conversation::MODE_COMMUNITY, false, false, 'commented', DI::userSession()->getLocalUserId());
$pager = new BoundariesPager(
DI::l10n(),
use Friendica\BaseModule;
use Friendica\Content\BoundariesPager;
+use Friendica\Content\Conversation;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
use Friendica\Content\Widget;
$ordering = '`commented`';
}
- $o .= DI::conversation()->create($items, 'network', false, false, $ordering, DI::userSession()->getLocalUserId());
+ $o .= DI::conversation()->create($items, Conversation::MODE_NETWORK, false, false, $ordering, DI::userSession()->getLocalUserId());
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
$output .= $this->conversation->statusEditor([], 0, true);
}
- $output .= $this->conversation->create([$item], 'display', $updateUid, false, 'commented', $itemUid);
+ $output .= $this->conversation->create([$item], Conversation::MODE_DISPLAY, $updateUid, false, 'commented', $itemUid);
return $output;
}
$items = array_merge($items, $pinned);
}
- $o .= $this->conversation->create($items, 'profile', false, false, 'pinned_received', $profile['uid']);
+ $o .= $this->conversation->create($items, Conversation::MODE_PROFILE, false, false, 'pinned_received', $profile['uid']);
$o .= $pager->renderMinimal(count($items));
namespace Friendica\Module\Search;
+use Friendica\Content\Conversation;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
- $o .= DI::conversation()->create($items, 'filed', false, false, '', DI::userSession()->getLocalUserId());
+ $o .= DI::conversation()->create($items, Conversation::MODE_FILED, false, false, '', DI::userSession()->getLocalUserId());
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
namespace Friendica\Module\Search;
use Friendica\App;
+use Friendica\Content\Conversation;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
Logger::info('Start Conversation.', ['q' => $search]);
- $o .= DI::conversation()->create($items, 'search', false, false, 'commented', DI::userSession()->getLocalUserId());
+ $o .= DI::conversation()->create($items, Conversation::MODE_SEARCH, false, false, 'commented', DI::userSession()->getLocalUserId());
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
namespace Friendica\Module\Update;
+use Friendica\Content\Conversation;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\Conversation\Community as CommunityModule;
$o = '';
if (!empty($request['force'])) {
- $o = DI::conversation()->create(self::getItems(), 'community', true, false, 'commented', DI::userSession()->getLocalUserId());
+ $o = DI::conversation()->create(self::getItems(), Conversation::MODE_COMMUNITY, true, false, 'commented', DI::userSession()->getLocalUserId());
}
System::htmlUpdateExit($o);
namespace Friendica\Module\Update;
+use Friendica\Content\Conversation;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
$ordering = '`commented`';
}
- $o = DI::conversation()->create($items, 'network', $profile_uid, false, $ordering, DI::userSession()->getLocalUserId());
+ $o = DI::conversation()->create($items, Conversation::MODE_NETWORK, $profile_uid, false, $ordering, DI::userSession()->getLocalUserId());
System::htmlUpdateExit($o);
}
namespace Friendica\Module\Update;
use Friendica\BaseModule;
+use Friendica\Content\Conversation;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
}
}
- $o .= DI::conversation()->create($items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
+ $o .= DI::conversation()->create($items, Conversation::MODE_PROFILE, $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
System::htmlUpdateExit($o);
}