Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: activity log modal for small actions (#39380)

Mark VanLandinghamc879820aa6f2
diff --git a/app/assets/stylesheets/common/nested-view.scss b/app/assets/stylesheets/common/nested-view.scss
index 77a6d246bc8..1079a05372e 100644
--- a/app/assets/stylesheets/common/nested-view.scss
+++ b/app/assets/stylesheets/common/nested-view.scss
@@ -108,10 +108,17 @@
margin-bottom: 1em;
}
+ &__controls-right {
+ display: flex;
+ align-items: center;
+ gap: 1em;
+ margin-left: auto;
+ }
+
+ &__activity-link,
&__flat-link {
font-size: var(--font-down-1);
white-space: nowrap;
- margin-left: auto;
}
&__op {
@@ -831,6 +838,61 @@
}
}
+// ── Activity log modal ────────────────────────────────────────────
+.nested-activity-log-modal {
+ .d-modal__body {
+ display: flex;
+ flex-direction: column-reverse;
+ }
+
+ &__list {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ }
+
+ &__item {
+ display: flex;
+ align-items: flex-start;
+ gap: 0.5em;
+ padding: 0.65em 0;
+
+ &:not(:last-child) {
+ border-bottom: 1px solid var(--primary-low);
+ }
+ }
+
+ &__icon {
+ flex-shrink: 0;
+ color: var(--primary-medium);
+ margin-top: 0.15em;
+ }
+
+ &__content {
+ flex: 1;
+ min-width: 0;
+ }
+
+ &__desc {
+ display: flex;
+ align-items: center;
+ gap: 0.35em;
+ flex-wrap: wrap;
+ }
+
+ &__message {
+ margin-top: 0.35em;
+ font-size: var(--font-down-1);
+ color: var(--primary-high);
+ }
+
+ &__empty {
+ color: var(--primary-medium);
+ text-align: center;
+ padding: 1em 0;
+ }
+}
+
// ── Mobile layout ─────────────────────────────────────────────────
// Reddit-style mobile redesign: avatars move inline into the post
// header (handled via JS template conditional), the gutter becomes a
diff --git a/app/controllers/nested_topics_controller.rb b/app/controllers/nested_topics_controller.rb
index fdf95a66415..aa46227c0c8 100644
--- a/app/controllers/nested_topics_controller.rb
+++ b/app/controllers/nested_topics_controller.rb
@@ -5,7 +5,7 @@ class NestedTopicsController < ApplicationController
before_action :ensure_nested_replies_enabled
before_action :find_topic_with_topic_view, only: %i[show children context]
- before_action :find_topic, only: %i[pin toggle]
+ before_action :find_topic, only: %i[pin toggle activity]
before_action :ensure_not_pm
after_action :track_visit, only: %i[show context]
@@ -83,6 +83,49 @@ class NestedTopicsController < ApplicationController
end
end
+ # GET /n/:slug/:topic_id/activity
+ def activity
+ post_types = [Post.types[:small_action]]
+ post_types << Post.types[:whisper] if guardian.user&.whisperer?
+
+ posts =
+ @topic
+ .posts
+ .where(post_type: post_types)
+ .where.not(action_code: [nil, ""])
+ .includes(:user)
+ .order(:created_at)
+
+ Post.preload_custom_fields(posts, %w[action_code_who action_code_path])
+
+ creator = @topic.user
+ actions = [
+ {
+ action_code: "topic_created",
+ created_at: @topic.created_at,
+ username: creator&.username,
+ avatar_template: creator&.avatar_template,
+ },
+ ]
+
+ actions.concat(
+ posts.map do |post|
+ {
+ id: post.id,
+ action_code: post.action_code,
+ action_code_who: post.custom_fields["action_code_who"],
+ action_code_path: post.custom_fields["action_code_path"],
+ created_at: post.created_at,
+ username: post.user&.username,
+ avatar_template: post.user&.avatar_template,
+ cooked: post.cooked,
+ }
+ end,
+ )
+
+ render json: { small_actions: actions }
+ end
+
# PUT /n/:slug/:topic_id/toggle
def toggle
NestedTopic::Toggle.call(service_params.deep_merge(params: { topic_id: @topic.id })) do
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index bff2650bc46..bb26e97e6ac 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -291,6 +291,7 @@ en:
last_item: "and"
action_codes:
+ topic_created: "Created this topic %{when}"
public_topic: "Made this topic public %{when}"
open_topic: "Converted this to a topic %{when}"
private_topic: "Made this topic a personal message %{when}"
@@ -3965,6 +3966,10 @@ en:
topic_admin_menu:
enable_nested_replies: "Enable nested replies"
disable_nested_replies: "Disable nested replies"
+ activity_log:
+ link: "Activity log"
+ title: "Topic activity log"
+ empty: "No topic activity to show."
context:
banner: "You are viewing a single thread from this topic."
view_full_topic: "View full topic"
diff --git a/config/routes.rb b/config/routes.rb
index 1090aff81ab..53b0b358859 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1431,6 +1431,7 @@ Discourse::Application.routes.draw do
get "/context/:post_number" => "nested_topics#context", :constraints => { post_number: /\d+/ }
put "/pin" => "nested_topics#pin"
put "/toggle" => "nested_topics#toggle"
+ get "/activity" => "nested_topics#activity"
get "/:post_number" => "nested_topics#context", :constraints => { post_number: /\d+/ }
get "/" => "nested_topics#show"
end
diff --git a/frontend/discourse/app/components/modal/nested-activity-log.gjs b/frontend/discourse/app/components/modal/nested-activity-log.gjs
new file mode 100644
index 00000000000..437d0254a28
--- /dev/null
+++ b/frontend/discourse/app/components/modal/nested-activity-log.gjs
@@ -0,0 +1,59 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
+import DModal from "discourse/components/d-modal";
+import NestedActivityLogItem from "discourse/components/modal/nested-activity-log/item";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { i18n } from "discourse-i18n";
+
+export default class NestedActivityLog extends Component {
+ @tracked loading = true;
+ @tracked smallActions = [];
+
+ constructor() {
+ super(...arguments);
+ this.fetchActivity();
+ }
+
+ @action
+ async fetchActivity() {
+ try {
+ const topic = this.args.model.topic;
+ const data = await ajax(`/n/${topic.slug}/${topic.id}/activity.json`);
+ this.smallActions = data.small_actions || [];
+ } catch (e) {
+ popupAjaxError(e);
+ } finally {
+ this.loading = false;
+ }
+ }
+
+ <template>
+ <DModal
+ @title={{i18n "nested_replies.activity_log.title"}}
+ @closeModal={{@closeModal}}
+ class="nested-activity-log-modal"
+ >
+ <:body>
+ <ConditionalLoadingSpinner @condition={{this.loading}}>
+ {{#if this.smallActions.length}}
+ <ul class="nested-activity-log-modal__list">
+ {{#each this.smallActions as |sa|}}
+ <NestedActivityLogItem
+ @action={{sa}}
+ @topicId={{@model.topic.id}}
+ />
+ {{/each}}
+ </ul>
+ {{else}}
+ <p class="nested-activity-log-modal__empty">
+ {{i18n "nested_replies.activity_log.empty"}}
+ </p>
+ {{/if}}
+ </ConditionalLoadingSpinner>
+ </:body>
+ </DModal>
+ </template>
+}
diff --git a/frontend/discourse/app/components/modal/nested-activity-log/item.gjs b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
new file mode 100644
index 00000000000..cfecf836659
--- /dev/null
+++ b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
@@ -0,0 +1,93 @@
+import Component from "@glimmer/component";
+import { trustHTML } from "@ember/template";
+import {
+ customGroupActionCodes,
+ GROUP_ACTION_CODES,
+ ICONS,
+} from "discourse/components/post/small-action";
+import UserAvatar from "discourse/components/user-avatar";
+import icon from "discourse/helpers/d-icon";
+import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
+import getURL from "discourse/lib/get-url";
+import { userPath } from "discourse/lib/url";
+import { escapeExpression } from "discourse/lib/utilities";
+import { i18n } from "discourse-i18n";
+
+const ACTIVITY_LOG_ICONS = {
+ topic_created: "plus",
+};
+
+// `action_codes.*` translations interpolate %{who}/%{when}/%{path} at arbitrary
+// positions inside a translated sentence, so the substitutions have to be HTML
+// strings — there's no template-only equivalent. Mirrors small-action.gjs.
+function buildDescription(action, topicId) {
+ const code = action.action_code;
+ const when = autoUpdatingRelativeAge(new Date(action.created_at), {
+ format: "medium-with-ago-and-on",
+ });
+ const path = getURL(action.action_code_path || `/t/${topicId}`);
+ const who = mentionLinkFor(code, action.action_code_who);
+
+ return trustHTML(i18n(`action_codes.${code}`, { who, when, path }));
+}
+
+function mentionLinkFor(code, who) {
+ if (!who) {
+ return "";
+ }
+
+ const escaped = escapeExpression(who);
+ if (
+ GROUP_ACTION_CODES.includes(code) ||
+ customGroupActionCodes.includes(code)
+ ) {
+ return `<a class="mention-group" href="/g/${encodeURIComponent(who)}">@${escaped}</a>`;
+ }
+ return `<a class="mention" href="${userPath(who)}">@${escaped}</a>`;
+}
+
+export default class NestedActivityLogItem extends Component {
+ get iconName() {
+ const code = this.args.action.action_code;
+ return ACTIVITY_LOG_ICONS[code] || ICONS[code] || "exclamation";
+ }
+
+ get description() {
+ return buildDescription(this.args.action, this.args.topicId);
+ }
+
+ get user() {
+ if (!this.args.action.username) {
+ return null;
+ }
+ return {
+ username: this.args.action.username,
+ avatar_template: this.args.action.avatar_template,
+ };
+ }
+
+ <template>
+ <li class="nested-activity-log-modal__item">
+ <span class="nested-activity-log-modal__icon" aria-hidden="true">
+ {{icon this.iconName}}
+ </span>
+ <div class="nested-activity-log-modal__content">
+ <div class="nested-activity-log-modal__desc">
+ {{#if this.user}}
+ <UserAvatar
+ @ariaHidden={{true}}
+ @size="small"
+ @user={{this.user}}
+ />
+ {{/if}}
+ <span>{{this.description}}</span>
+ </div>
+ {{#if @action.cooked}}
+ <div class="nested-activity-log-modal__message">
+ {{trustHTML @action.cooked}}
+ </div>
+ {{/if}}
+ </div>
+ </li>
+ </template>
+}
diff --git a/frontend/discourse/app/components/nested.gjs b/frontend/discourse/app/components/nested.gjs
index 7c5af42559c..45a45fad585 100644
--- a/frontend/discourse/app/components/nested.gjs
+++ b/frontend/discourse/app/components/nested.gjs
@@ -95,11 +95,20 @@ export default class Nested extends Component {
<div class="nested-view__controls">
<NestedSortSelector @current={{@sort}} @onChange={{@changeSort}} />
- {{#if this.currentUser.can_toggle_nested_mode}}
- <a href={{this.flatViewUrl}} class="nested-view__flat-link">{{i18n
- "nested_replies.view_as_flat"
- }}</a>
- {{/if}}
+ <div class="nested-view__controls-right">
+ <DButton
+ class="btn-flat nested-view__activity-link"
+ @action={{@showActivityLog}}
+ @label="nested_replies.activity_log.link"
+ />
+ {{#if this.currentUser.can_toggle_nested_mode}}
+ <DButton
+ class="btn-flat nested-view__flat-link"
+ @href={{this.flatViewUrl}}
+ @label="nested_replies.view_as_flat"
+ />
+ {{/if}}
+ </div>
</div>
{{#if (gt @newRootPostCount 0)}}
diff --git a/frontend/discourse/app/components/nested/context-view.gjs b/frontend/discourse/app/components/nested/context-view.gjs
index 96099406add..c35a193d8f6 100644
--- a/frontend/discourse/app/components/nested/context-view.gjs
+++ b/frontend/discourse/app/components/nested/context-view.gjs
@@ -124,11 +124,20 @@ export default class NestedContextView extends Component {
<div class="nested-view__controls">
<NestedSortSelector @current={{@sort}} @onChange={{@changeSort}} />
- {{#if this.currentUser.can_toggle_nested_mode}}
- <a href={{this.flatViewUrl}} class="nested-view__flat-link">{{i18n
- "nested_replies.view_as_flat"
- }}</a>
- {{/if}}
+ <div class="nested-view__controls-right">
+ <DButton
+ class="btn-flat nested-view__activity-link"
+ @action={{@showActivityLog}}
+ @label="nested_replies.activity_log.link"
+ />
+ {{#if this.currentUser.can_toggle_nested_mode}}
+ <DButton
+ class="btn-flat nested-view__flat-link"
+ @href={{this.flatViewUrl}}
+ @label="nested_replies.view_as_flat"
+ />
+ {{/if}}
+ </div>
</div>
<div class="nested-context-view__banner">
diff --git a/frontend/discourse/app/controllers/nested.js b/frontend/discourse/app/controllers/nested.js
index ee5783ca87e..ec74562b9b2 100644
--- a/frontend/discourse/app/controllers/nested.js
+++ b/frontend/discourse/app/controllers/nested.js
@@ -3,6 +3,7 @@ import Controller from "@ember/controller";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
+import NestedActivityLog from "discourse/components/modal/nested-activity-log";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { bind } from "discourse/lib/decorators";
@@ -18,8 +19,10 @@ export default class NestedController extends Controller {
@service dialog;
@service currentUser;
@service messageBus;
+ @service modal;
@service nestedViewCache;
@service router;
+ @service site;
@tracked topic;
@tracked opPost;
@@ -281,6 +284,13 @@ export default class NestedController extends Controller {
this.#topicRoute.showFlags(post);
}
+ @action
+ showActivityLog() {
+ this.modal.show(NestedActivityLog, {
+ model: { topic: this.topic },
+ });
+ }
+
// editingTopic is @tracked locally because the topic controller's
// editingTopic is a classic property (not @tracked) — a plain getter
// aliasing it won't trigger Glimmer re-renders. We sync the flag to
@@ -415,6 +425,10 @@ export default class NestedController extends Controller {
return;
}
+ if (!this.#isVisibleInTree(postData)) {
+ return;
+ }
+
const post = this.store.createRecord("post", postData);
post.topic = this.topic;
@@ -441,6 +455,20 @@ export default class NestedController extends Controller {
}
}
+ // Mirrors the server-side filter in NestedReplies::TreeLoader#apply_visibility:
+ // small_action posts (close/open/etc.) belong in the activity log, not the tree;
+ // whispers with an action_code (e.g. assigns) are likewise activity-log-only.
+ #isVisibleInTree(postData) {
+ const postTypes = this.site.post_types;
+ if (postData.post_type === postTypes.small_action) {
+ return false;
+ }
+ if (postData.post_type === postTypes.whisper && postData.action_code) {
+ return false;
+ }
+ return true;
+ }
+
#isPostKnown(postId) {
if (this.rootNodes.some((n) => n.post.id === postId)) {
return true;
diff --git a/frontend/discourse/app/templates/nested.gjs b/frontend/discourse/app/templates/nested.gjs
index 9056dfe2001..cc581371dc2 100644
--- a/frontend/discourse/app/templates/nested.gjs
+++ b/frontend/discourse/app/templates/nested.gjs
@@ -42,6 +42,7 @@ export default <template>
@expansionState={{@controller.expansionState}}
@fetchedChildrenCache={{@controller.fetchedChildrenCache}}
@scrollAnchor={{@controller.scrollAnchor}}
+ @showActivityLog={{@controller.showActivityLog}}
/>
{{else}}
<Nested
@@ -76,6 +77,7 @@ export default <template>
@expansionState={{@controller.expansionState}}
@fetchedChildrenCache={{@controller.fetchedChildrenCache}}
@scrollAnchor={{@controller.scrollAnchor}}
+ @showActivityLog={{@controller.showActivityLog}}
/>
{{/if}}
</template>
diff --git a/lib/nested_replies/tree_loader.rb b/lib/nested_replies/tree_loader.rb
index 4f0eb7b6037..c0514627603 100644
--- a/lib/nested_replies/tree_loader.rb
+++ b/lib/nested_replies/tree_loader.rb
@@ -85,6 +85,13 @@ module NestedReplies
def apply_visibility(scope)
scope = scope.unscope(where: :deleted_at)
scope = scope.where(post_type: visible_post_types)
+ if guardian.user&.whisperer?
+ scope =
+ scope.where(
+ "post_type != :whisper OR action_code IS NULL OR action_code = ''",
+ whisper: Post.types[:whisper],
+ )
+ end
scope
end
diff --git a/spec/requests/nested_topics_controller_spec.rb b/spec/requests/nested_topics_controller_spec.rb
index 7d2ba2ad6a8..0e827388a94 100644
--- a/spec/requests/nested_topics_controller_spec.rb
+++ b/spec/requests/nested_topics_controller_spec.rb
@@ -1172,4 +1172,86 @@ RSpec.describe NestedTopicsController, type: :request do
expect(TopicUser.count).to eq(topic_user_count)
end
end
+
+ describe "GET activity" do
+ def activity_url(topic)
+ "/n/#{topic.slug}/#{topic.id}/activity.json"
+ end
+
+ it "returns 404 when nested replies is disabled" do
+ SiteSetting.nested_replies_enabled = false
+ sign_in(user)
+ get activity_url(topic)
+ expect(response.status).to eq(404)
+ end
+
+ it "includes a synthetic topic_created entry first" do
+ sign_in(user)
+ get activity_url(topic)
+ expect(response.status).to eq(200)
+
+ actions = response.parsed_body["small_actions"]
+ expect(actions.length).to eq(1)
+ expect(actions[0]["action_code"]).to eq("topic_created")
+ expect(actions[0]["username"]).to eq(user.username)
+ end
+
+ it "returns small action posts in chronological order after topic_created" do
+ sign_in(user)
+
+ topic.add_small_action(admin, "closed.enabled")
+ topic.add_small_action(admin, "opened.enabled")
+ topic.add_small_action(admin, "invited_user", "testuser")
+
+ get activity_url(topic)
+ expect(response.status).to eq(200)
+
+ actions = response.parsed_body["small_actions"]
+ expect(actions.length).to eq(4)
+ expect(actions[0]["action_code"]).to eq("topic_created")
+ expect(actions[1]["action_code"]).to eq("closed.enabled")
+ expect(actions[2]["action_code"]).to eq("opened.enabled")
+ expect(actions[3]["action_code"]).to eq("invited_user")
+ expect(actions[3]["action_code_who"]).to eq("testuser")
+ expect(actions[1]["username"]).to eq(admin.username)
+ end
+
+ it "excludes whisper action-code posts for non-whisperers" do
+ topic.add_moderator_post(
+ admin,
+ nil,
+ post_type: Post.types[:whisper],
+ action_code: "assigned",
+ custom_fields: {
+ "action_code_who" => user.username,
+ },
+ )
+
+ sign_in(user)
+ get activity_url(topic)
+
+ actions = response.parsed_body["small_actions"]
+ expect(actions.map { |a| a["action_code"] }).not_to include("assigned")
+ end
+
+ it "includes whisper action-code posts for whisperers" do
+ SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
+
+ topic.add_moderator_post(
+ admin,
+ nil,
+ post_type: Post.types[:whisper],
+ action_code: "assigned",
+ custom_fields: {
+ "action_code_who" => user.username,
+ },
+ )
+
+ sign_in(admin)
+ get activity_url(topic)
+
+ actions = response.parsed_body["small_actions"]
+ expect(actions.map { |a| a["action_code"] }).to include("assigned")
+ end
+ end
end
diff --git a/spec/system/nested_activity_log_spec.rb b/spec/system/nested_activity_log_spec.rb
new file mode 100644
index 00000000000..c6b07002615
--- /dev/null
+++ b/spec/system/nested_activity_log_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+RSpec.describe "Nested activity log" do
+ fab!(:admin)
+ fab!(:topic) { Fabricate(:topic, user: admin) }
+ fab!(:op) { Fabricate(:post, topic: topic, user: admin, post_number: 1) }
+
+ before do
+ SiteSetting.nested_replies_enabled = true
+ sign_in(admin)
+ end
+
+ it "opens the activity log modal and lists small actions" do
+ topic.add_small_action(admin, "closed.enabled")
+
+ page.visit("/n/#{topic.slug}/#{topic.id}")
+ find(".nested-view__activity-link").click
+
+ expect(page).to have_css(".nested-activity-log-modal")
+ expect(page).to have_css(".nested-activity-log-modal__item", count: 2)
+ end
+end
diff --git a/spec/system/nested_realtime_spec.rb b/spec/system/nested_realtime_spec.rb
index 2c917239e4a..3ef330a1c0d 100644
--- a/spec/system/nested_realtime_spec.rb
+++ b/spec/system/nested_realtime_spec.rb
@@ -3,6 +3,7 @@
RSpec.describe "Nested view real-time updates" do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:other_user) { Fabricate(:user, refresh_auto_groups: true) }
+ fab!(:admin)
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
fab!(:root_reply) do
@@ -59,4 +60,25 @@ RSpec.describe "Nested view real-time updates" do
)
end
end
+
+ describe "small_action posts" do
+ it "does not insert close/open small_actions into the tree" do
+ nested_view.visit_nested(topic)
+ expect(nested_view).to have_root_post(root_reply)
+
+ small_action = topic.add_small_action(admin, "closed.enabled")
+
+ # A real reply published right after — once it surfaces, the small_action's
+ # message bus event has already been delivered (same channel, in order),
+ # so we can safely assert it never landed in the tree.
+ new_reply =
+ PostCreator.create!(other_user, topic_id: topic.id, raw: "Real reply that must show")
+
+ expect(page).to have_css(".nested-view__new-replies-btn", wait: 10)
+ find(".nested-view__new-replies-btn").click
+
+ expect(nested_view).to have_root_post(new_reply)
+ expect(page).to have_no_css("[data-post-number='#{small_action.post_number}']")
+ end
+ end
end