X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FConversation.php;h=66654aab102c5740906873d5c891fcdf003a418d;hb=5cf71baf551bf209e62cf13b16173bddcd76a0fc;hp=710422ee762cc162e411b8dd496a4c8e751fb2c3;hpb=4a645bec27a3bb1481b9ec046bfe9aa57f59a485;p=friendica.git diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index 710422ee76..66654aab10 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -38,6 +38,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Item as ItemModel; use Friendica\Model\Post; +use Friendica\Model\Post\Category; use Friendica\Model\Tag; use Friendica\Model\User; use Friendica\Model\Verb; @@ -45,6 +46,8 @@ use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Object\Post as PostObject; use Friendica\Object\Thread; use Friendica\Protocol\Activity; +use Friendica\User\Settings\Entity\UserGServer; +use Friendica\User\Settings\Repository; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Profiler; @@ -54,6 +57,7 @@ use Psr\Log\LoggerInterface; class Conversation { + const MODE_CHANNEL = 'channel'; const MODE_COMMUNITY = 'community'; const MODE_CONTACTS = 'contacts'; const MODE_CONTACT_POSTS = 'contact-posts'; @@ -90,22 +94,25 @@ class Conversation private $mode; /** @var IHandleUserSessions */ private $session; + /** @var Repository\UserGServer */ + private $userGServer; - public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleUserSessions $session) + public function __construct(Repository\UserGServer $userGServer, LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleUserSessions $session) { - $this->activity = $activity; - $this->item = $item; - $this->config = $config; - $this->mode = $mode; - $this->baseURL = $baseURL; - $this->profiler = $profiler; - $this->logger = $logger; - $this->l10n = $l10n; - $this->args = $args; - $this->pConfig = $pConfig; - $this->page = $page; - $this->app = $app; - $this->session = $session; + $this->activity = $activity; + $this->item = $item; + $this->config = $config; + $this->mode = $mode; + $this->baseURL = $baseURL; + $this->profiler = $profiler; + $this->logger = $logger; + $this->l10n = $l10n; + $this->args = $args; + $this->pConfig = $pConfig; + $this->page = $page; + $this->app = $app; + $this->session = $session; + $this->userGServer = $userGServer; } /** @@ -459,8 +466,14 @@ class Conversation $live_update_div = ''; + $userGservers = $this->userGServer->listIgnoredByUser($this->session->getLocalUserId()); + + $ignoredGsids = array_map(function (UserGServer $userGServer) { + return $userGServer->gsid; + }, $userGservers->getArrayCopy()); + if ($mode === self::MODE_NETWORK) { - $items = $this->addChildren($items, false, $order, $uid, $mode); + $items = $this->addChildren($items, false, $order, $uid, $mode, $ignoredGsids); if (!$update) { /* * The special div is needed for liveUpdate to kick in for this page. @@ -482,11 +495,13 @@ class Conversation . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '') . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '') . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '') - + . (!empty($_GET['channel']) ? '&channel=' . rawurlencode($_GET['channel']) : '') + . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '') + . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '') . "'; \r\n"; } } elseif ($mode === self::MODE_PROFILE) { - $items = $this->addChildren($items, false, $order, $uid, $mode); + $items = $this->addChildren($items, false, $order, $uid, $mode, $ignoredGsids); if (!$update) { $tab = !empty($_GET['tab']) ? trim($_GET['tab']) : 'posts'; @@ -511,15 +526,26 @@ class Conversation . "; var netargs = '?f='; \r\n"; } } elseif ($mode === self::MODE_DISPLAY) { - $items = $this->addChildren($items, false, $order, $uid, $mode); + $items = $this->addChildren($items, false, $order, $uid, $mode, $ignoredGsids); if (!$update) { $live_update_div = '
' . "\r\n" . ""; } + } elseif ($mode === self::MODE_CHANNEL) { + $items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids); + + if (!$update) { + $live_update_div = '
' . "\r\n" + . "\r\n"; + } } elseif ($mode === self::MODE_COMMUNITY) { - $items = $this->addChildren($items, true, $order, $uid, $mode); + $items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids); if (!$update) { $live_update_div = '
' . "\r\n" @@ -530,7 +556,7 @@ class Conversation . "'; \r\n"; } } elseif ($mode === self::MODE_CONTACTS) { - $items = $this->addChildren($items, false, $order, $uid, $mode); + $items = $this->addChildren($items, false, $order, $uid, $mode, $ignoredGsids); if (!$update) { $live_update_div = '
' . "\r\n" @@ -541,7 +567,7 @@ class Conversation $live_update_div = '' . "\r\n"; } - $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH; + $page_dropping = $this->session->getLocalUserId() && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'show_page_drop', true) && ($this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH); if (!$update) { $_SESSION['return_path'] = $this->args->getQueryString(); @@ -609,7 +635,7 @@ class Conversation unset($conv_responses['dislike']); } - if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) { + if (in_array($mode, [self::MODE_CHANNEL, 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); @@ -743,7 +769,12 @@ class Conversation $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])]; break; case ItemModel::PR_TAG: - $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; + $tags = Category::getArrayByURIId($row['uri-id'], $row['uid'], Category::SUBCRIPTION); + if (!empty($tags)) { + $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to %s.', implode(', ', $tags))]; + } else { + $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')]; + } break; case ItemModel::PR_ANNOUNCEMENT: if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) { @@ -812,13 +843,14 @@ class Conversation * * @param array $parents Parent items * @param bool $block_authors - * @param bool $order + * @param string $order Either "received" or "commented" * @param int $uid - * @param string $mode + * @param string $mode One of self::MODE_* + * @param array $ignoredGsids List of ids of servers ignored by the user * @return array items with parents and comments - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ - private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode): array + private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode, array $ignoredGsids = []): array { $this->profiler->startRecording('rendering'); if (count($parents) > 1) { @@ -857,8 +889,10 @@ class Conversation $condition['author-hidden'] = false; } - if ($this->config->get('system', 'emoji_activities')) { - $emojis = $this->getEmojis($uriids); + $emojis = $this->getEmojis($uriids); + $quoteshares = $this->getQuoteShares($uriids); + + if (!$this->config->get('system', 'legacy_activities')) { $condition = DBA::mergeConditions($condition, ["(`gravity` != ? OR `origin`)", ItemModel::GRAVITY_ACTIVITY]); } @@ -900,6 +934,14 @@ class Conversation continue; } + if ( + in_array($row['author-gsid'], $ignoredGsids) + || in_array($row['owner-gsid'], $ignoredGsids) + || in_array($row['causer-gsid'], $ignoredGsids) + ) { + continue; + } + if (($mode != self::MODE_CONTACTS) && !$row['origin']) { $row['featured'] = false; } @@ -972,7 +1014,8 @@ class Conversation } foreach ($items as $key => $row) { - $items[$key]['emojis'] = $emojis[$key] ?? []; + $items[$key]['emojis'] = $emojis[$key] ?? []; + $items[$key]['quoteshares'] = $quoteshares[$key] ?? []; $always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]); @@ -984,7 +1027,7 @@ class Conversation $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($mode, [self::MODE_CHANNEL, 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]); @@ -1016,19 +1059,24 @@ class Conversation ]; $index_list = array_values($activity_emoji); - $verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT]); + $verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT, Activity::POST]); - $condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => ItemModel::GRAVITY_ACTIVITY, 'verb' => $verbs], ["NOT `deleted`"]); + $condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => [ItemModel::GRAVITY_ACTIVITY, ItemModel::GRAVITY_COMMENT], 'verb' => $verbs], ["NOT `deleted`"]); $separator = chr(255) . chr(255) . chr(255); - $sql = "SELECT `thr-parent-id`, `body`, `verb`, COUNT(*) AS `total`, GROUP_CONCAT(REPLACE(`author-name`, '" . $separator . "', ' ') SEPARATOR '" . $separator . "' LIMIT 50) AS `title` FROM `post-view` WHERE " . array_shift($condition) . " GROUP BY `thr-parent-id`, `verb`, `body`"; + $sql = "SELECT `thr-parent-id`, `body`, `verb`, `gravity`, COUNT(*) AS `total`, GROUP_CONCAT(REPLACE(`author-name`, '" . $separator . "', ' ') SEPARATOR '" . $separator . "' LIMIT 50) AS `title` FROM `post-view` WHERE " . array_shift($condition) . " GROUP BY `thr-parent-id`, `verb`, `body`, `gravity`"; $emojis = []; $rows = DBA::p($sql, $condition); while ($row = DBA::fetch($rows)) { - $row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb']; - $emoji = $row['body'] ?: $activity_emoji[$row['verb']]; + if ($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) { + $row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb']; + $emoji = $row['body'] ?: $activity_emoji[$row['verb']]; + } else { + $emoji = ''; + } + if (!isset($index_list[$emoji])) { $index_list[] = $emoji; } @@ -1044,6 +1092,31 @@ class Conversation return $emojis; } + /** + * Fetch quote shares from the conversation + * + * @param array $uriids + * @return array + */ + private function getQuoteShares(array $uriids): array + { + $condition = DBA::mergeConditions(['quote-uri-id' => $uriids], ["NOT `quote-uri-id` IS NULL"]); + $separator = chr(255) . chr(255) . chr(255); + + $sql = "SELECT `quote-uri-id`, COUNT(*) AS `total`, GROUP_CONCAT(REPLACE(`name`, '" . $separator . "', ' ') SEPARATOR '" . $separator . "' LIMIT 50) AS `title` FROM `post-content` INNER JOIN `post` ON `post`.`uri-id` = `post-content`.`uri-id` INNER JOIN `contact` ON `post`.`author-id` = `contact`.`id` WHERE " . array_shift($condition) . " GROUP BY `quote-uri-id`"; + + $quotes = []; + + $rows = DBA::p($sql, $condition); + while ($row = DBA::fetch($rows)) { + $quotes[$row['quote-uri-id']]['total'] = $row['total']; + $quotes[$row['quote-uri-id']]['title'] = array_unique(explode($separator, $row['title'])); + } + DBA::close($rows); + + return $quotes; + } + /** * Plucks the children of the given parent from a given item list. * @@ -1462,6 +1535,7 @@ class Conversation 'received' => $item['received'], 'created_date' => $item['created'], 'uriid' => $item['uri-id'], + 'author_gsid' => $item['author-gsid'], 'network' => $item['network'], 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']), 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),