class Conversation
{
+ const MODE_CHANNEL = 'channel';
const MODE_COMMUNITY = 'community';
const MODE_CONTACTS = 'contacts';
const MODE_CONTACT_POSTS = 'contact-posts';
/**
* Format the activity text for an item/photo/video
*
- * @param array $links = array of pre-linked names of actors
- * @param string $verb = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
- * @param int $id = item id
+ * @param array $links array of pre-linked names of actors
+ * @param string $verb one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
+ * @param int $id item id
+ * @param string $activity Activity URI
+ * @param array $emojis Array with emoji reactions
* @return string formatted text
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public function formatActivity(array $links, string $verb, int $id): string
+ public function formatActivity(array $links, string $verb, int $id, string $activity, array $emojis): string
{
$this->profiler->startRecording('rendering');
$expanded = '';
$phrase = $this->getLikerPhrase($verb, $links);
- $total = count($links);
+ $total = max(count($links), $emojis[$activity]['total'] ?? 0);
if ($total > 1) {
$spanatts = "class=\"btn btn-link fakelink\" onclick=\"openClose('{$verb}list-$id');\"";
. (!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']) : '')
. "'; </script>\r\n";
}
} elseif ($mode === self::MODE_PROFILE) {
. "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
. "</script>";
}
+ } elseif ($mode === self::MODE_CHANNEL) {
+ $items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids);
+
+ if (!$update) {
+ $live_update_div = '<div id="live-channel"></div>' . "\r\n"
+ . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
+ . '?f='
+ . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
+ . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
+ . "'; </script>\r\n";
+ }
} elseif ($mode === self::MODE_COMMUNITY) {
$items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids);
$live_update_div = '<div id="live-search"></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();
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);
$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]);
}
continue;
}
- if (in_array($row['author-gsid'], $ignoredGsids)
+ if (
+ in_array($row['author-gsid'], $ignoredGsids)
|| in_array($row['owner-gsid'], $ignoredGsids)
|| in_array($row['causer-gsid'], $ignoredGsids)
) {
}
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]);
$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]);
];
$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;
}
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.
*