A platform for community discussion. Free, open, simple.
FEATURE: Add floating emoji reactions to live calls (#45178)
Rafael dos Santos Silva7f1302a2974a
diff --git a/plugins/live/app/controllers/live/rooms_controller.rb b/plugins/live/app/controllers/live/rooms_controller.rbindex 25ae643d71d..e3cb88f37c6 100644--- a/plugins/live/app/controllers/live/rooms_controller.rb+++ b/plugins/live/app/controllers/live/rooms_controller.rb@@ -11,6 +11,10 @@ module LiveSIGNAL_EVENTS_PER_USER_PER_MINUTE = 5_000SIGNAL_EVENTS_PER_ROOM_PER_MINUTE = 100_000+ # Generous enough for a burst of applause, low enough that one user can't+ # flood every participant's MessageBus.+ REACTIONS_PER_USER = 15 # per 10 seconds+STATE_FIELDS = %i[muted deafened video screen watching transcribing]# Anonymous visitors may browse the directory; the guardian still limits the@@ -40,6 +44,7 @@ module Livestop_recordingrequest_to_speakwithdraw_request_to_speak+ reaction]def index@@ -630,6 +635,20 @@ module Livehead :no_contentend+ def reaction+ guardian.ensure_can_join_live_room!(@room)+ ensure_participant_session!++ emoji = params.require(:emoji)+ raise Discourse::InvalidParameters.new(:emoji) if !Live::Reactions.valid?(emoji)++ RateLimiter.new(current_user, "live-reactions", REACTIONS_PER_USER, 10.seconds).performed!++ Live::RoomBroadcaster.publish_reaction(@room, current_user, emoji)++ head :no_content+ end+def signalguardian.ensure_can_join_live_room!(@room)# Room eligibility alone is not enough: signaling authority comes fromdiff --git a/plugins/live/app/services/live/room_broadcaster.rb b/plugins/live/app/services/live/room_broadcaster.rbindex bc08b85c9ca..a206514f40c 100644--- a/plugins/live/app/services/live/room_broadcaster.rb+++ b/plugins/live/app/services/live/room_broadcaster.rb@@ -22,6 +22,10 @@ module Livenew(room).publish_hand_raise(user_id, raised: raised, raised_at: raised_at, reason: reason)end+ def self.publish_reaction(room, user, emoji)+ new(room).publish_reaction(user, emoji)+ end+# Someone in the room started ringing `user` — lets open room pages show# a pending tile for them without refetching the room.def self.publish_ringing(room, user, notified_at:)@@ -132,6 +136,25 @@ module Live)end+ # Fire-and-forget: nothing is stored, so a client that misses one simply+ # never sees it float by.+ def publish_reaction(user, emoji)+ participant_ids = Live::ParticipantTracker.user_ids(room.id)+ return if participant_ids.empty?++ MessageBus.publish(+ Live.room_channel(room.id),+ {+ type: "reaction",+ room_id: room.id,+ user_id: user.id,+ username: user.username,+ emoji: emoji,+ },+ user_ids: participant_ids,+ )+ end+privateattr_reader :roomdiff --git a/plugins/live/assets/javascripts/discourse/app/services/live-reactions.js b/plugins/live/assets/javascripts/discourse/app/services/live-reactions.jsnew file mode 100644index 00000000000..13efe67fec3--- /dev/null+++ b/plugins/live/assets/javascripts/discourse/app/services/live-reactions.js@@ -0,0 +1,94 @@+import { tracked } from "@glimmer/tracking";+import { cancel } from "@ember/runloop";+import Service, { service } from "@ember/service";+import { ajax } from "discourse/lib/ajax";+import { popupAjaxError } from "discourse/lib/ajax-error";+import discourseLater from "discourse/lib/later";+import ReactionFeed from "../../lib/live/reaction-feed.js";++// Emoji reactions floating over a call. Room messages reach this through the+// live-webrtc service, which only forwards them for the call we're in.+export default class LiveReactionsService extends Service {+ @service currentUser;+ @service liveWebrtc;++ @tracked rateLimited = false;++ #feed = new ReactionFeed();+ #rateLimitTimer = null;++ willDestroy() {+ super.willDestroy(...arguments);+ cancel(this.#rateLimitTimer);+ }++ reactionsFor(roomId) {+ return this.#feed.forRoom(roomId);+ }++ // Shown locally straight away for instant feedback; the broadcast echo of+ // our own reaction is ignored.+ async send(roomId, emoji) {+ if (this.rateLimited) {+ return;+ }++ const reaction = this.#feed.add({+ roomId,+ userId: this.currentUser.id,+ username: this.currentUser.username,+ emoji,+ });++ try {+ await ajax(`/live/rooms/${roomId}/reaction`, {+ type: "POST",+ data: {+ emoji,+ participant_session_id:+ this.liveWebrtc.participantSessionIdFor(roomId),+ },+ });+ } catch (error) {+ this.#feed.remove(reaction.id);+ // Hitting the rate limit mid-burst isn't worth a popup; the picker+ // disables itself until the server's window reopens instead.+ if (error?.jqXHR?.status === 429) {+ this.#holdUntilRateLimitLifts(+ error.jqXHR.responseJSON?.extras?.wait_seconds ?? 1+ );+ } else {+ popupAjaxError(error);+ }+ }+ }++ receive(roomId, payload) {+ if (Number(payload.user_id) === this.currentUser?.id) {+ return;+ }++ this.#feed.add({+ roomId,+ userId: payload.user_id,+ username: payload.username,+ emoji: payload.emoji,+ });+ }++ clearRoom(roomId) {+ this.#feed.clearRoom(roomId);+ }++ #holdUntilRateLimitLifts(waitSeconds) {+ this.rateLimited = true;+ cancel(this.#rateLimitTimer);+ this.#rateLimitTimer = discourseLater(+ () => {+ this.rateLimited = false;+ this.#rateLimitTimer = null;+ },+ Math.max(1, waitSeconds) * 1000+ );+ }+}diff --git a/plugins/live/assets/javascripts/discourse/app/services/live-webrtc.js b/plugins/live/assets/javascripts/discourse/app/services/live-webrtc.jsindex c1b10ca8de7..4696f04b460 100644--- a/plugins/live/assets/javascripts/discourse/app/services/live-webrtc.js+++ b/plugins/live/assets/javascripts/discourse/app/services/live-webrtc.js@@ -72,6 +72,7 @@ export default class LiveWebrtcService extends Service {@service messageBus;@service modal;@service siteSettings;+ @service("live-reactions") liveReactions;@service("live-rooms") liveRooms;@service toasts;@@ -1674,6 +1675,7 @@ export default class LiveWebrtcService extends Service {this.#signaling.clearHttpQueue(roomId);this.#roomMessageQueue.clear(roomId);this.#transcription.stopIfTranscribing(roomId);+ this.liveReactions.clearRoom(roomId);}#handleRoomMessage(roomId, payload) {@@ -1737,6 +1739,16 @@ export default class LiveWebrtcService extends Service {await this.#roster.handleRoleChange(roomId, payload);} else if (payload.type === "hand_raise") {this.#roster.handleHandRaise(roomId, payload);+ } else if (payload.type === "reaction") {+ this.liveReactions.receive(roomId, payload);+ // Recorded from the broadcast, our own included, so the transcript holds+ // exactly what everyone in the call saw.+ this.#transcription.recordReaction(+ roomId,+ payload.user_id,+ payload.username,+ payload.emoji+ );} else if (payload.type === "kicked") {this.#handleKicked(roomId);} else if (payload.type === "room_updated") {diff --git a/plugins/live/assets/javascripts/discourse/components/live/call-widget.gjs b/plugins/live/assets/javascripts/discourse/components/live/call-widget.gjsindex 6d213c3b4df..ca7ced78ac7 100644--- a/plugins/live/assets/javascripts/discourse/components/live/call-widget.gjs+++ b/plugins/live/assets/javascripts/discourse/components/live/call-widget.gjs@@ -22,6 +22,7 @@ import LiveInviteAgentButton from "../live-invite-agent-button.gjs";import LiveInviteUsersModal from "../modal/live-invite-users.gjs";import LiveRoomInfoModal from "../modal/live-room-info.gjs";import LiveCallControls from "./call-controls.gjs";+import LiveReactionOverlay from "./reaction-overlay.gjs";import LiveRecordingBadge from "./recording-badge.gjs";import LiveRingingTile from "./ringing-tile.gjs";import LiveTranscriptBadge from "./transcript-badge.gjs";@@ -757,6 +758,8 @@ export default class LiveCallWidget extends Component {</button>{{/if}}</div>++ <LiveReactionOverlay @room={{this.room}} />{{/unless}}<footer class="live-call-widget__controls">diff --git a/plugins/live/assets/javascripts/discourse/components/live/reaction-overlay.gjs b/plugins/live/assets/javascripts/discourse/components/live/reaction-overlay.gjsnew file mode 100644index 00000000000..5e68c94649e--- /dev/null+++ b/plugins/live/assets/javascripts/discourse/components/live/reaction-overlay.gjs@@ -0,0 +1,33 @@+import Component from "@glimmer/component";+import { service } from "@ember/service";+import { trustHTML } from "@ember/template";+import dEmoji from "discourse/ui-kit/helpers/d-emoji";++function offsetStyle(reaction) {+ return trustHTML(`--live-reaction-offset: ${reaction.offset}%`);+}++export default class LiveReactionOverlay extends Component {+ @service liveReactions;++ get reactions() {+ return this.liveReactions.reactionsFor(this.args.room.id);+ }++ <template>+ {{! Purely decorative: screen readers would otherwise announce every+ reaction, which drowns out the call in a busy room. }}+ <div aria-hidden="true" class="live-reactions">+ {{#each this.reactions key="id" as |reaction|}}+ <span+ class="live-reactions__item"+ data-emoji={{reaction.emoji}}+ style={{offsetStyle reaction}}+ >+ <span class="live-reactions__emoji">{{dEmoji reaction.emoji}}</span>+ <span class="live-reactions__username">{{reaction.username}}</span>+ </span>+ {{/each}}+ </div>+ </template>+}diff --git a/plugins/live/assets/javascripts/discourse/components/live/reaction-picker.gjs b/plugins/live/assets/javascripts/discourse/components/live/reaction-picker.gjsnew file mode 100644index 00000000000..f971a0a5079--- /dev/null+++ b/plugins/live/assets/javascripts/discourse/components/live/reaction-picker.gjs@@ -0,0 +1,61 @@+import Component from "@glimmer/component";+import { fn } from "@ember/helper";+import { action } from "@ember/object";+import { service } from "@ember/service";+import DMenu from "discourse/float-kit/components/d-menu";+import DButton from "discourse/ui-kit/d-button";+import dEmoji from "discourse/ui-kit/helpers/d-emoji";+import { i18n } from "discourse-i18n";++export default class LiveReactionPicker extends Component {+ @service liveReactions;+ @service site;+ @service siteSettings;++ get emojis() {+ return this.siteSettings.enable_emoji+ ? (this.site.live_reaction_emojis ?? [])+ : [];+ }++ get title() {+ return this.liveReactions.rateLimited+ ? i18n("live.reactions.rate_limited")+ : i18n("live.reactions.title");+ }++ // The menu stays open so a burst of applause doesn't need a reopen per clap.+ @action+ react(emoji) {+ this.liveReactions.send(this.args.room.id, emoji);+ }++ <template>+ {{#if this.emojis.length}}+ <DMenu+ @ariaLabel={{this.title}}+ @disabled={{this.liveReactions.rateLimited}}+ @icon="far-face-smile"+ @identifier="live-reaction-menu"+ @placement="top"+ @title={{this.title}}+ @triggerClass="btn-default live-reaction-picker__trigger"+ >+ <:content>+ <div class="live-reaction-picker">+ {{#each this.emojis as |emoji|}}+ <DButton+ class="btn-transparent live-reaction-picker__emoji"+ data-emoji={{emoji}}+ @action={{fn this.react emoji}}+ @translatedTitle={{emoji}}+ >+ {{dEmoji emoji}}+ </DButton>+ {{/each}}+ </div>+ </:content>+ </DMenu>+ {{/if}}+ </template>+}diff --git a/plugins/live/assets/javascripts/discourse/components/live/room-page.gjs b/plugins/live/assets/javascripts/discourse/components/live/room-page.gjsindex c632bee906e..78be6c37af9 100644--- a/plugins/live/assets/javascripts/discourse/components/live/room-page.gjs+++ b/plugins/live/assets/javascripts/discourse/components/live/room-page.gjs@@ -34,6 +34,8 @@ import LiveCallControls from "./call-controls.gjs";import LiveCallSubmenu from "./call-submenu.gjs";import LiveCaptionOverlay from "./caption-overlay.gjs";import LiveChatPanel from "./chat-panel.gjs";+import LiveReactionOverlay from "./reaction-overlay.gjs";+import LiveReactionPicker from "./reaction-picker.gjs";import LiveRingingTile from "./ringing-tile.gjs";import LiveRoomHeader from "./room-header.gjs";import LiveSpeakQueue from "./speak-queue.gjs";@@ -657,11 +659,13 @@ export default class LiveRoomPage extends Component {{{/if}}{{#if this.joined}}<LiveCaptionOverlay @room={{this.room}} />+ <LiveReactionOverlay @room={{this.room}} />{{/if}}<footer class="live-room-page__controls">{{#if this.joined}}<LiveCallControls @room={{this.room}} />+ <LiveReactionPicker @room={{this.room}} />{{#if this.isStageRoom}}<DMenu@ariaLabel={{i18n "live.stage.queue_title"}}diff --git a/plugins/live/assets/javascripts/discourse/lib/live/reaction-feed.js b/plugins/live/assets/javascripts/discourse/lib/live/reaction-feed.jsnew file mode 100644index 00000000000..d0b5ffdf02f--- /dev/null+++ b/plugins/live/assets/javascripts/discourse/lib/live/reaction-feed.js@@ -0,0 +1,69 @@+import { tracked } from "@glimmer/tracking";+import { cancel } from "@ember/runloop";+import discourseLater from "discourse/lib/later";++// Matches the float animation in live-room-page.scss.+export const REACTION_TTL_MS = 4000;+// A burst from a large room would otherwise pile up hundreds of nodes.+export const MAX_VISIBLE_REACTIONS = 40;++let nextId = 0;++// Reactions currently floating over a call. Expiry is timer-driven rather+// than tied to animationend: animations pause in background tabs, which would+// replay a backlog of stale reactions when the user returns.+export default class ReactionFeed {+ @tracked reactions = [];++ #timers = new Map();++ add({ roomId, userId, username, emoji }) {+ const reaction = {+ id: ++nextId,+ roomId: Number(roomId),+ userId: Number(userId),+ username,+ emoji,+ // Percent across the overlay, kept off the edges so the label fits.+ offset: 10 + Math.random() * 80,+ };++ const overflow = Math.max(+ 0,+ this.reactions.length + 1 - MAX_VISIBLE_REACTIONS+ );+ for (const dropped of this.reactions.slice(0, overflow)) {+ this.#clearTimer(dropped.id);+ }+ this.reactions = [...this.reactions.slice(overflow), reaction];++ this.#timers.set(+ reaction.id,+ discourseLater(() => this.remove(reaction.id), REACTION_TTL_MS)+ );++ return reaction;+ }++ remove(id) {+ this.#clearTimer(id);+ this.reactions = this.reactions.filter((reaction) => reaction.id !== id);+ }++ forRoom(roomId) {+ return this.reactions.filter(+ (reaction) => reaction.roomId === Number(roomId)+ );+ }++ clearRoom(roomId) {+ for (const reaction of this.forRoom(roomId)) {+ this.remove(reaction.id);+ }+ }++ #clearTimer(id) {+ cancel(this.#timers.get(id));+ this.#timers.delete(id);+ }+}diff --git a/plugins/live/assets/javascripts/discourse/lib/live/transcript-markdown.js b/plugins/live/assets/javascripts/discourse/lib/live/transcript-markdown.jsindex 1f9941359a8..e3d10d9500e 100644--- a/plugins/live/assets/javascripts/discourse/lib/live/transcript-markdown.js+++ b/plugins/live/assets/javascripts/discourse/lib/live/transcript-markdown.js@@ -19,15 +19,30 @@ export function transcriptToMarkdown(.map((entry, index) => {const username =entry.username || i18n("live.transcript.unknown_speaker");+ const text = entry.reactions ? reactionsText(entry) : entry.text;if (chatMarkup) {const timestamp = new Date(entry.startedAt).toISOString();const source =index === 0 && roomName? `${serializeBBCodeAttr(roomName, "source")}${serializeBBCodeAttr(TRANSCRIPT_SOURCE_TYPE, "sourceType")}`: "";- return `[chat quote="${username};${entry.utteranceId};${timestamp}"${source} chained="true"]\n${entry.text}\n[/chat]`;+ // Prefixed so it can't collide with a numeric utterance id.+ const id = entry.reactions+ ? `reaction-${entry.reactionId}`+ : entry.utteranceId;+ return `[chat quote="${username};${id};${timestamp}"${source} chained="true"]\n${text}\n[/chat]`;}- return `[quote="${username}"]\n${entry.text}\n[/quote]`;+ return `[quote="${username}"]\n${text}\n[/quote]`;}).join("\n\n");}++function reactionsText(entry) {+ return entry.reactions+ .map(({ emoji, count }) =>+ count > 1+ ? i18n("live.transcript.reaction_count", { emoji: `:${emoji}:`, count })+ : `:${emoji}:`+ )+ .join(" ");+}diff --git a/plugins/live/assets/javascripts/discourse/lib/live/transcript-recorder.js b/plugins/live/assets/javascripts/discourse/lib/live/transcript-recorder.jsindex f9d6460e6de..ac056a9de3c 100644--- a/plugins/live/assets/javascripts/discourse/lib/live/transcript-recorder.js+++ b/plugins/live/assets/javascripts/discourse/lib/live/transcript-recorder.js@@ -1,5 +1,7 @@// Accumulates a meeting transcript from the subtitles pipeline: one entry per// final utterance, with the speaker and the utterance's start wall-clock.+// In-call reactions are interleaved as entries carrying `reactions` instead+// of `text`.//// Recording is scoped to a single room. Interim captions never land here —// only finals do — and a null-text final withdraws the entry (a VAD misfire,@@ -14,6 +16,7 @@ export default class TranscriptRecorder {// so a consumer can still attribute the finished transcript.#entriesRoomId = null;#startedAt = null;+ #reactionCounter = 0;constructor({ onChange }) {this.#onChange = onChange;@@ -102,4 +105,51 @@ export default class TranscriptRecorder {];this.#onChange();}++ // Reactions between two utterances fold into one entry per reacting user,+ // so a burst of applause reads as a single line instead of drowning out+ // what was said.+ recordReaction(roomId, userId, username, emoji, at = Date.now()) {+ if (!this.recording || Number(roomId) !== Number(this.#roomId)) {+ return;+ }++ const lastUtterance = this.#entries.findLastIndex(+ (entry) => !entry.reactions+ );+ const groupIndex = this.#entries.findIndex(+ (entry, index) =>+ index > lastUtterance && Number(entry.userId) === Number(userId)+ );++ if (groupIndex === -1) {+ this.#entries = [+ ...this.#entries,+ {+ reactionId: ++this.#reactionCounter,+ userId,+ username,+ reactions: [{ emoji, count: 1 }],+ startedAt: at,+ },+ ];+ } else {+ this.#entries = this.#entries.map((entry, index) =>+ index === groupIndex+ ? { ...entry, reactions: addReaction(entry.reactions, emoji) }+ : entry+ );+ }+ this.#onChange();+ }+}++function addReaction(reactions, emoji) {+ return reactions.some((reaction) => reaction.emoji === emoji)+ ? reactions.map((reaction) =>+ reaction.emoji === emoji+ ? { ...reaction, count: reaction.count + 1 }+ : reaction+ )+ : [...reactions, { emoji, count: 1 }];}diff --git a/plugins/live/assets/javascripts/discourse/lib/live/transcription-coordinator.js b/plugins/live/assets/javascripts/discourse/lib/live/transcription-coordinator.jsindex af0f54fc509..d60ebfcb248 100644--- a/plugins/live/assets/javascripts/discourse/lib/live/transcription-coordinator.js+++ b/plugins/live/assets/javascripts/discourse/lib/live/transcription-coordinator.js@@ -197,6 +197,10 @@ export default class TranscriptionCoordinator {this.#broadcastTranscribingState(roomId, true);}+ recordReaction(roomId, userId, username, emoji) {+ this.#transcript.recordReaction(roomId, userId, username, emoji);+ }+// Leaving the recorded room ends the recording; the transcript gathered so// far is kept for consumption.stopIfTranscribing(roomId) {diff --git a/plugins/live/assets/stylesheets/common/live-room-page.scss b/plugins/live/assets/stylesheets/common/live-room-page.scssindex cf4382d63de..2e745d2460a 100644--- a/plugins/live/assets/stylesheets/common/live-room-page.scss+++ b/plugins/live/assets/stylesheets/common/live-room-page.scss@@ -283,6 +283,7 @@ html.discourse-touch .live-call-widget {// and the control bar sits on the bottom row, level with the chat panel's// composer next door.&__stage {+ position: relative;flex: 1;min-height: 0;display: flex;@@ -676,6 +677,115 @@ body.has-sidebar-page #main-outlet-wrapper:has(.live-room-header) {}}+// Each item spans the overlay's full height with its content pinned to the+// bottom, so a percentage translate rises relative to the overlay — keeping+// the animation on the compositor regardless of how tall the stage is.+.live-reactions {+ position: absolute;+ inset: 0 0 var(--live-reactions-bottom, 4rem);+ z-index: 2;+ overflow: hidden;+ pointer-events: none;++ .live-call-widget & {+ --live-reactions-bottom: 3.5rem;+ }++ &__item {+ position: absolute;+ inset-block: 0;+ inset-inline-start: var(--live-reaction-offset, 50%);+ display: flex;+ flex-direction: column;+ justify-content: flex-end;+ align-items: center;+ row-gap: 0.15rem;+ animation: live-reaction-float 4s ease-out forwards;++ @media (prefers-reduced-motion: reduce) {+ animation-name: live-reaction-fade;+ }+ }++ &__emoji .emoji {+ width: 2.25rem;+ height: 2.25rem;++ .live-call-widget & {+ width: 1.5rem;+ height: 1.5rem;+ }+ }++ &__username {+ max-width: 8rem;+ padding: 0 0.4em;+ overflow: hidden;+ border-radius: var(--d-border-radius);+ background: rgb(0 0 0 / 55%);+ color: #fff;+ font-size: var(--font-down-2);+ text-overflow: ellipsis;+ white-space: nowrap;+ }+}++@keyframes live-reaction-float {+ 0% {+ opacity: 0;+ transform: translate(-50%, 0) scale(0.6);+ }++ 10% {+ opacity: 1;+ transform: translate(-50%, -8%) scale(1);+ }++ 75% {+ opacity: 1;+ }++ 100% {+ opacity: 0;+ transform: translate(-50%, -80%) scale(1);+ }+}++@keyframes live-reaction-fade {+ 0%,+ 100% {+ opacity: 0;+ transform: translateX(-50%);+ }++ 15%,+ 75% {+ opacity: 1;+ transform: translateX(-50%);+ }+}++.live-reaction-picker {+ display: flex;+ gap: var(--space-1);+ padding: var(--space-1);++ &__emoji {+ padding: var(--space-1);++ .emoji {+ width: 1.75rem;+ height: 1.75rem;+ transition: transform 0.1s ease-out;+ }++ &:hover .emoji,+ &:focus-visible .emoji {+ transform: scale(1.2);+ }+ }+}+@keyframes live-ns-badge-pulse {50% {opacity: 0.4;diff --git a/plugins/live/config/locales/client.en.yml b/plugins/live/config/locales/client.en.ymlindex d79c22cb6da..90710c00f49 100644--- a/plugins/live/config/locales/client.en.yml+++ b/plugins/live/config/locales/client.en.yml@@ -13,6 +13,9 @@ en:title: "Live rooms"create: "Create room"empty: "No live rooms yet."+ reactions:+ title: "Send a reaction"+ rate_limited: "You're sending reactions too quickly. Try again in a moment."room:join: "Join live room"leave: "Leave room"@@ -209,6 +212,7 @@ en:draft_topic: "Open transcript draft"stop_and_open: "Stop recording and open draft"draft_title: "Call transcript: %{room}"+ reaction_count: "%{emoji} ×%{count}"source_label: "Call transcript"unknown_speaker: "unknown speaker"stage:diff --git a/plugins/live/config/routes.rb b/plugins/live/config/routes.rbindex c1d263788fb..c37d8d4f284 100644--- a/plugins/live/config/routes.rb+++ b/plugins/live/config/routes.rb@@ -19,6 +19,7 @@ Live::Engine.routes.draw dodelete :recording, action: :stop_recording, as: :stop_recordingdelete :kickpost :flag+ post :reactionpost :request_to_speakdelete :request_to_speak, action: :withdraw_request_to_speak, as: :withdraw_request_to_speakenddiff --git a/plugins/live/lib/live.rb b/plugins/live/lib/live.rbindex f62f7502367..46c55f53519 100644--- a/plugins/live/lib/live.rb+++ b/plugins/live/lib/live.rb@@ -60,6 +60,7 @@ require_relative "live/livekit/webhook_verifier"require_relative "live/inline_onebox_handler"require_relative "live/media_entitlements"require_relative "live/onebox_handler"+require_relative "live/reactions"require_relative "live/room_hashtag_data_source"require_relative "live/user_status_manager"require_relative "../app/services/live/agent_manager"diff --git a/plugins/live/lib/live/reactions.rb b/plugins/live/lib/live/reactions.rbnew file mode 100644index 00000000000..ad54c76201a--- /dev/null+++ b/plugins/live/lib/live/reactions.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true++module Live+ # In-call reactions offer the same emoji set the site curated for post+ # reactions. When post reactions are turned off, that setting's stock value+ # stands in, so an admin's tweaks to a disabled feature don't leak into calls.+ module Reactions+ ENABLED_SETTING = :discourse_reactions_enabled+ LIST_SETTING = :discourse_reactions_enabled_reactions+ MAIN_SETTING = :discourse_reactions_reaction_for_like++ # Used only when the post reactions settings aren't registered at all.+ FALLBACK = %w[heart +1 laughing open_mouth clap confetti_ball hugs].freeze++ def self.emojis+ return FALLBACK if !SiteSetting.has_setting?(LIST_SETTING)++ read =+ if SiteSetting.get(ENABLED_SETTING)+ ->(name) { SiteSetting.get(name) }+ else+ ->(name) { SiteSetting.defaults[name] }+ end++ [read.(MAIN_SETTING), *read.(LIST_SETTING).to_s.split("|")].compact_blank.uniq+ end++ def self.valid?(emoji)+ emojis.include?(emoji)+ end+ end+enddiff --git a/plugins/live/plugin.rb b/plugins/live/plugin.rbindex 6be028ca282..7c3ae8f69bf 100644--- a/plugins/live/plugin.rb+++ b/plugins/live/plugin.rb@@ -175,6 +175,8 @@ after_initialize doSiteSetting.live_screen_share_allowed_groups.present?end+ add_to_serializer(:site, :live_reaction_emojis) { Live::Reactions.emojis }+Live::DefaultRoomSeeder.ensure! if SiteSetting.live_enabled?Live::AgentBot.ensure! if SiteSetting.live_enabled?diff --git a/plugins/live/spec/lib/live/reactions_spec.rb b/plugins/live/spec/lib/live/reactions_spec.rbnew file mode 100644index 00000000000..dc10555be0d--- /dev/null+++ b/plugins/live/spec/lib/live/reactions_spec.rb@@ -0,0 +1,26 @@+# frozen_string_literal: true++RSpec.describe Live::Reactions do+ describe ".emojis" do+ it "offers the site's post reaction set, main reaction first, when post reactions are enabled" do+ SiteSetting.discourse_reactions_enabled = true+ SiteSetting.discourse_reactions_reaction_for_like = "+1"+ SiteSetting.discourse_reactions_enabled_reactions = "+1|tada|rocket"++ expect(described_class.emojis).to eq(%w[+1 tada rocket])+ end++ it "offers the stock post reaction set when post reactions are disabled" do+ SiteSetting.discourse_reactions_enabled = false+ SiteSetting.discourse_reactions_reaction_for_like = "+1"+ SiteSetting.discourse_reactions_enabled_reactions = "tada|rocket"++ expect(described_class.emojis).to eq(+ [+ SiteSetting.defaults[:discourse_reactions_reaction_for_like],+ *SiteSetting.defaults[:discourse_reactions_enabled_reactions].split("|"),+ ],+ )+ end+ end+enddiff --git a/plugins/live/spec/requests/live/rooms_controller_reactions_spec.rb b/plugins/live/spec/requests/live/rooms_controller_reactions_spec.rbnew file mode 100644index 00000000000..feb7630b86b--- /dev/null+++ b/plugins/live/spec/requests/live/rooms_controller_reactions_spec.rb@@ -0,0 +1,109 @@+# frozen_string_literal: true++RSpec.describe Live::RoomsController do+ fab!(:room_owner) { Fabricate(:user, trust_level: TrustLevel[2]) }+ fab!(:participant) { Fabricate(:user, trust_level: TrustLevel[2]) }+ fab!(:other_participant) { Fabricate(:user, trust_level: TrustLevel[2]) }+ fab!(:outsider) { Fabricate(:user, trust_level: TrustLevel[2]) }+ fab!(:room) { Fabricate(:live_room, creator: room_owner, public: true) }++ before do+ SiteSetting.live_enabled = true+ SiteSetting.live_allowed_groups = "#{Group::AUTO_GROUPS[:logged_in_users]}"+ SiteSetting.discourse_reactions_enabled = true+ SiteSetting.discourse_reactions_reaction_for_like = "heart"+ SiteSetting.discourse_reactions_enabled_reactions = "clap|tada"++ Live::ParticipantTracker.add(room.id, participant.id)+ Live::ParticipantTracker.add(room.id, other_participant.id)+ @session_id = Live::ParticipantTracker.create_participant_session!(room.id, participant.id)+ end++ after { Live::ParticipantTracker.clear(room.id) }++ describe "#reaction" do+ it "broadcasts the reaction to everyone in the call" do+ sign_in(participant)++ messages =+ MessageBus.track_publish(Live.room_channel(room.id)) do+ post "/live/rooms/#{room.id}/reaction.json",+ params: {+ emoji: "clap",+ participant_session_id: @session_id,+ }+ end++ expect(response.status).to eq(204)+ expect(messages.size).to eq(1)+ expect(messages.first.data).to eq(+ type: "reaction",+ room_id: room.id,+ user_id: participant.id,+ username: participant.username,+ emoji: "clap",+ )+ expect(messages.first.user_ids).to contain_exactly(participant.id, other_participant.id)+ end++ it "accepts the main reaction even when it isn't in the enabled list" do+ sign_in(participant)++ post "/live/rooms/#{room.id}/reaction.json",+ params: {+ emoji: "heart",+ participant_session_id: @session_id,+ }++ expect(response.status).to eq(204)+ end++ it "rejects an emoji outside the reaction set without broadcasting" do+ sign_in(participant)++ messages =+ MessageBus.track_publish(Live.room_channel(room.id)) do+ post "/live/rooms/#{room.id}/reaction.json",+ params: {+ emoji: "poop",+ participant_session_id: @session_id,+ }+ end++ expect(response.status).to eq(400)+ expect(messages).to be_empty+ end++ it "returns 403 for a user who hasn't joined the call" do+ sign_in(outsider)++ post "/live/rooms/#{room.id}/reaction.json", params: { emoji: "clap" }++ expect(response.status).to eq(403)+ end++ it "rate limits bursts beyond the per-user budget" do+ RateLimiter.enable+ sign_in(participant)++ Live::RoomsController::REACTIONS_PER_USER.times do+ post "/live/rooms/#{room.id}/reaction.json",+ params: {+ emoji: "clap",+ participant_session_id: @session_id,+ }+ end+ expect(response.status).to eq(204)++ post "/live/rooms/#{room.id}/reaction.json",+ params: {+ emoji: "clap",+ participant_session_id: @session_id,+ }++ expect(response.status).to eq(429)+ # The picker stays disabled for exactly this long.+ expect(response.parsed_body.dig("extras", "wait_seconds")).to be_between(1, 10)+ end+ end+enddiff --git a/plugins/live/test/javascripts/unit/lib/reaction-feed-test.js b/plugins/live/test/javascripts/unit/lib/reaction-feed-test.jsnew file mode 100644index 00000000000..275bcf24dba--- /dev/null+++ b/plugins/live/test/javascripts/unit/lib/reaction-feed-test.js@@ -0,0 +1,61 @@+import { settled } from "@ember/test-helpers";+import { module, test } from "qunit";+import ReactionFeed, {+ MAX_VISIBLE_REACTIONS,+} from "discourse/plugins/live/discourse/lib/live/reaction-feed";++function reaction(roomId, emoji = "clap") {+ return { roomId, userId: 1, username: "sam", emoji };+}++module("Live | Unit | Lib | reaction-feed", function () {+ test("scopes reactions to their room", function (assert) {+ const feed = new ReactionFeed();+ feed.add(reaction(1, "clap"));+ feed.add(reaction("2", "heart"));++ assert.deepEqual(+ feed.forRoom(1).map((entry) => entry.emoji),+ ["clap"]+ );+ assert.deepEqual(+ feed.forRoom(2).map((entry) => entry.emoji),+ ["heart"],+ "room ids are compared numerically"+ );+ });++ test("expires reactions once they've floated by", async function (assert) {+ const feed = new ReactionFeed();+ feed.add(reaction(1));++ await settled();++ assert.deepEqual(feed.forRoom(1), []);+ });++ test("drops the oldest reactions beyond the visible cap", function (assert) {+ const feed = new ReactionFeed();+ const first = feed.add(reaction(1));+ for (let i = 0; i < MAX_VISIBLE_REACTIONS; i++) {+ feed.add(reaction(1));+ }++ assert.strictEqual(feed.forRoom(1).length, MAX_VISIBLE_REACTIONS);+ assert.false(+ feed.forRoom(1).some((entry) => entry.id === first.id),+ "the oldest reaction made room"+ );+ });++ test("clearRoom leaves other rooms untouched", function (assert) {+ const feed = new ReactionFeed();+ feed.add(reaction(1));+ feed.add(reaction(2));++ feed.clearRoom(1);++ assert.strictEqual(feed.forRoom(1).length, 0);+ assert.strictEqual(feed.forRoom(2).length, 1);+ });+});diff --git a/plugins/live/test/javascripts/unit/lib/transcript-markdown-test.js b/plugins/live/test/javascripts/unit/lib/transcript-markdown-test.jsindex 9a484f41987..aa14490c226 100644--- a/plugins/live/test/javascripts/unit/lib/transcript-markdown-test.js+++ b/plugins/live/test/javascripts/unit/lib/transcript-markdown-test.js@@ -74,4 +74,26 @@ module("Live | Unit | Lib | transcript-markdown", function (hooks) {assert.false(markdown.includes('"undefined;'));assert.true(markdown.startsWith("[chat quote="));});++ test("renders a reaction group as the reactor's emoji line", function (assert) {+ const reactionEntry = {+ reactionId: 1,+ userId: 43,+ username: "bob",+ reactions: [+ { emoji: "clap", count: 3 },+ { emoji: "heart", count: 1 },+ ],+ startedAt: Date.UTC(2026, 7, 20, 16, 38, 50),+ };++ assert.strictEqual(+ transcriptToMarkdown([reactionEntry]),+ '[chat quote="bob;reaction-1;2026-08-20T16:38:50.000Z" chained="true"]\n:clap: ×3 :heart:\n[/chat]'+ );+ assert.strictEqual(+ transcriptToMarkdown([reactionEntry], { chatMarkup: false }),+ '[quote="bob"]\n:clap: ×3 :heart:\n[/quote]'+ );+ });});diff --git a/plugins/live/test/javascripts/unit/lib/transcript-recorder-test.js b/plugins/live/test/javascripts/unit/lib/transcript-recorder-test.jsindex 5d485cee806..576330319fb 100644--- a/plugins/live/test/javascripts/unit/lib/transcript-recorder-test.js+++ b/plugins/live/test/javascripts/unit/lib/transcript-recorder-test.js@@ -135,4 +135,46 @@ module("Live | Unit | Lib | transcript-recorder", function (hooks) {assert.strictEqual(this.changes, 3);});++ test("folds each user's reactions between utterances into one entry", function (assert) {+ this.recorder.start(1);+ this.recorder.recordReaction(1, 43, "bob", "clap", 1000);+ this.recorder.recordReaction(1, 44, "carol", "heart", 1100);+ this.recorder.recordReaction(1, 43, "bob", "clap", 1200);+ this.recorder.recordReaction(1, 43, "bob", "heart", 1300);+ this.recorder.record(1, 42, "alice", {+ id: 7,+ text: "thanks",+ final: true,+ startedAt: 2000,+ });+ this.recorder.recordReaction(1, 43, "bob", "clap", 3000);++ assert.deepEqual(+ this.recorder.entries.map((entry) => [+ entry.username,+ entry.text ?? entry.reactions,+ ]),+ [+ [+ "bob",+ [+ { emoji: "clap", count: 2 },+ { emoji: "heart", count: 1 },+ ],+ ],+ ["carol", [{ emoji: "heart", count: 1 }]],+ ["alice", "thanks"],+ ["bob", [{ emoji: "clap", count: 1 }]],+ ]+ );+ });++ test("ignores reactions from other rooms and while not recording", function (assert) {+ this.recorder.recordReaction(1, 43, "bob", "clap");+ this.recorder.start(1);+ this.recorder.recordReaction(2, 43, "bob", "clap");++ assert.deepEqual(this.recorder.entries, []);+ });});