A platform for community discussion. Free, open, simple.
FEATURE: view all post reactions and likes (#39283)
David Battersbybe0d7f77ffb4
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scssindex facd611cafc..3c08f9e16af 100644--- a/app/assets/stylesheets/common/base/topic-post.scss+++ b/app/assets/stylesheets/common/base/topic-post.scss@@ -415,9 +415,13 @@ nav.post-controls {gap: var(--space-1);}- .post-action-menu__double-button {+ .post-action-menu__like {+ &.has-like .d-icon {+ color: var(--love);+ }+.discourse-no-touch & {- &:not(.has-liked):hover {+ &:not(.has-like):hover {--d-post-control-background--hover: var(--love-low);--d-button-flat-icon-color--hover: var(--love);}@@ -2165,6 +2169,175 @@ html.discourse-no-touch .fullscreen-table-wrapper:hover {}}+.post-action-menu__like-count {+ color: var(--d-post-control-text-color) !important;+ gap: var(--space-2);++ &.has-liked .d-icon {+ color: var(--danger);+ }+}++.post-users-popup {+ width: 300px;+ background: var(--secondary);+ color: var(--primary);+ line-height: normal;+ border-radius: 10px;++ &__title {+ padding: 0.25em 0.5em 0.75em;+ text-align: center;+ font-weight: 600;+ border-bottom: 1px solid var(--primary-low);+ }++ &__header {+ display: flex;+ align-items: center;+ gap: 0.25em;+ padding: 0.5em 0.65em;+ border-bottom: 1px solid var(--primary-low);+ border-radius: 10px 10px 0 0;+ overflow-x: auto;+ -webkit-overflow-scrolling: touch;++ &::-webkit-scrollbar {+ display: none;+ }+ }++ &__filter {+ display: inline-flex;+ align-items: center;+ gap: 0.3em;+ padding: 0.3em 0.6em;+ border: none;+ border-radius: 6px;+ background: transparent;+ color: var(--primary-medium);+ font-size: var(--font-down-1);+ cursor: pointer;+ white-space: nowrap;+ transition: background 0.15s;++ .emoji {+ width: 1.15em;+ height: 1.15em;+ }++ &:hover {+ background: var(--primary-very-low);+ }++ &.is-active {+ background: var(--tertiary-low);+ color: var(--primary);+ font-weight: 600;+ }+ }++ &__body {+ height: 320px;+ overflow-y: auto;+ overscroll-behavior: contain;+ padding-top: 0.35em;+ border-radius: 0 0 10px 10px;++ &:first-child {+ border-radius: 10px;+ }+ }++ &__item {+ display: flex;+ align-items: center;+ gap: 0.5em;+ padding: 0.45em 0.75em;++ &:hover {+ background: var(--primary-very-low);+ }+ }++ &__avatar-link {+ flex-shrink: 0;+ display: flex;++ .avatar {+ border-radius: 50%;+ background: var(--primary-very-low);+ }+ }++ &__user-info {+ flex: 1;+ min-width: 0;+ display: flex;+ flex-direction: column;+ align-items: flex-start;+ }++ &__name {+ color: var(--primary) !important;+ font-weight: 600;+ font-size: var(--font-down-1);+ text-decoration: none;+ text-align: left;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ max-width: 100%;++ &:hover {+ text-decoration: underline;+ }+ }++ &__username {+ color: var(--primary-medium) !important;+ font-size: var(--font-down-2);+ text-decoration: none;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;++ &:hover {+ text-decoration: underline;+ }+ }++ &__reaction {+ color: var(--danger);+ flex-shrink: 0;+ margin-left: auto;++ .emoji {+ width: 1.15em;+ height: 1.15em;+ }+ }++ &__loading {+ display: flex;+ justify-content: center;+ padding: 0.75em;+ }+}++.mobile-view .post-users-popup {+ width: 100%;+ height: 400px;+ display: flex;+ flex-direction: column;++ .post-users-popup__body {+ flex: 1;+ height: auto;+ min-height: 0;+ }+}+.time-gap + .topic-post .topic-body,.time-gap + .topic-post .topic-avatar {border-top: none;diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 5136e3039fd..8d0389b7723 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4527,6 +4527,11 @@ en:sr_post_like_count_button:one: "%{count} person liked this post."other: "%{count} people liked this post."++ likes_popup:+ title:+ one: "%{count} like"+ other: "%{count} likes"sr_post_read_count_button:one: "%{count} person read this post."other: "%{count} people read this post."diff --git a/frontend/discourse/app/components/card-contents-base.js b/frontend/discourse/app/components/card-contents-base.jsindex 13ac7313059..53902176a2e 100644--- a/frontend/discourse/app/components/card-contents-base.js+++ b/frontend/discourse/app/components/card-contents-base.js@@ -10,7 +10,11 @@ import { headerOffset } from "discourse/lib/offset-calculator";import DiscourseURL from "discourse/lib/url";import { escapeExpression } from "discourse/lib/utilities";-const DEFAULT_SELECTORS = ["#main-outlet", "#d-menu-portals"];+const DEFAULT_SELECTORS = [+ "#main-outlet",+ "#d-menu-portals",+ ".modal-container",+];const AVATAR_OVERFLOW_SIZE = 44;const MOBILE_SCROLL_EVENT = "scroll.mobile-card-cloak";diff --git a/frontend/discourse/app/components/post/menu.gjs b/frontend/discourse/app/components/post/menu.gjsindex a01b393b248..979ce2c9aec 100644--- a/frontend/discourse/app/components/post/menu.gjs+++ b/frontend/discourse/app/components/post/menu.gjs@@ -33,6 +33,7 @@ import PostMenuDeleteButton from "./menu/buttons/delete";import PostMenuEditButton from "./menu/buttons/edit";import PostMenuFlagButton from "./menu/buttons/flag";import PostMenuLikeButton from "./menu/buttons/like";+import PostMenuLikeCountButton from "./menu/buttons/like-count";import PostMenuReadButton from "./menu/buttons/read";import PostMenuRepliesButton from "./menu/buttons/replies";import PostMenuReplyButton from "./menu/buttons/reply";@@ -50,6 +51,7 @@ const buttonKeys = Object.freeze({EDIT: "edit",FLAG: "flag",LIKE: "like",+ LIKE_COUNT: "likeCount",READ: "read",REPLIES: "replies",REPLY: "reply",@@ -66,6 +68,7 @@ const coreButtonComponents = new Map([[buttonKeys.EDIT, PostMenuEditButton],[buttonKeys.FLAG, PostMenuFlagButton],[buttonKeys.LIKE, PostMenuLikeButton],+ [buttonKeys.LIKE_COUNT, PostMenuLikeCountButton],[buttonKeys.READ, PostMenuReadButton],[buttonKeys.REPLIES, PostMenuRepliesButton],[buttonKeys.REPLY, PostMenuReplyButton],diff --git a/frontend/discourse/app/components/post/menu/buttons/like-count.gjs b/frontend/discourse/app/components/post/menu/buttons/like-count.gjsnew file mode 100644index 00000000000..c9c668b74ab--- /dev/null+++ b/frontend/discourse/app/components/post/menu/buttons/like-count.gjs@@ -0,0 +1,12 @@+import Component from "@glimmer/component";+import LikedUsersList from "../liked-users-list";++export default class PostMenuLikeCountButton extends Component {+ static extraControls = true;++ static shouldRender(args) {+ return args.post.likeCount > 0;+ }++ <template><LikedUsersList ...attributes @post={{@post}} /></template>+}diff --git a/frontend/discourse/app/components/post/menu/buttons/like.gjs b/frontend/discourse/app/components/post/menu/buttons/like.gjsindex 3f233eb90a1..15944fc9695 100644--- a/frontend/discourse/app/components/post/menu/buttons/like.gjs+++ b/frontend/discourse/app/components/post/menu/buttons/like.gjs@@ -6,11 +6,10 @@ import DButton from "discourse/components/d-button";import concatClass from "discourse/helpers/concat-class";import discourseLater from "discourse/lib/later";import { applyValueTransformer } from "discourse/lib/transformer";-import LikedUsersList from "../liked-users-list";export default class PostMenuLikeButton extends Component {static shouldRender(args) {- const show = args.post.showLike || args.post.likeCount > 0;+ const show = args.post.showLike;return applyValueTransformer("like-button-render-decision", show, {post: args.post,});@@ -59,39 +58,22 @@ export default class PostMenuLikeButton extends Component {}<template>- {{#if @post.showLike}}- <div- class={{concatClass- "double-button"- (if @post.liked "has-liked" "")- "post-action-menu__double-button"- }}- >- {{#if @post.likeCount}}- <LikedUsersList ...attributes @post={{@post}} />- {{/if}}- <DButton- class={{concatClass- "post-action-menu__like"- "toggle-like"- "btn-icon"- (if this.isAnimated "heart-animation")- (if @post.liked "has-like" "like")- }}- ...attributes- data-post-id={{@post.id}}- disabled={{this.disabled}}- @action={{this.toggleLike}}- @icon={{this.likeButtonIcon}}- @label={{if @showLabel "post.controls.like_action"}}- @title={{this.title}}- @ariaLabel={{this.title}}- />- </div>- {{else}}- <div class="double-button">- <LikedUsersList ...attributes @post={{@post}} />- </div>- {{/if}}+ <DButton+ class={{concatClass+ "post-action-menu__like"+ "toggle-like"+ "btn-icon"+ (if this.isAnimated "heart-animation")+ (if @post.liked "has-like" "like")+ }}+ ...attributes+ data-post-id={{@post.id}}+ disabled={{this.disabled}}+ @action={{this.toggleLike}}+ @icon={{this.likeButtonIcon}}+ @label={{if @showLabel "post.controls.like_action"}}+ @title={{this.title}}+ @ariaLabel={{this.title}}+ /></template>}diff --git a/frontend/discourse/app/components/post/menu/liked-users-list.gjs b/frontend/discourse/app/components/post/menu/liked-users-list.gjsindex b3962bcd00f..afd14503364 100644--- a/frontend/discourse/app/components/post/menu/liked-users-list.gjs+++ b/frontend/discourse/app/components/post/menu/liked-users-list.gjs@@ -1,167 +1,56 @@import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";import { action } from "@ember/object";import { service } from "@ember/service";-import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";-import DButton from "discourse/components/d-button";-import PluginOutlet from "discourse/components/plugin-outlet";-import UserAvatar from "discourse/components/user-avatar";-import DMenu from "discourse/float-kit/components/d-menu";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";-import lazyHash from "discourse/helpers/lazy-hash";import { i18n } from "discourse-i18n";+import PostLikedUsersMenu from "./liked-users-menu";-const LIKE_ACTION = 2; // The action type ID for "like" in Discourse-const DISPLAY_MAX_USERS = 8; // will show X users, then a button to show one more row of X;+const MENU_IDENTIFIER = "post-liked-users-menu";export default class LikedUsersList extends Component {- @service store;+ @service menu;- @tracked likedUsers;- @tracked loadingLikedUsers = false;- @tracked slicedUsersVisible = false;-- @action- async fetchLikedUsers() {- if (this.loadingLikedUsers) {- return;- }-- this.loadingLikedUsers = true;-- try {- this.likedUsers = await this.store.find("post-action-user", {- id: this.args.post.id,- post_action_type_id: LIKE_ACTION,- });- } finally {- this.loadingLikedUsers = false;- }+ get buttonIcon() {+ return this.args.post.liked || this.args.post.yours+ ? "d-liked"+ : "d-unliked";}@action- toggleSlicedUsersVisiblity() {- this.slicedUsersVisible = !this.slicedUsersVisible;- }-- get icon() {- if (!this.args.post.showLike) {- return this.args.post.yours ? "d-liked" : "d-unliked";- }-- if (this.args.post.yours) {- return "d-liked";- }- }-- get truncatedUsers() {- return this.likedUsers?.content.slice(0, DISPLAY_MAX_USERS);- }-- get slicedUsers() {- return this.likedUsers?.content.slice(- DISPLAY_MAX_USERS,- DISPLAY_MAX_USERS * 2- );- }-- get hiddenUserCount() {- return (- this.likedUsers?.length -- (this.truncatedUsers.length + this.slicedUsers.length)- );- }-- get toggleSlicedUsersVisiblityIcon() {- return this.slicedUsersVisible ? "angle-up" : "angle-down";+ togglePopup(event) {+ this.menu.show(event.currentTarget, {+ identifier: MENU_IDENTIFIER,+ component: PostLikedUsersMenu,+ modalForMobile: true,+ closeOnScroll: true,+ placement: "bottom",+ offset: 10,+ data: { post: this.args.post },+ });}<template>- <DMenu- @modalForMobile={{true}}- @identifier="post-like-users_{{@post.id}}"- @onShow={{this.fetchLikedUsers}}- @triggerClass={{concatClass+ <button+ type="button"+ aria-label={{i18n "post.sr_post_like_count_button" [email protected]}}+ class={{concatClass+ "btn btn-flat no-text""post-action-menu__like-count""like-count"- "btn-flat""button-count""highlight-action"+ (if @post.liked "has-liked")(if @post.yours "my-likes" "regular-likes")}}- @icon={{if @post.yours "d-liked" ""}}- @placement="top"- label={{i18n "post.sr_post_like_count_button" [email protected]}}- id="post-like-users_{{@post.id}}"+ {{on "click" this.togglePopup}}+ ...attributes>- <:trigger>- {{@post.likeCount}}- </:trigger>- <:content>- <ConditionalLoadingSpinner- @condition={{this.loadingLikedUsers}}- class="liked-users-list__container"- >- <span class="liked-users-list__count">- {{icon "d-liked" class="liked-users-list__count-icon"}}- {{@post.likeCount}}- </span>- <div class="liked-users-list">- <ul class="liked-users-list__list">- {{#each this.truncatedUsers as |user|}}- <li class="liked-users-list__item">- <PluginOutlet- @name="liked-users-list-avatar"- @outletArgs={{lazyHash user=user post=@post}}- >- <UserAvatar- class="trigger-user-card"- @user={{user}}- @size="small"- />- </PluginOutlet>- </li>- {{/each}}- {{#if this.slicedUsers}}- <li class="liked-users-list__item">- <DButton- class="liked-users-list__more-button btn-flat"- @icon={{this.toggleSlicedUsersVisiblityIcon}}- @action={{this.toggleSlicedUsersVisiblity}}- />- </li>- {{/if}}- </ul>- {{#if this.slicedUsersVisible}}- <ul class="liked-users-list__list">- {{#each this.slicedUsers as |user|}}- <li class="liked-users-list__item">- <PluginOutlet- @name="liked-users-list-avatar"- @outletArgs={{lazyHash user=user post=@post}}- >- <UserAvatar- class="trigger-user-card"- @user={{user}}- @size="small"- />- </PluginOutlet>- </li>- {{/each}}- </ul>- {{#if this.hiddenUserCount}}- <span class="liked-users-list__more">- {{i18n- "discourse_reactions.state_panel.more_users"- count=this.hiddenUserCount- }}- </span>- {{/if}}- {{/if}}- </div>- </ConditionalLoadingSpinner>- </:content>- </DMenu>+ {{#if this.buttonIcon}}+ {{icon this.buttonIcon}}+ {{/if}}+ {{@post.likeCount}}+ </button></template>}diff --git a/frontend/discourse/app/components/post/menu/liked-users-menu.gjs b/frontend/discourse/app/components/post/menu/liked-users-menu.gjsnew file mode 100644index 00000000000..c3ce0b6112c--- /dev/null+++ b/frontend/discourse/app/components/post/menu/liked-users-menu.gjs@@ -0,0 +1,41 @@+import Component from "@glimmer/component";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";+import PostUsersMenu from "./post-users-menu";++const LIKE_ACTION = 2;++export default class PostLikedUsersMenu extends Component {+ fetchUsers = async (page, pageSize) => {+ const result = await ajax("/post_action_users", {+ data: {+ id: this.post.id,+ post_action_type_id: LIKE_ACTION,+ page,+ limit: pageSize,+ },+ });++ const newUsers = result.post_action_users ?? [];+ const canLoadMore =+ newUsers.length >= pageSize && !!result.total_rows_post_action_users;+ return { users: newUsers, canLoadMore };+ };++ get post() {+ return this.args.data.post;+ }++ get titleText() {+ return i18n("post.likes_popup.title", {+ count: this.post.likeCount,+ });+ }++ <template>+ <PostUsersMenu+ @fetchUsers={{this.fetchUsers}}+ @titleText={{this.titleText}}+ />+ </template>+}diff --git a/frontend/discourse/app/components/post/menu/post-users-menu.gjs b/frontend/discourse/app/components/post/menu/post-users-menu.gjsnew file mode 100644index 00000000000..316b89ee217--- /dev/null+++ b/frontend/discourse/app/components/post/menu/post-users-menu.gjs@@ -0,0 +1,121 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import didInsert from "@ember/render-modifiers/modifiers/did-insert";+import { service } from "@ember/service";+import UserAvatar from "discourse/components/user-avatar";+import UserLink from "discourse/components/user-link";+import icon from "discourse/helpers/d-icon";++const PAGE_SIZE = 30;++export default class PostUsersMenu extends Component {+ @service siteSettings;+ @service site;++ @tracked users = [];+ @tracked loading = false;+ @tracked canLoadMore = true;++ displayName = (user) => {+ if (user.name && !this.siteSettings.prioritize_username_in_ux) {+ return user.name;+ }+ return user.username;+ };++ resetAndReload = () => {+ this.users = [];+ this.#page = 0;+ this.canLoadMore = true;+ return this.#loadMore();+ };+ #page = 0;++ @action+ async loadInitial() {+ await this.#loadMore();+ }++ @action+ onScroll(event) {+ const el = event.target;+ if (el.scrollTop + el.clientHeight >= el.scrollHeight - 50) {+ this.#loadMore();+ }+ }++ async #loadMore() {+ if (this.loading || !this.canLoadMore) {+ return;+ }++ this.loading = true;++ try {+ const { users, canLoadMore } = await this.args.fetchUsers(+ this.#page,+ PAGE_SIZE+ );+ this.users = [...this.users, ...users];+ this.#page++;+ this.canLoadMore = canLoadMore;+ } finally {+ this.loading = false;+ }+ }++ <template>+ <div class="post-users-popup">+ {{#if this.site.mobileView}}+ <div class="post-users-popup__title">{{@titleText}}</div>+ {{/if}}++ {{yield this.resetAndReload to="header"}}++ <div+ class="post-users-popup__body"+ {{on "scroll" this.onScroll}}+ {{didInsert this.loadInitial}}+ >+ {{#each this.users as |user|}}+ <div class="post-users-popup__item">+ <UserLink+ @username={{user.username}}+ class="post-users-popup__avatar-link"+ >+ <UserAvatar @user={{user}} @size="small" />+ </UserLink>+ <div class="post-users-popup__user-info">+ <UserLink+ @username={{user.username}}+ class="post-users-popup__name"+ >+ {{this.displayName user}}+ </UserLink>+ {{#unless this.siteSettings.prioritize_username_in_ux}}+ <UserLink+ @username={{user.username}}+ class="post-users-popup__username"+ >+ @{{user.username}}+ </UserLink>+ {{/unless}}+ </div>+ {{#if (has-block "reaction")}}+ {{yield user to="reaction"}}+ {{else}}+ {{icon "d-liked" class="post-users-popup__reaction"}}+ {{/if}}+ </div>+ {{/each}}+ {{#if this.loading}}+ <div class="post-users-popup__loading">+ <div class="spinner small"></div>+ </div>+ {{/if}}+ </div>+ </div>+ </template>+}diff --git a/frontend/discourse/tests/acceptance/post-controls-test.js b/frontend/discourse/tests/acceptance/post-controls-test.jsindex dc4c95a5c17..94e4b3b236a 100644--- a/frontend/discourse/tests/acceptance/post-controls-test.js+++ b/frontend/discourse/tests/acceptance/post-controls-test.js@@ -4,17 +4,17 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";import { i18n } from "discourse-i18n";acceptance(`Post controls`, function () {- test("menu of like count is shown when clicking on like count", async function (assert) {+ test("popup with likes is shown when clicking on like count", async function (assert) {await visit("/t/internationalization-localization/280");assert.dom("#post_2 .button-count").exists("like count button exists");await click("#post_2 .button-count");- // Assert that the liked users list container appears+ assert.dom(".post-users-popup").exists("post likes popup appears");assert- .dom(".liked-users-list__container")- .exists("liked users list container appears");+ .dom(".post-users-popup__item")+ .exists("liked users are listed in the popup");});test("accessibility of the embedded replies below the post", async function (assert) {diff --git a/frontend/discourse/tests/acceptance/topic-test.js b/frontend/discourse/tests/acceptance/topic-test.jsindex b77dd806b74..c36fde36da3 100644--- a/frontend/discourse/tests/acceptance/topic-test.js+++ b/frontend/discourse/tests/acceptance/topic-test.js@@ -42,7 +42,7 @@ acceptance(`Topic`, function (needs) {test("Reply as new topic", async function (assert) {await visit("/t/internationalization-localization/280");- await click("button.share:nth-of-type(1)");+ await click(".topic-post[data-post-number='1'] button.share");await click("button.new-topic");assert.dom(".d-editor-input").exists("the composer input is visible");@@ -62,7 +62,7 @@ acceptance(`Topic`, function (needs) {test("Reply as new message", async function (assert) {await visit("/t/pm-for-testing/12");- await click("button.share:nth-of-type(1)");+ await click(".topic-post[data-post-number='1'] button.share");await click("button.new-topic");assert.dom(".d-editor-input").exists("the composer input is visible");diff --git a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rbindex cb948f69cb0..5f63d6a7902 100644--- a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb+++ b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb@@ -1,12 +1,11 @@# frozen_string_literal: trueclass DiscourseReactions::CustomReactionsController < ApplicationController- MAX_USERS_COUNT = 26PAGE_SIZE = 20requires_plugin DiscourseReactions::PLUGIN_NAME- before_action :ensure_logged_in, except: [:post_reactions_users]+ before_action :ensure_logged_in, except: %i[reactions_users_list]def togglepost = fetch_post_from_params@@ -158,133 +157,136 @@ class DiscourseReactions::CustomReactionsController < ApplicationControllerrender_serialized reaction_users.first(PAGE_SIZE), UserReactionSerializerend- def post_reactions_users- params.require(:id).to_i- reaction_value = params[:reaction_value]+ def reactions_users_listpost = fetch_post_from_params+ page = params[:page].to_i.clamp(0..)+ limit = params[:limit].present? ? params[:limit].to_i.clamp(1, 50) : 30+ offset = page * limit+ main_reaction = DiscourseReactions::Reaction.main_reaction_id+ like_type = PostActionType::LIKE_POST_ACTION_ID+ reaction_filter = params[:reaction_value]++ rows, total =+ fetch_reaction_rows(post, reaction_filter, main_reaction, like_type, limit, offset)++ users =+ rows.map do |row|+ {+ id: row.id,+ username: row.username,+ name: row.name,+ avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),+ reaction: row.reaction,+ }+ end- raise Discourse::InvalidParameters if !post+ render_json_dump(users: users, total_rows: total)+ end- reaction_users = []+ private- if !reaction_value || reaction_value == DiscourseReactions::Reaction.main_reaction_id- # We only want to get likes that don't have an associated ReactionUser- # record, which count as a like or there will be double ups for main_reaction_id.- likes =- post.post_actions.where(- DiscourseReactions::PostActionExtension.filter_reaction_likes_sql,- like: PostActionType::LIKE_POST_ACTION_ID,- valid_reactions: DiscourseReactions::Reaction.valid_reactions.to_a,- )+ def plain_likes_scope(post, like_type)+ PostAction.where(post_id: post.id).where(+ DiscourseReactions::PostActionExtension.filter_reaction_likes_sql,+ like: like_type,+ valid_reactions: DiscourseReactions::Reaction.valid_reactions.to_a,+ )+ end- # Filter out likes for reactions that are not longer enabled,- # which match up to a ReactionUser in historical data.- historical_reaction_likes =- likes- .joins(- "LEFT JOIN discourse_reactions_reaction_users ON discourse_reactions_reaction_users.user_id = post_actions.user_id AND discourse_reactions_reaction_users.post_id = post_actions.post_id",- )- .joins(- "LEFT JOIN discourse_reactions_reactions ON discourse_reactions_reactions.id = discourse_reactions_reaction_users.reaction_id",- )- .where.not(+ def fetch_reaction_rows(post, reaction_filter, main_reaction, like_type, limit, offset)+ if reaction_filter.present? && reaction_filter != main_reaction+ total =+ DiscourseReactions::ReactionUser+ .joins(:reaction)+ .where(+ post_id: post.id,discourse_reactions_reactions: {- reaction_value: DiscourseReactions::Reaction.valid_reactions.to_a,+ reaction_value: reaction_filter,},)-- likes = likes.where.not(id: historical_reaction_likes.select(:id))- end-- if likes.present?- main_reaction =- DiscourseReactions::Reaction.find_by(- reaction_value: DiscourseReactions::Reaction.main_reaction_id,+ .count++ rows =+ DB.query(+ <<~SQL,+ SELECT u.id, u.username, u.name, u.uploaded_avatar_id,+ dr.reaction_value AS reaction, drru.created_at+ FROM discourse_reactions_reaction_users drru+ INNER JOIN discourse_reactions_reactions dr ON dr.id = drru.reaction_id+ INNER JOIN users u ON u.id = drru.user_id+ WHERE drru.post_id = :post_id AND dr.reaction_value = :reaction_filter+ ORDER BY drru.created_at ASC+ LIMIT :limit OFFSET :offset+ SQLpost_id: post.id,+ reaction_filter: reaction_filter,+ limit: limit,+ offset: offset,+ )+ elsif reaction_filter == main_reaction+ total = plain_likes_scope(post, like_type).count++ rows =+ DB.query(+ <<~SQL,+ SELECT u.id, u.username, u.name, u.uploaded_avatar_id,+ :main_reaction AS reaction, post_actions.created_at+ FROM post_actions+ INNER JOIN users u ON u.id = post_actions.user_id+ WHERE post_actions.post_id = :post_id+ AND (#{DiscourseReactions::PostActionExtension.filter_reaction_likes_sql})+ ORDER BY post_actions.created_at ASC+ LIMIT :limit OFFSET :offset+ SQL+ post_id: post.id,+ like: like_type,+ valid_reactions: DiscourseReactions::Reaction.valid_reactions.to_a,+ main_reaction: main_reaction,+ limit: limit,+ offset: offset,+ )+ else+ reaction_user_count = DiscourseReactions::ReactionUser.where(post_id: post.id).count+ plain_like_count = plain_likes_scope(post, like_type).count+ total = reaction_user_count + plain_like_count++ rows =+ DB.query(+ <<~SQL,+ SELECT * FROM (+ SELECT u.id, u.username, u.name, u.uploaded_avatar_id,+ dr.reaction_value AS reaction, drru.created_at+ FROM discourse_reactions_reaction_users drru+ INNER JOIN discourse_reactions_reactions dr ON dr.id = drru.reaction_id+ INNER JOIN users u ON u.id = drru.user_id+ WHERE drru.post_id = :post_id+ UNION ALL+ SELECT u.id, u.username, u.name, u.uploaded_avatar_id,+ :main_reaction AS reaction, post_actions.created_at+ FROM post_actions+ INNER JOIN users u ON u.id = post_actions.user_id+ WHERE post_actions.post_id = :post_id+ AND (#{DiscourseReactions::PostActionExtension.filter_reaction_likes_sql})+ ) combined+ ORDER BY created_at ASC+ LIMIT :limit OFFSET :offset+ SQL+ post_id: post.id,+ like: like_type,+ valid_reactions: DiscourseReactions::Reaction.valid_reactions.to_a,+ main_reaction: main_reaction,+ limit: limit,+ offset: offset,)- count = likes.length- users = format_likes_users(likes)-- # Also include ReactionUser records for main_reaction_id- # if they have been created in the past; new records created- # using main_reaction_id will only make a PostAction.- if main_reaction && main_reaction[:reaction_users_count]- (users << get_users(main_reaction)).flatten!- users.sort_by! { |user| user[:created_at] }- count += main_reaction.reaction_users_count.to_i- end-- reaction_users << {- id: DiscourseReactions::Reaction.main_reaction_id,- count: count,- users: users.reverse.slice(0, MAX_USERS_COUNT + 1),- }- end-- if !reaction_value- post- .reactions- .select do |reaction|- reaction[:reaction_users_count] &&- reaction[:reaction_value] != DiscourseReactions::Reaction.main_reaction_id- end- .each { |reaction| reaction_users << format_reaction_user(reaction) }- elsif reaction_value != DiscourseReactions::Reaction.main_reaction_id- post- .reactions- .where(reaction_value: reaction_value)- .select { |reaction| reaction[:reaction_users_count] }- .each { |reaction| reaction_users << format_reaction_user(reaction) }end- render_json_dump(reaction_users: reaction_users)- end-- private-- def get_users(reaction)- reaction- .reaction_users- .includes(:user)- .order("discourse_reactions_reaction_users.created_at desc")- .limit(MAX_USERS_COUNT + 1)- .map do |reaction_user|- {- username: reaction_user.user.username,- name: reaction_user.user.name,- avatar_template: reaction_user.user.avatar_template,- can_undo: reaction_user.can_undo?,- created_at: reaction_user.created_at.to_s,- }- end+ [rows, total]enddef post_serializer(post)PostSerializer.new(post, scope: guardian, root: false)end- def format_reaction_user(reaction)- {- id: reaction.reaction_value,- count: reaction.reaction_users_count.to_i,- users: get_users(reaction),- }- end-- def format_like_user(like)- {- username: like.user.username,- name: like.user.name,- avatar_template: like.user.avatar_template,- can_undo: guardian.can_delete_post_action?(like),- created_at: like.created_at.to_s,- }- end-- def format_likes_users(likes)- likes.includes([:user]).limit(MAX_USERS_COUNT + 1).map { |like| format_like_user(like) }- end-def fetch_post_from_paramspost_id = params[:post_id] || params[:id]post = Post.find(post_id)diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjsindex bd13f69e908..ea648fd3b96 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs@@ -4,21 +4,12 @@ import DiscourseReactionsActions from "./discourse-reactions-actions";export default class ReactionsActionSummary extends Component {static extraControls = true;- static shouldRender(args, context, owner) {- const site = owner.lookup("service:site");-- if (site.mobileView || args.post.deleted) {+ static shouldRender(args) {+ if (args.post.deleted) {return false;}- const siteSettings = owner.lookup("service:site-settings");- const mainReaction = siteSettings.discourse_reactions_reaction_for_like;-- return !(- args.post.reactions &&- args.post.reactions.length === 1 &&- args.post.reactions[0].id === mainReaction- );+ return args.post.reaction_users_count > 0;}<template>diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjsindex 86bcaae1644..bdb3f060f25 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs@@ -21,11 +21,10 @@ import lazyHash from "discourse/helpers/lazy-hash";import { isRailsTesting, isTesting } from "discourse/lib/environment";import { emojiUrlFor } from "discourse/lib/text";import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";-import { and, eq, not } from "discourse/truth-helpers";+import { eq, not } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import CustomReaction from "../models/discourse-reactions-custom-reaction";import DiscourseReactionsCounter from "./discourse-reactions-counter";-import DiscourseReactionsDoubleButton from "./discourse-reactions-double-button";import DiscourseReactionsPicker from "./discourse-reactions-picker";import DiscourseReactionsReactionButton from "./discourse-reactions-reaction-button";@@ -122,12 +121,10 @@ export default class DiscourseReactionsActions extends Component {@service dialog;@service capabilities;@service siteSettings;- @service site;@service currentUser;@service appEvents;@tracked reactionsPickerExpanded = false;- @tracked statePanelExpanded = false;@tracked clickOutsideDisabled = false;containerElement = null;@@ -186,11 +183,7 @@ export default class DiscourseReactionsActions extends Component {@actiontoggleReactions(event) {if (!this.reactionsPickerExpanded) {- if (this.statePanelExpanded) {- this.scheduleExpand("expandReactionsPicker");- } else {- this.expandReactionsPicker(event);- }+ this.expandReactionsPicker(event);}}@@ -528,18 +521,10 @@ export default class DiscourseReactionsActions extends Component {}let selector;- if (- this.data.reactions &&- this.data.reactions.length === 1 &&- this.data.reactions[0].id === mainReactionName- ) {- selector = `.discourse-reactions-double-button .discourse-reactions-reaction-button .d-icon`;+ if (!attrs.reaction || attrs.reaction === mainReactionName) {+ selector = `.discourse-reactions-reaction-button .d-icon`;} else {- if (!attrs.reaction || attrs.reaction === mainReactionName) {- selector = `.discourse-reactions-reaction-button .d-icon`;- } else {- selector = `.discourse-reactions-reaction-button .reaction-button .btn-toggle-reaction-emoji`;- }+ selector = `.discourse-reactions-reaction-button .reaction-button .btn-toggle-reaction-emoji`;}const mainReaction = this.containerElement?.querySelector(selector);@@ -614,7 +599,7 @@ export default class DiscourseReactionsActions extends Component {if (this.clickOutsideDisabled) {return;}- if (this.reactionsPickerExpanded || this.statePanelExpanded) {+ if (this.reactionsPickerExpanded) {this.collapseAllPanels();}}@@ -622,27 +607,10 @@ export default class DiscourseReactionsActions extends Component {expandReactionsPicker() {cancel(this._collapseHandler);activeReactionsComponent?.collapseAllPanels();- this.statePanelExpanded = false;this.reactionsPickerExpanded = true;this.updateReactionsPickerPopover();}- @action- expandStatePanel() {- cancel(this._collapseHandler);- activeReactionsComponent?.collapseAllPanels();- this.statePanelExpanded = true;- this.reactionsPickerExpanded = false;- this.updateReactionsStatePanel();- }-- @action- collapseStatePanel() {- cancel(this._collapseHandler);- this._collapseHandler = null;- this.statePanelExpanded = false;- }-collapseReactionsPicker() {cancel(this._collapseHandler);this._collapseHandler = null;@@ -657,7 +625,6 @@ export default class DiscourseReactionsActions extends Component {false);this._collapseHandler = null;- this.statePanelExpanded = false;this.reactionsPickerExpanded = false;}@@ -669,14 +636,6 @@ export default class DiscourseReactionsActions extends Component {);}- @action- updateReactionsStatePanel() {- this.showPopover(- ".discourse-reactions-counter",- ".discourse-reactions-state-panel"- );- }-showPopover(referenceSelector, floatingSelector) {schedule("afterRender", () => {const referenceElement =@@ -741,14 +700,6 @@ export default class DiscourseReactionsActions extends Component {}}- get onlyOneMainReaction() {- return (- this.data.reactions?.length === 1 &&- this.data.reactions[0].id ===- this.siteSettings.discourse_reactions_reaction_for_like- );- }-get showReactionsPicker() {return (this.currentUser &&@@ -776,18 +727,7 @@ export default class DiscourseReactionsActions extends Component {(hashcounter=(curryComponentDiscourseReactionsCounter- (lazyHash- post=this.data- position=@position- reactionsPickerExpanded=this.reactionsPickerExpanded- statePanelExpanded=this.statePanelExpanded- expandStatePanel=this.expandStatePanel- collapseStatePanel=this.collapseStatePanel- cancelCollapse=this.cancelCollapse- scheduleCollapse=this.scheduleCollapse- updatePopover=this.updateReactionsStatePanel- collapseAllPanels=this.collapseAllPanels- )+ (lazyHash post=this.data position=@position))button=(curryComponentDiscourseReactionsReactionButton@@ -818,21 +758,6 @@ export default class DiscourseReactionsActions extends Component {{{#if (eq @position "left")}}<components.counter />- {{else if this.onlyOneMainReaction}}- <DiscourseReactionsDoubleButton- @post={{this.data}}- @counterComponent={{components.counter}}- @buttonComponent={{components.button}}- />- {{else if this.site.mobileView}}- {{#if (not this.data.yours)}}- <components.counter />- <components.button />- {{else if- (and this.data.yours this.data.reactions this.data.reactions.length)- }}- <components.counter />- {{/if}}{{else if (not this.data.yours)}}<components.button />{{/if}}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjsindex eae7f483a5e..931f36d89b6 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs@@ -1,50 +1,23 @@import Component from "@glimmer/component";import { on } from "@ember/modifier";import { action } from "@ember/object";-import { trackedObject } from "@ember/reactive/collections";import { service } from "@ember/service";-import DButton from "discourse/components/d-button";-import { uniqueItemsFromArray } from "discourse/lib/array-tools";-import { bind } from "discourse/lib/decorators";-import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";-import { and } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";-import CustomReaction from "../models/discourse-reactions-custom-reaction";import DiscourseReactionsList from "./discourse-reactions-list";-import DiscourseReactionsStatePanel from "./discourse-reactions-state-panel";+import DiscourseReactionsUsersMenu from "./discourse-reactions-users-menu";++const MENU_IDENTIFIER = "discourse-reactions-users-menu";export default class DiscourseReactionsCounter extends Component {- @service capabilities;- @service site;+ @service menu;@service siteSettings;- reactionsUsers = trackedObject();-get elementId() {return `discourse-reactions-counter-${this.args.post.id}-${this.args.position || "right"}`;}- reactionsChanged(data) {- uniqueItemsFromArray(data.reactions).forEach((reaction) => {- this.getUsers(reaction);- });- }-- @bind- async getUsers(reactionValue) {- const response = await CustomReaction.findReactionUsers(this.args.post.id, {- reactionValue,- });-- response.reaction_users.forEach((reactionUser) => {- this.reactionsUsers[reactionUser.id] = reactionUser.users;- });-- this.args.updatePopover();- }-@actionmouseDown(event) {event.stopImmediatePropagation();@@ -59,11 +32,7 @@ export default class DiscourseReactionsCounter extends Component {keyDown(event) {if (event.key === "Enter" || event.key === " ") {event.preventDefault();- this.click(event);- } else if (event.key === "Escape" && this.args.statePanelExpanded) {- event.stopPropagation();- this.args.collapseStatePanel();- document.getElementById(this.elementId)?.focus();+ this.#toggleMenu(event.currentTarget);}}@@ -73,50 +42,13 @@ export default class DiscourseReactionsCounter extends Component {return;}- this.args.cancelCollapse();-- if (!this.capabilities.touch || this.site.desktopView) {- event.stopPropagation();- event.preventDefault();-- if (!this.args.statePanelExpanded) {- this.getUsers();- }-- this.toggleStatePanel(event);- }- }-- @action- clickOutside() {- if (this.args.statePanelExpanded) {- this.args.collapseAllPanels();- }- }-- @action- touchStart(event) {- this.args.cancelCollapse();-- if (- event.target.classList.contains("show-users") ||- event.target.classList.contains("avatar")- ) {- return true;- }-- if (this.args.statePanelExpanded) {- event.stopPropagation();- event.preventDefault();+ if (event.target.closest(".post-users-popup")) {return;}- if (this.capabilities.touch) {- event.stopPropagation();- event.preventDefault();- this.getUsers();- this.toggleStatePanel(event);- }+ event.stopPropagation();+ event.preventDefault();+ this.#toggleMenu(event.currentTarget);}get classes() {@@ -141,46 +73,22 @@ export default class DiscourseReactionsCounter extends Component {return classes.join(" ");}- toggleStatePanel() {- if (!this.args.statePanelExpanded) {- this.args.expandStatePanel();- } else {- this.args.collapseStatePanel();- }- }-- @action- pointerOver(event) {- if (event.pointerType !== "mouse") {- return;- }-- this.args.cancelCollapse();- }-- @action- pointerOut(event) {- if (event.pointerType !== "mouse") {- return;- }-- if (!event.relatedTarget?.closest(`#${this.elementId}`)) {- this.args.scheduleCollapse("collapseStatePanel");- }- }-get counterAriaLabel() {return i18n("discourse_reactions.counter.aria_label", {count: this.args.post.reaction_users_count,});}- get onlyOneMainReaction() {- return (- this.args.post.reactions?.length === 1 &&- this.args.post.reactions[0].id ===- this.siteSettings.discourse_reactions_reaction_for_like- );+ #toggleMenu(trigger) {+ this.menu.show(trigger, {+ identifier: MENU_IDENTIFIER,+ component: DiscourseReactionsUsersMenu,+ modalForMobile: true,+ closeOnScroll: true,+ placement: "bottom",+ offset: 10,+ data: { post: this.args.post },+ });}<template>@@ -193,44 +101,15 @@ export default class DiscourseReactionsCounter extends Component {aria-label={{this.counterAriaLabel}}{{on "mousedown" this.mouseDown}}{{on "mouseup" this.mouseUp}}- {{closeOnClickOutside this.clickOutside}}- {{on "touchstart" this.touchStart}}- {{on "pointerover" this.pointerOver}}- {{on "pointerout" this.pointerOut}}{{on "click" this.click}}{{on "keydown" this.keyDown}}>{{#if @post.reaction_users_count}}- <DiscourseReactionsStatePanel- @post={{@post}}- @reactionsUsers={{this.reactionsUsers}}- @statePanelExpanded={{@statePanelExpanded}}- @scheduleCollapse={{@scheduleCollapse}}- @cancelCollapse={{@cancelCollapse}}- />-- {{#unless this.onlyOneMainReaction}}- <DiscourseReactionsList- {{on "click" this.click}}- @post={{@post}}- @reactionsUsers={{this.reactionsUsers}}- @getUsers={{this.getUsers}}- />- {{/unless}}+ <DiscourseReactionsList @post={{@post}} /><span class="reactions-counter" aria-hidden="true">{{@post.reaction_users_count}}</span>-- {{#if (and @post.yours this.onlyOneMainReaction)}}- <div class="discourse-reactions-reaction-button my-likes">- <DButton- class="btn-toggle-reaction-like btn-flat btn-icon no-text reaction-button"- @translatedTitle={{this.counterAriaLabel}}- @icon={{this.siteSettings.discourse_reactions_like_icon}}- />- </div>- {{/if}}{{/if}}</div></template>diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjsindex 683ab4837e7..6780d1ae775 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs@@ -1,100 +1,16 @@import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";-import { on } from "@ember/modifier";-import { action } from "@ember/object";-import { debounce } from "@ember/runloop";import { service } from "@ember/service";-import {- computePosition,- flip,- limitShift,- offset,- shift,-} from "@floating-ui/dom";import emoji from "discourse/helpers/emoji";-import { bind } from "discourse/lib/decorators";-import { i18n } from "discourse-i18n";--const DISPLAY_MAX_USERS = 19;export default class DiscourseReactionsListEmoji extends Component {@service siteSettings;- @tracked loadingReactions = false;-get elementId() {return `discourse-reactions-list-emoji-${this.args.post.id}-${this.args.reaction.id}`;}- @action- pointerOver(event) {- if (event.pointerType !== "mouse" || !this.args.reaction.count) {- return;- }-- this.showTooltip();-- if (!this.args.users?.length && !this.loadingReactions) {- debounce(this, this._loadReactionUsers, 3000, true);- }- }-- showTooltip() {- const referenceElement = document.getElementById(this.elementId);- const floatingElement = referenceElement.querySelector(".user-list");-- computePosition(referenceElement, floatingElement, {- placement: "bottom",- middleware: [- offset(-5),- shift({ limiter: limitShift() }),- flip({ padding: 5 }),- ],- }).then(({ x, y }) => {- Object.assign(floatingElement.style, {- left: `${x}px`,- top: `${y}px`,- });- });- }-- _loadReactionUsers() {- this.loadingReactions = true;- this.args.getUsers(this.args.reaction.id).finally(() => {- this.loadingReactions = false;- });- }-- get truncatedUsers() {- return this.args.users?.slice(0, DISPLAY_MAX_USERS);- }-- @bind- displayNameForUser(user) {- if (- !this.siteSettings.prioritize_username_in_ux &&- this.siteSettings.prioritize_full_name_in_ux- ) {- return user.name || user.username;- } else if (this.siteSettings.prioritize_username_in_ux) {- return user.username;- } else if (!user.name) {- return user.username;- } else {- return user.name;- }- }-- get hiddenUserCount() {- return this.args.users?.length - this.truncatedUsers?.length;- }-<template>- <div- class="discourse-reactions-list-emoji"- id={{this.elementId}}- {{on "pointerover" this.pointerOver}}- >+ <div class="discourse-reactions-list-emoji" id={{this.elementId}}>{{#if @reaction.count}}{{emoji@reaction.id@@ -105,25 +21,6 @@ export default class DiscourseReactionsListEmoji extends Component {"")}}-- <div class="user-list">- <div class="container">- <span class="heading">{{@reaction.id}}</span>- {{#each this.truncatedUsers as |user|}}- <span class="username">{{this.displayNameForUser user}}</span>- {{else}}- <div class="center"><div class="spinner small"></div></div>- {{/each}}- {{#if this.hiddenUserCount}}- <span class="other-users">- {{i18n- "discourse_reactions.state_panel.more_users"- count=this.hiddenUserCount- }}- </span>- {{/if}}- </div>- </div>{{/if}}</div></template>diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjsindex c86a55b71a6..a0abed8c710 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs@@ -1,4 +1,3 @@-import { get } from "@ember/helper";import DiscourseReactionsListEmoji from "./discourse-reactions-list-emoji";const DiscourseReactionsList = <template>@@ -6,12 +5,7 @@ const DiscourseReactionsList = <template>{{#if @post.reaction_users_count}}<div class="reactions">{{#each @post.reactions as |reaction|}}- <DiscourseReactionsListEmoji- @reaction={{reaction}}- @users={{get @reactionsUsers reaction.id}}- @post={{@post}}- @getUsers={{@getUsers}}- />+ <DiscourseReactionsListEmoji @reaction={{reaction}} @post={{@post}} />{{/each}}</div>{{/if}}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjsdeleted file mode 100644index c2dbf4b952c..00000000000--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjs+++ /dev/null@@ -1,120 +0,0 @@-import Component from "@glimmer/component";-import { on } from "@ember/modifier";-import { action } from "@ember/object";-import UserAvatar from "discourse/components/user-avatar";-import concatClass from "discourse/helpers/concat-class";-import icon from "discourse/helpers/d-icon";-import emoji from "discourse/helpers/emoji";-import { gt } from "discourse/truth-helpers";-import { i18n } from "discourse-i18n";--const MAX_USERS_COUNT = 26;-const MIN_USERS_COUNT = 8;--export default class DiscourseReactionsStatePanelReaction extends Component {- @action- click(event) {- if (event?.target?.classList?.contains("show-users")) {- event.preventDefault();- event.stopPropagation();-- this.args.showUsers(this.args.reaction.id);- }- }-- get firstLineUsers() {- return this.args.users.slice(0, MIN_USERS_COUNT);- }-- get otherUsers() {- return this.args.users.slice(MIN_USERS_COUNT, MAX_USERS_COUNT);- }-- get columnsCount() {- return this.args.users.length > MIN_USERS_COUNT- ? this.firstLineUsers.length + 1- : this.firstLineUsers.length;- }-- get groupAriaLabel() {- return i18n("discourse_reactions.state_panel.reaction_group", {- reaction: this.args.reaction.id,- count: this.args.reaction.count,- });- }-- get moreLabel() {- if (this.args.isDisplayed && this.args.reaction.count > MAX_USERS_COUNT) {- return i18n("discourse_reactions.state_panel.more_users", {- count: this.args.reaction.count - MAX_USERS_COUNT,- });- }- }-- <template>- {{! template-lint-disable no-invalid-interactive }}- <div- class={{concatClass- "discourse-reactions-state-panel-reaction"- (if @isDisplayed "is-displayed")- }}- role="listitem"- aria-label={{this.groupAriaLabel}}- {{on "click" this.click}}- >- {{#if @users}}- <div class="reaction-wrapper" aria-hidden="true">- <div class="emoji-wrapper">- {{emoji @reaction.id}}- </div>- <div class="count">- {{@reaction.count}}- </div>- </div>-- <div class="users">- <div class="list list-columns-{{this.columnsCount}}">- {{#each this.firstLineUsers key="username" as |user|}}- <span>- <UserAvatar- class="trigger-user-card"- @size="tiny"- @user={{user}}- />- </span>- {{/each}}-- {{#if (gt @users.length MIN_USERS_COUNT)}}- <button- type="button"- class="show-users"- aria-label={{if- @isDisplayed- (i18n "discourse_reactions.state_panel.hide_users")- (i18n "discourse_reactions.state_panel.show_users")- }}- >- {{icon (if @isDisplayed "chevron-up" "chevron-down")}}- </button>- {{/if}}-- {{#if @isDisplayed}}- {{#each this.otherUsers key="username" as |user|}}- <span>- <UserAvatar- class="trigger-user-card"- @size="tiny"- @user={{user}}- />- </span>- {{/each}}- {{/if}}- </div>- <span class="more">- {{this.moreLabel}}- </span>- </div>- {{/if}}- </div>- </template>-}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjsdeleted file mode 100644index 0a406af481e..00000000000--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjs+++ /dev/null@@ -1,115 +0,0 @@-import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";-import { on } from "@ember/modifier";-import { action, get } from "@ember/object";-import didInsert from "@ember/render-modifiers/modifiers/did-insert";-import { schedule } from "@ember/runloop";-import concatClass from "discourse/helpers/concat-class";-import { and, eq } from "discourse/truth-helpers";-import DiscourseReactionsStatePanelReaction from "./discourse-reactions-state-panel-reaction";--export default class DiscourseReactionsStatePanel extends Component {- @tracked displayedReactionId;-- get classes() {- const classes = [];-- const { post } = this.args;- if (post?.reactions) {- const maxCount = Math.max(- ...post.reactions.map((reaction) => reaction.count)- );- const charsCount = maxCount.toString().length;- classes.push(`max-length-${charsCount}`);- }-- if (this.args.statePanelExpanded) {- classes.push("is-expanded");- }-- return classes;- }-- @action- pointerOut(event) {- if (event.pointerType !== "mouse") {- return;- }-- this.args.scheduleCollapse("collapseStatePanel");- }-- @action- pointerOver(event) {- if (event.pointerType !== "mouse") {- return;- }-- this.args.cancelCollapse();- }-- @action- showUsers(reactionId) {- if (!this.displayedReactionId) {- this.displayedReactionId = reactionId;- } else if (this.displayedReactionId === reactionId) {- this.hideUsers();- } else if (this.displayedReactionId !== reactionId) {- this.displayedReactionId = reactionId;- }- }-- @action- hideUsers() {- this.displayedReactionId = null;- }-- get hasReactionData() {- return !!Object.keys(this.args.reactionsUsers).length;- }-- @action- focusContainer(element) {- schedule("afterRender", () => {- const counter = element.closest(".discourse-reactions-counter");- if (counter?.matches(":focus-visible")) {- element.focus();- }- });- }-- <template>- <div- class={{concatClass "discourse-reactions-state-panel" this.classes}}- {{on "pointerout" this.pointerOut}}- {{on "pointerover" this.pointerOver}}- >- {{#if (and @statePanelExpanded @post.reactions.length)}}- <div class="container">- {{#if this.hasReactionData}}- <div- class="counters"- role="list"- tabindex="-1"- {{didInsert this.focusContainer}}- >- {{#each @post.reactions key="id" as |reaction|}}- <DiscourseReactionsStatePanelReaction- @reaction={{reaction}}- @users={{get @reactionsUsers reaction.id}}- @post={{@post}}- @isDisplayed={{eq reaction.id this.displayedReactionId}}- @showUsers={{this.showUsers}}- />- {{/each}}- </div>- {{else}}- <div class="spinner-container">- <div class="spinner small"></div>- </div>- {{/if}}- </div>- {{/if}}- </div>- </template>-}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-users-menu.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-users-menu.gjsnew file mode 100644index 00000000000..317736519d4--- /dev/null+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-users-menu.gjs@@ -0,0 +1,120 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { fn } from "@ember/helper";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import PostUsersMenu from "discourse/components/post/menu/post-users-menu";+import concatClass from "discourse/helpers/concat-class";+import icon from "discourse/helpers/d-icon";+import emoji from "discourse/helpers/emoji";+import { eq } from "discourse/truth-helpers";+import { i18n } from "discourse-i18n";+import CustomReaction from "../models/discourse-reactions-custom-reaction";++export default class DiscourseReactionsUsersMenu extends Component {+ @tracked activeFilter = null;++ fetchUsers = async (page, pageSize) => {+ const result = await CustomReaction.fetchReactionsUsersList(+ this.post.id,+ page,+ pageSize,+ this.activeFilter+ );++ const loadedSoFar = page * pageSize + (result.users?.length ?? 0);+ const canLoadMore = result.total_rows+ ? loadedSoFar < result.total_rows+ : (result.users?.length ?? 0) >= pageSize;++ return { users: result.users ?? [], canLoadMore };+ };+ #resetCallback = null;++ get post() {+ return this.args.data.post;+ }++ get reactions() {+ return this.post.reactions || [];+ }++ get showFilters() {+ return this.reactions.length > 1;+ }++ get titleText() {+ return i18n("discourse_reactions.users_popup.title", {+ count: this.post.reaction_users_count,+ });+ }++ @action+ registerReset(resetFn) {+ this.#resetCallback = resetFn;+ }++ @action+ selectFilter(filterId, event) {+ event.stopPropagation();+ event.preventDefault();+ if (this.activeFilter === filterId) {+ return;+ }++ this.activeFilter = filterId;+ this.#resetCallback?.();+ }++ <template>+ <PostUsersMenu+ @fetchUsers={{this.fetchUsers}}+ @titleText={{this.titleText}}+ >+ <:header as |resetAndReload|>+ {{this.registerReset resetAndReload}}+ {{#if this.showFilters}}+ <div class="post-users-popup__header">+ <button+ type="button"+ class={{concatClass+ "post-users-popup__filter"+ (unless this.activeFilter "is-active")+ }}+ data-reaction-filter="all"+ {{on "click" (fn this.selectFilter null)}}+ >+ {{i18n "discourse_reactions.users_popup.all"}}+ </button>+ {{#each this.reactions as |reaction|}}+ <button+ type="button"+ class={{concatClass+ "post-users-popup__filter"+ (if (eq reaction.id this.activeFilter) "is-active")+ }}+ data-reaction-filter={{reaction.id}}+ {{on "click" (fn this.selectFilter reaction.id)}}+ >+ {{emoji reaction.id skipTitle=true}}+ <span>{{reaction.count}}</span>+ </button>+ {{/each}}+ </div>+ {{/if}}+ </:header>++ <:reaction as |user|>+ {{#if user.reaction}}+ {{emoji+ user.reaction+ skipTitle=true+ class="post-users-popup__reaction"+ }}+ {{else}}+ {{icon "d-liked" class="post-users-popup__reaction"}}+ {{/if}}+ </:reaction>+ </PostUsersMenu>+ </template>+}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjsindex 7595b81286f..42349022d9a 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs@@ -162,6 +162,7 @@ function customizePostMenu(api) {"post-menu-buttons",({ value: dag, context: { buttonKeys } }) => {dag.replace(buttonKeys.LIKE, ReactionsActionButton);+ dag.delete(buttonKeys.LIKE_COUNT);dag.add("discourse-reactions-actions", ReactionsActionSummary, {after: buttonKeys.REPLIES,});diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.jsindex 4306fdb7ded..764cfa35045 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js@@ -92,17 +92,15 @@ export default class CustomReaction extends RestModel {});}- static findReactionUsers(postId, opts) {- opts = opts || {};- const data = {};-- if (opts.reactionValue) {- data.reaction_value = opts.reactionValue;+ static fetchReactionsUsersList(postId, page, limit, reactionValue) {+ const data = { page, limit };+ if (reactionValue) {+ data.reaction_value = reactionValue;}-- return ajax(`/discourse-reactions/posts/${postId}/reactions-users.json`, {- data,- });+ return ajax(+ `/discourse-reactions/posts/${postId}/reactions-users-list.json`,+ { data }+ );}init() {diff --git a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scssindex 6e2306dc5cb..df12a530fbe 100644--- a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss+++ b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss@@ -36,69 +36,6 @@ html.discourse-reactions-no-select {}}}-- .discourse-no-touch & {- &:hover {- .user-list {- visibility: visible;- opacity: 0.9;-- .spinner {- animation-play-state: running;- }- }- }- }- }-- .user-list {- position: absolute;- visibility: hidden;- z-index: z("usercard") - 2;- transition: opacity 0.33s;- opacity: 0;- padding: 0.5em 0;- min-width: 120px;- min-height: 80px;- width: max-content;- top: 0;-- .spinner {- animation-play-state: paused;- }-- .container {- margin-top: 0.5em;- font-size: $font-down-2;- background-color: var(--primary);- color: var(--secondary-very-high);- border-radius: 3px;- padding: 1em;- display: flex;- flex-direction: column;-- .heading {- font-weight: 700;- font-size: $font-up-1;- padding-bottom: 0.5em;- text-align: left;- }-- .username {- @include ellipsis;- }-- .username,- .other-users {- white-space: nowrap;- text-align: left;- }-- .other-users {- padding-top: 0.25em;- color: var(--secondary-high);- }- }}}@@ -184,150 +121,6 @@ html.discourse-reactions-no-select {}}-.discourse-reactions-counter .discourse-reactions-state-panel {- cursor: default;- z-index: z("usercard") - 2;- position: absolute;- visibility: hidden;- padding: 15px 0;- width: max-content;- top: 0;-- &.is-expanded {- min-width: 80px;- visibility: visible;- }-- .discourse-reactions-state-panel-reaction .count {- padding-right: 0.25em;- }-- @for $i from 1 through 5 {- &.max-length-#{$i} {- .discourse-reactions-state-panel-reaction .count {- width: #{$i * 10}px;- }- }- }-- .container {- box-shadow: var(--shadow-card);- background-color: var(--secondary);- display: flex;- flex-direction: column;- z-index: 1;- padding: 0.25em;- border-radius: 8px;- }-- .counters {- display: flex;- flex-direction: column;- max-height: 200px;- overflow-y: auto;- }-}--.discourse-reactions-state-panel-reaction {- border-bottom: 1px solid var(--content-border-color);- display: flex;- justify-content: flex-start;- align-items: flex-start;-- &:first-child {- padding-top: 0;- }-- &:last-child {- border: none;- padding-bottom: 0;- }-- .list {- display: grid;- column-gap: 0.25em;- row-gap: 0.25em;- padding-top: 0.25em;- grid-template-rows: 22.5px;- }-- @for $i from 1 through 9 {- .list-columns-#{$i} {- grid-template-columns: repeat($i, 22.5px);- }- }-- .users {- display: flex;- flex-direction: column;-- .trigger-user-card {- width: 22px;- height: 22px;- display: flex;- align-items: center;- justify-content: center;-- .avatar {- // constrain to container- width: 100%;- height: 100%;- }- }- }-- .more {- color: var(--primary-medium);- font-size: $font-down-1;- padding-top: 0.5em;- text-align: left;- }-- .reaction-wrapper {- display: flex;- align-items: center;- justify-content: center;- padding-top: 0.25em;- margin-left: 0 !important; // core rule has too much specificity-- .count {- font-size: $font-down-1;- color: var(--primary-medium);- text-align: left;-- @include ellipsis;- }-- .emoji-wrapper {- width: 25px;- height: 25px;- display: flex;- align-items: center;- justify-content: center;- }- }-- .show-users {- padding: 0 !important;- margin: 0 !important;- background: none !important;- border-color: transparent !important;- color: var(--primary-medium) !important;-- .d-icon {- color: var(--primary-medium) !important;- margin: 0;- pointer-events: none;- }- }-- .count {- color: var(--primary);- font-size: $font-up-1;- margin-left: 0.5em;- }-}-.discourse-reactions-actions {display: inline-flex;justify-content: flex-end;diff --git a/plugins/discourse-reactions/config/locales/client.en.yml b/plugins/discourse-reactions/config/locales/client.en.ymlindex 5b6c5adb683..c48102a4f44 100644--- a/plugins/discourse-reactions/config/locales/client.en.yml+++ b/plugins/discourse-reactions/config/locales/client.en.yml@@ -20,6 +20,11 @@ en:react_with: "React to this post with: %{reaction}"cant_remove_reaction: "You can no longer remove your reaction"remove_reaction: "Remove this %{reaction} reaction"+ users_popup:+ all: "All"+ title:+ one: "%{count} reaction"+ other: "%{count} reactions"counter:aria_label:one: "%{count} reaction"diff --git a/plugins/discourse-reactions/config/routes.rb b/plugins/discourse-reactions/config/routes.rbindex 6d0f38e2e4b..e3f5f2cfe8d 100644--- a/plugins/discourse-reactions/config/routes.rb+++ b/plugins/discourse-reactions/config/routes.rb@@ -14,6 +14,7 @@ DiscourseReactions::Engine.routes.draw do:as => "reactions_given"get "/discourse-reactions/posts/reactions-received" => "custom_reactions#reactions_received",:as => "reactions_received"- get "/discourse-reactions/posts/:id/reactions-users" => "custom_reactions#post_reactions_users",- :as => "post_reactions_users"+ get "/discourse-reactions/posts/:id/reactions-users-list" =>+ "custom_reactions#reactions_users_list",+ :as => "reactions_users_list"enddiff --git a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rbindex ce516d58055..b58b847b120 100644--- a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb+++ b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb@@ -458,110 +458,38 @@ describe DiscourseReactions::CustomReactionsController doendend- describe "#post_reactions_users" do- it "return reaction_users of post when theres no parameters" do- get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json"- parsed = response.parsed_body+ describe "#reactions_users_list" do+ it "returns users who reacted or liked a post" do+ get "/discourse-reactions/posts/#{post_2.id}/reactions-users-list.json"expect(response.status).to eq(200)- expect(parsed["reaction_users"][0]["users"][0]["username"]).to eq(user_5.username)- expect(parsed["reaction_users"][0]["users"][0]["name"]).to eq(user_5.name)- expect(parsed["reaction_users"][0]["users"][0]["avatar_template"]).to eq(- user_5.avatar_template,- )+ usernames = response.parsed_body["users"].map { |u| u["username"] }+ expect(usernames).to include(user_1.username, user_3.username, user_5.username)end- it "return reaction_users of reaction when there are parameters" do- get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{laughing_reaction.reaction_value}"- parsed = response.parsed_body+ it "filters by reaction_value" do+ get "/discourse-reactions/posts/#{post_2.id}/reactions-users-list.json?reaction_value=hugs"expect(response.status).to eq(200)- expect(parsed["reaction_users"][0]["users"][0]["username"]).to eq(user_1.username)- expect(parsed["reaction_users"][0]["users"][0]["name"]).to eq(user_1.name)- expect(parsed["reaction_users"][0]["users"][0]["avatar_template"]).to eq(- user_1.avatar_template,- )+ users = response.parsed_body["users"]+ expect(users.map { |u| u["username"] }).to eq([user_4.username])+ expect(users.first["reaction"]).to eq("hugs")end- it "gives 404 ERROR when the post_id OR reaction_value is invalid" do- get "/discourse-reactions/posts/1000000/reactions-users.json"+ it "404s for an unknown post id" do+ get "/discourse-reactions/posts/0/reactions-users-list.json"expect(response.status).to eq(404)-- get "/discourse-reactions/posts/1000000/reactions-users.json?reaction_value=test"- expect(response.status).to eq(404)- end-- it "merges matching custom reaction into likes" do- get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{DiscourseReactions::Reaction.main_reaction_id}"- parsed = response.parsed_body- like_count = parsed["reaction_users"][0]["count"].to_i- expect(like_count).to eq(1)-- get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=laughing"- parsed = response.parsed_body- reaction_count = parsed["reaction_users"][0]["count"].to_i- expect(reaction_count).to eq(2)-- SiteSetting.discourse_reactions_reaction_for_like = "laughing"-- get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{DiscourseReactions::Reaction.main_reaction_id}"- parsed = response.parsed_body- expect(parsed["reaction_users"][0]["count"]).to eq(like_count + reaction_count)end- it "does not show reaction_users on PMs without permission" do- get "/discourse-reactions/posts/#{private_post.id}/reactions-users.json"+ it "does not expose users on PMs without permission" do+ get "/discourse-reactions/posts/#{private_post.id}/reactions-users-list.json"expect(response.status).to eq(403)end- it "shows reaction_users on PMs with permission" do+ it "exposes users on PMs to participants" dosign_in(user_2)- get "/discourse-reactions/posts/#{private_post.id}/reactions-users.json"- expect(response.status).to eq(200)- end-- it "does not double up reactions which also count as likes if the reaction is no longer enabled" do- post_for_enabled_reactions = Fabricate(:post, user: user_2)- new_reaction_1 =- Fabricate(:reaction, post: post_for_enabled_reactions, reaction_value: "laughing")- new_reaction_user_1 =- Fabricate(- :reaction_user,- user: user_5,- reaction: new_reaction_1,- post: post_for_enabled_reactions,- )- new_like_1 =- Fabricate(- :post_action,- post: post_for_enabled_reactions,- user: user_4,- post_action_type_id: PostActionType::LIKE_POST_ACTION_ID,- )-- get "/discourse-reactions/posts/#{post_for_enabled_reactions.id}/reactions-users.json"- parsed = response.parsed_body-+ get "/discourse-reactions/posts/#{private_post.id}/reactions-users-list.json"expect(response.status).to eq(200)- expect(- parsed["reaction_users"].find { |reaction| reaction["id"] == "laughing" }["count"],- ).to eq(1)- expect(parsed["reaction_users"].find { |reaction| reaction["id"] == "heart" }["count"]).to eq(- 1,- )-- SiteSetting.discourse_reactions_enabled_reactions = "+1"-- get "/discourse-reactions/posts/#{post_for_enabled_reactions.id}/reactions-users.json"- parsed = response.parsed_body-- expect(response.status).to eq(200)- expect(- parsed["reaction_users"].find { |reaction| reaction["id"] == "laughing" }["count"],- ).to eq(1)- expect(parsed["reaction_users"].find { |reaction| reaction["id"] == "heart" }["count"]).to eq(- 1,- )endenddiff --git a/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb b/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rbindex c39117d9e94..58b2a5c8441 100644--- a/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb+++ b/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb@@ -29,18 +29,11 @@ module PageObjectsdef hover_over_reaction(reaction)component.find(reaction_list_emoji_selector(reaction)).hover- page.has_css?(".discourse-reactions-list-emoji .user-list", visible: true)enddef click_reaction(reaction)component.find(reaction_list_emoji_selector(reaction)).clickend-- def has_users_for_reaction?(reaction, usernames)- find("#{reaction_list_emoji_selector(reaction)} .user-list .container").has_text?(- usernames.join("\n"),- )- endendendenddiff --git a/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb b/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rbindex fd9e5ff5ba9..44675d628fe 100644--- a/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb+++ b/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb@@ -25,58 +25,74 @@ describe "Reactions | Post reaction user list" do).toggle!end- it "shows a list of users who have reacted to a post on hover for likes and each reaction" do+ it "shows more info about reactions when clicking" dosign_in(current_user)visit(post.url)-expect(reactions_list).to have_reaction("heart")- expect(reactions_list).to have_reaction("clap")- reactions_list.hover_over_reaction("heart")- expect(reactions_list).to have_users_for_reaction("heart", [user_2.username])+ find(".discourse-reactions-counter").click- # hover on something else to clear the current hover- page.find("#site-logo").hover+ expect(page).to have_css(".post-users-popup")+ find(".post-users-popup .post-users-popup__name[data-user-card=#{user_2.username}]").click- reactions_list.hover_over_reaction("clap")- expect(reactions_list).to have_users_for_reaction("clap", [user_3.username])+ expect(page).to have_css(".user-card.user-card-#{user_2.username}")end- it "shows more info about reactions when clicking" do+ it "shows the user's name as primary when prioritize_username_in_ux is false" do+ SiteSetting.prioritize_username_in_ux = false++ sign_in(current_user)visit(post.url)expect(reactions_list).to have_reaction("heart")- reactions_list.click_reaction("heart")- expect(page).to have_css(".discourse-reactions-state-panel")- find(".discourse-reactions-state-panel [data-user-card=#{user_2.username}]").click+ find(".discourse-reactions-counter").click- expect(page).to have_css(".user-card.user-card-#{user_2.username}")+ expect(page).to have_css(+ ".post-users-popup__name[data-user-card=#{user_2.username}]",+ text: user_2.name,+ )+ expect(page).to have_css(".post-users-popup__username", text: "@#{user_2.username}")end- context "when the site allows anonymous users to like posts" do- before do- SiteSetting.allow_anonymous_mode = true- SiteSetting.allow_likes_in_anonymous_mode = true- end+ it "shows the user's username as primary when prioritize_username_in_ux is true" do+ SiteSetting.prioritize_username_in_ux = true- it "shows a list of users who have liked a post on hover for unauthenticated users" do- visit(post.url)+ sign_in(current_user)+ visit(post.url)+ expect(reactions_list).to have_reaction("heart")- expect(reactions_list).to have_reaction("heart")+ find(".discourse-reactions-counter").click- reactions_list.hover_over_reaction("heart")- expect(reactions_list).to have_users_for_reaction("heart", [user_2.username])- end+ expect(page).to have_css(+ ".post-users-popup__name[data-user-card=#{user_2.username}]",+ text: user_2.username,+ )+ expect(page).to have_no_css(".post-users-popup__username")+ end++ it "filters the users popup by reaction" do+ sign_in(current_user)+ visit(post.url)+ expect(reactions_list).to have_reaction("heart")++ find(".discourse-reactions-counter").click+ expect(page).to have_css(".post-users-popup")++ within(".post-users-popup") do+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_2.username}]")+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_3.username}]")- it "shows a list of users who have liked a post on hover for authenticated users posting anonymously" do- anonymous_user = Fabricate(:anonymous)- sign_in(anonymous_user)- visit(post.url)+ find("[data-reaction-filter=heart]").click+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_2.username}]")+ expect(page).to have_no_css(".post-users-popup__name[data-user-card=#{user_3.username}]")- expect(reactions_list).to have_reaction("heart")+ find("[data-reaction-filter=clap]").click+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_3.username}]")+ expect(page).to have_no_css(".post-users-popup__name[data-user-card=#{user_2.username}]")- reactions_list.hover_over_reaction("heart")- expect(reactions_list).to have_users_for_reaction("heart", [user_2.username])+ find("[data-reaction-filter=all]").click+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_2.username}]")+ expect(page).to have_css(".post-users-popup__name[data-user-card=#{user_3.username}]")endendenddiff --git a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.jsindex 7d0f498113b..df0ea9cd139 100644--- a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js+++ b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js@@ -46,17 +46,18 @@ acceptance(`Discourse Reactions - Post`, function (needs) {await visit("/t/topic_with_reactions_and_likes/374");assert- .dom("#post_3 .discourse-reactions-double-button")- .exists("displays the reaction count beside the reaction button");+ .dom("#post_3 .discourse-reactions-counter .reactions-counter")+ .hasText("2", "displays the like count in the counter");});test("Post has likes and reactions", async function (assert) {await visit("/t/topic_with_reactions_and_likes/374");assert- .dom("#post_1 .discourse-reactions-double-button")- .doesNotExist(- "does not display the reaction count beside the reaction button"+ .dom("#post_1 .discourse-reactions-list .discourse-reactions-list-emoji")+ .exists(+ { count: 8 },+ "renders an emoji for each reaction in the counter list");});diff --git a/spec/support/shared_examples/core_features.rb b/spec/support/shared_examples/core_features.rbindex e0a06ba7cab..e7428183f8e 100644--- a/spec/support/shared_examples/core_features.rb+++ b/spec/support/shared_examples/core_features.rb@@ -113,10 +113,8 @@ RSpec.shared_examples_for "having working core features" do |skip_examples: []|it "likes a post" doclick_on(topics.first.title)- within(".double-button") do- find(".toggle-like").click- expect(page).to have_content("1")- end+ find(".toggle-like").click+ expect(page).to have_css(".post-action-menu__like-count", text: "1")endendenddiff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rbindex 8ed0538dbef..cb7b3d0782e 100644--- a/spec/system/page_objects/pages/topic.rb+++ b/spec/system/page_objects/pages/topic.rb@@ -136,20 +136,13 @@ module PageObjectsenddef has_who_liked_on_post?(post, count: nil)- if count- return(- has_css?(- ".liked-users-list__container .liked-users-list__item a.trigger-user-card",- count: count,- )- )- end+ return has_css?(".post-users-popup .post-users-popup__item", count: count) if count- within_post(post) { has_css?(".who-liked.--expanded") }+ has_css?(".post-users-popup")enddef has_no_who_liked_on_post?(post)- within_post(post) { has_no_css?(".who-liked.--expanded") }+ has_no_css?(".post-users-popup")enddef has_who_read_on_post?(post, count: nil)