A platform for community discussion. Free, open, simple.
FIX: Missing excerpt for post small actions in topic timeline. (#14547)
Alan Guo Xiang Tand0595127cc92
diff --git a/app/assets/javascripts/discourse/app/widgets/topic-timeline.js b/app/assets/javascripts/discourse/app/widgets/topic-timeline.jsindex 0d83d2b3f13..28437a7f540 100644--- a/app/assets/javascripts/discourse/app/widgets/topic-timeline.js+++ b/app/assets/javascripts/discourse/app/widgets/topic-timeline.js@@ -2,6 +2,7 @@ import ComponentConnector from "discourse/widgets/component-connector";import I18n from "I18n";import RawHtml from "discourse/widgets/raw-html";import { createWidget } from "discourse/widgets/widget";+import { actionDescriptionHtml } from "discourse/widgets/post-small-action";import { h } from "virtual-dom";import { iconNode } from "discourse-common/lib/icon-library";import { later } from "@ember/runloop";@@ -456,7 +457,16 @@ export default createWidget("topic-timeline", {excerpt = "<span class='username'>" + info.username + ":</span> ";}- this.state.excerpt = excerpt + info.excerpt;+ if (info.excerpt) {+ this.state.excerpt = excerpt + info.excerpt;+ } else if (info.action_code) {+ this.state.excerpt = `${excerpt} ${actionDescriptionHtml(+ info.action_code,+ info.created_at,+ info.username+ )}`;+ }+this.scheduleRerender();}});diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex b23245cc1be..32f378594d9 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -262,14 +262,21 @@ class TopicsController < ApplicationController@posts = Post.where(hidden: false, deleted_at: nil, topic_id: @topic.id).where('posts.id in (?)', post_ids).joins("LEFT JOIN users u on u.id = posts.user_id")- .pluck(:id, :cooked, :username)- .map do |post_id, cooked, username|- {- post_id: post_id,- username: username,- excerpt: PrettyText.excerpt(cooked, 800, keep_emoji_images: true)- }- end+ .pluck(:id, :cooked, :username, :action_code, :created_at)+ .map do |post_id, cooked, username, action_code, created_at|+ attrs = {+ post_id: post_id,+ username: username,+ excerpt: PrettyText.excerpt(cooked, 800, keep_emoji_images: true),+ }++ if action_code+ attrs[:action_code] = action_code+ attrs[:created_at] = created_at+ end++ attrs+ endrender json: @posts.to_jsonenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 281b3aeda42..2aa3b858b2f 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -3444,25 +3444,29 @@ RSpec.describe TopicsController doit "can correctly get excerpts" dofirst_post = create_post(raw: 'This is the first post :)', title: 'This is a test title I am making yay')second_post = create_post(raw: 'This is second post', topic: first_post.topic)+ third_post = first_post.topic.add_small_action(first_post.user, "autobumped")random_post = Fabricate(:post)get "/t/#{first_post.topic_id}/excerpts.json", params: {- post_ids: [first_post.id, second_post.id, random_post.id]+ post_ids: [first_post.id, second_post.id, third_post.id, random_post.id]}json = response.parsed_bodyjson.sort! { |a, b| a["post_id"] <=> b["post_id"] }# no random post- expect(json.length).to eq(2)+ expect(json.map { |p| p["post_id"] }).to contain_exactly(first_post.id, second_post.id, third_post.id)# keep emoji imagesexpect(json[0]["excerpt"]).to match(/emoji/)expect(json[0]["excerpt"]).to match(/first post/)expect(json[0]["username"]).to eq(first_post.user.username)- expect(json[0]["post_id"]).to eq(first_post.id)+ expect(json[0]["created_at"].present?).to eq(false)expect(json[1]["excerpt"]).to match(/second post/)++ expect(json[2]["action_code"]).to eq("autobumped")+ expect(json[2]["created_at"].present?).to eq(true)endend