From 1dd48e4a8bed8ddee15f2f244f6c3a1c589f10dd Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Nov 2023 12:57:54 +0000 Subject: [PATCH] Frio: The activity buttons now have got counters --- src/Content/Conversation.php | 15 +- src/Model/Event.php | 2 +- src/Object/Post.php | 39 ++- view/global.css | 6 + view/theme/frio/css/style.css | 2 + view/theme/frio/templates/wall_thread.tpl | 292 +++++++++++----------- 6 files changed, 201 insertions(+), 155 deletions(-) diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index c52517cf8a..9cf85b6feb 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -1056,19 +1056,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; } diff --git a/src/Model/Event.php b/src/Model/Event.php index 6f77832209..ab52fb279e 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -636,7 +636,7 @@ class Event { $fmt = DI::l10n()->t('l, F j'); - $item = Post::selectFirst(['plink', 'author-name', 'author-network', 'author-id', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]); + $item = Post::selectFirst(['plink', 'author-name', 'author-network', 'author-id', 'author-avatar', 'author-link', 'author-alias', 'private', 'uri-id'], ['id' => $event['itemid']]); if (empty($item)) { // Using default values when no item had been found $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC, 'uri-id' => ($event['uri-id'] ?? 0)]; diff --git a/src/Object/Post.php b/src/Object/Post.php index 8d7ff128dc..ed0e2977c7 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -320,7 +320,7 @@ class Post $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: ''); // process action responses - e.g. like/dislike/attend/agree/whatever - $response_verbs = ['like', 'dislike', 'announce']; + $response_verbs = ['like', 'dislike', 'announce', 'comment']; $isevent = false; $attend = []; @@ -335,14 +335,31 @@ class Post } } + $emojis = $this->getEmojis($item); + + $verbs = [ + 'like' => Activity::LIKE, + 'dislike' => Activity::DISLIKE, + 'announce' => Activity::ANNOUNCE, + 'comment' => Activity::POST, + 'attendyes' => Activity::ATTEND, + 'attendno' => Activity::ATTENDNO, + 'attendmaybe' => Activity::ATTENDMAYBE, + ]; + $reactions = $emojis; $responses = []; foreach ($response_verbs as $value => $verb) { $responses[$verb] = [ 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0, 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? DI::conversation()->formatActivity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '', + 'total' => $emojis[$verbs[$verb]]['total'] ?? '', + 'title' => $emojis[$verbs[$verb]]['title'] ?? '', ]; + unset($reactions[$verbs[$verb]]); } + unset($emojis[Activity::POST]); + /* * We should avoid doing this all the time, but it depends on the conversation mode * And the conv mode may change when we change the conv, or it changes its mode @@ -576,7 +593,8 @@ class Post 'vote' => $buttons, 'like_html' => $responses['like']['output'], 'dislike_html' => $responses['dislike']['output'], - 'emojis' => $this->getEmojis($item), + 'emojis' => $emojis, + 'reactions' => $reactions, 'responses' => $responses, 'switchcomment' => DI::l10n()->t('Comment'), 'reply_label' => DI::l10n()->t('Reply to %s', $profile_name), @@ -667,46 +685,59 @@ class Post case Activity::ANNOUNCE: $title = DI::l10n()->t('Reshared by: %s', $actors); $icon = ['fa' => 'fa-retweet', 'icon' => 'icon-retweet']; + $verb = Activity::ANNOUNCE; break; case Activity::VIEW: $title = DI::l10n()->t('Viewed by: %s', $actors); $icon = ['fa' => 'fa-eye', 'icon' => 'icon-eye-open']; + $verb = Activity::VIEW; break; case Activity::LIKE: $title = DI::l10n()->t('Liked by: %s', $actors); $icon = ['fa' => 'fa-thumbs-up', 'icon' => 'icon-thumbs-up']; + $verb = Activity::LIKE; break; case Activity::DISLIKE: $title = DI::l10n()->t('Disliked by: %s', $actors); $icon = ['fa' => 'fa-thumbs-down', 'icon' => 'icon-thumbs-down']; + $verb = Activity::DISLIKE; break; case Activity::ATTEND: $title = DI::l10n()->t('Attended by: %s', $actors); $icon = ['fa' => 'fa-check', 'icon' => 'icon-ok']; + $verb = Activity::ATTEND; break; case Activity::ATTENDMAYBE: $title = DI::l10n()->t('Maybe attended by: %s', $actors); $icon = ['fa' => 'fa-question', 'icon' => 'icon-question']; + $verb = Activity::ATTENDMAYBE; break; case Activity::ATTENDNO: $title = DI::l10n()->t('Not attended by: %s', $actors); $icon = ['fa' => 'fa-times', 'icon' => 'icon-remove']; + $verb = Activity::ATTENDNO; break; + case Activity::POST: + $title = DI::l10n()->t('Commented by: %s', $actors); + $icon = ['fa' => 'fa-commenting', 'icon' => 'icon-remove']; + $verb = Activity::POST; + break; + default: $title = DI::l10n()->t('Reacted with %s by: %s', $element['emoji'], $actors); $icon = []; + $verb = $element['emoji']; break; } - $emojis[$index] = ['emoji' => $element['emoji'], 'total' => $element['total'], 'title' => $title, 'icon' => $icon]; + $emojis[$verb] = ['emoji' => $element['emoji'], 'total' => $element['total'], 'title' => $title, 'icon' => $icon]; } - ksort($emojis); return $emojis; } diff --git a/view/global.css b/view/global.css index ecab5a1c15..aab6e8d67d 100644 --- a/view/global.css +++ b/view/global.css @@ -110,6 +110,12 @@ span.connector { margin: 0; } +.wall-item-response { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + .type-link blockquote, .type-video blockquote { margin-left: 0px; max-height: 160px; diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 3618fa1520..6e1668a3e3 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -1985,6 +1985,8 @@ code > .hl-main { .wall-item-actions button { color: $font_color_darker; background-color: transparent; + padding-left: 5px; + padding-right: 5px; } .wall-item-actions .active { font-weight: bold; diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 5615d704af..2dcbade22c 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -309,18 +309,22 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.vote}} {{if $item.vote.like}} - - {{/if}} - {{if $item.vote.like AND $item.vote.dislike}} - + + + {{$item.responses.like.total}} + {{/if}} {{if $item.vote.dislike}} - + + + {{$item.responses.dislike.total}} + {{/if}} + - {{if ($item.vote.like OR $item.vote.dislike) AND $item.comment_html}} - - {{/if}} + {{foreach $item.reactions as $emoji}} + {{$emoji.emoji}} {{$emoji.total}} + {{/foreach}} {{/if}} {{if $item.remote_comment}} @@ -329,138 +333,146 @@ as the value of $top_child_total (this is done at the end of this file) {{* Button to open the comment text field *}} {{if $item.comment_html}} - + + + {{$item.responses.comment.total}} + {{/if}} {{* Button for sharing the item *}} {{if $item.vote}} - {{if $item.vote.share OR $item.vote.announce}} - {{if $item.vote.like OR $item.vote.dislike OR $item.comment_html}} - - {{/if}} - {{/if}} {{if $item.vote.announce}} - - + + + {{$item.responses.announce.total}} + {{/if}} {{if $item.vote.share}} - + + + {{/if}} {{/if}} - - {{* Put additional actions in a dropdown menu *}} - - - - - - - -