A platform for community discussion. Free, open, simple.
DEV: Customization enhancements for the Glimmer Post Stream (#32063)
Sérgio Saquetimd4b6f04ab0e5
diff --git a/app/assets/javascripts/discourse/app/components/post.gjs b/app/assets/javascripts/discourse/app/components/post.gjsindex 307deed6819..567fb83df2e 100644--- a/app/assets/javascripts/discourse/app/components/post.gjs+++ b/app/assets/javascripts/discourse/app/components/post.gjs@@ -333,247 +333,272 @@ export default class Post extends Component {{{parentClass "post--cloaked cloaked-post" parentSelector="div"}}></article>{{else}}- <article- {{parentClass- (concatClass- "topic-post"- "clearfix"- (if this.staged "post--staged staged")- (if @selected "post--selected selected")- (if @post.topicOwner "post--topic-owner topic-owner")- (if this.isFromCurrentUser "post--current-user current-user-post")- (if- @post.group_moderator- "post--category-moderator category-moderator"- )- (if @post.hidden "post--hidden post-hidden")- (if @post.deleted "post--deleted deleted")- (if- @post.primary_group_name+ {{#let+ (hash+ post=@post+ actions=(hash updateTopicPageQueryParams=@updateTopicPageQueryParams)+ topicPageQueryParams=@topicPageQueryParams+ )+ as |postOutletArgs|+ }}+ <PluginOutlet @name="post-article" @outletArgs={{postOutletArgs}}>+ <article+ {{parentClass(concatClass- (concat "post--group-" @post.primary_group_name)- (concat "group-" @post.primary_group_name)- )- )- (if @post.wiki "post--wiki wiki")- (if @post.isWhisper "post--whisper whisper")- (if- (or @post.isModeratorAction (and @post.isWarning @post.firstPost))- "post--moderator moderator"- "post--regular regular"- )- (if @post.user_suspended "post--user-suspended user-suspended")- this.additionalClasses- )- parentSelector="div"- }}- ...attributes- id={{this.id}}- class={{concatClass- "boxed"- "onscreen-post"- (if this.hasRepliesAbove "post--has-replies-above replies-above")- (if @post.is_auto_generated "post--auto-generated is-auto-generated")- (if @post.via_email "post--via-email via-email")- }}- aria-label={{i18n- "share.post"- (hash [email protected]_number [email protected])- }}- role="region"- data-post-id={{@post.id}}- data-topic-id={{@post.topicId}}- data-user-id={{@post.user_id}}- >- {{#if this.hasRepliesAbove}}- <div class="post__row row">- <section- id={{concat "embedded-posts__top--" @post.post_number}}- class="post__embedded-posts post__embedded-posts--top post__body embedded-posts top topic-body"- >- <DButton- class="post__collapse-button post__collapse-button-down collapse-down"- @action={{this.toggleReplyAbove}}- @icon="chevron-down"- @title="post.collapse"- />- {{#each this.repliesAbove.value key="id" as |reply|}}- <PostEmbedded- @post={{reply}}- @above={{true}}- @highlightTerm={{this.search.highlightTerm}}- />- {{/each}}- </section>- </div>- {{/if}}- {{#if (and (not @post.deletedAt) @post.notice)}}- <div class="post__row row">- <PostNotice @post={{@post}} />- </div>- {{/if}}- <div class="post__row row">- <PostAvatar @post={{@post}} />- <div class="post__body topic-body clearfix">- <PluginOutlet @name="post-metadata" @outletArgs={{hash post=@post}}>- <PostMetaData- @post={{@post}}- @editPost={{@editPost}}- @hasRepliesAbove={{this.hasRepliesAbove}}- @isReplyingDirectlyToPostAbove={{this.isReplyingDirectlyToPostAbove}}- @multiSelect={{@multiSelect}}- @repliesAbove={{this.repliesAbove}}- @selectBelow={{@selectBelow}}- @selectReplies={{@selectReplies}}- @selected={{@selected}}- @showHistory={{@showHistory}}- @showRawEmail={{@showRawEmail}}- @togglePostSelection={{@togglePostSelection}}- @toggleReplyAbove={{this.toggleReplyAbove}}- />- </PluginOutlet>- <div- class={{concatClass- "post__regular regular"- (unless this.repliesShown "post__contents contents")+ "topic-post"+ "clearfix"+ (if this.staged "post--staged staged")+ (if @selected "post--selected selected")+ (if @post.topicOwner "post--topic-owner topic-owner")(if- this.isReplyToTabDisplayed- "post__contents--avoid-tab avoid-tab"+ this.isFromCurrentUser "post--current-user current-user-post")- }}- >- <PluginOutlet @name="post-content-cooked-html" @post={{@post}}>- <PostCookedHtml- @post={{@post}}- @highlightTerm={{this.search.highlightTerm}}- />- </PluginOutlet>-- {{#if @post.requestedGroupName}}- <div class="post__group-request group-request">- <a href={{this.groupRequestUrl}}>- {{i18n "groups.requests.handle"}}- </a>- </div>- {{/if}}-- {{#if (and @post.cooked_hidden @post.can_see_hidden_post)}}- {{! template-lint-disable no-invalid-interactive }}- <a- class="post__expand-hidden expand-hidden"- {{on "click" @expandHidden}}- >- {{i18n "post.show_hidden"}}- </a>- {{/if}}-- {{#if- (and- (not this.expandedFirstPost.isResolved) @post.expandablePost+ (if+ @post.group_moderator+ "post--category-moderator category-moderator")- }}- <DButton- class="post__expand-button expand-post"- @action={{this.expandFirstPost}}- @translatedLabel={{if- this.expandedFirstPost.isPending- (i18n "loading")- (concat (i18n "post.show_full") "...")- }}- />- {{/if}}-- <section class="post__menu-area post-menu-area clearfix">- <PostMenu- @post={{@post}}- @prevPost={{@prevPost}}- @nextPost={{@nextPost}}- @canCreatePost={{@canCreatePost}}- @changeNotice={{@changeNotice}}- @changePostOwner={{@changePostOwner}}- @copyLink={{this.copyLink}}- @deletePost={{@deletePost}}- @editPost={{@editPost}}- @filteredRepliesView={{this.filteredRepliesView}}- @grantBadge={{@grantBadge}}- @lockPost={{@lockPost}}- @permanentlyDeletePost={{@permanentlyDeletePost}}- @rebakePost={{@rebakePost}}- @recoverPost={{@recoverPost}}- @repliesShown={{this.repliesShown}}- @replyToPost={{@replyToPost}}- @share={{this.share}}- @showFlags={{@showFlags}}- @showLogin={{@showLogin}}- @showPagePublish={{@showPagePublish}}- @showReadIndicator={{@showReadIndicator}}- @toggleLike={{this.toggleLike}}- @togglePostType={{@togglePostType}}- @toggleReplies={{this.toggleReplies}}- @toggleWiki={{@toggleWiki}}- @unhidePost={{@unhidePost}}- @unlockPost={{@unlockPost}}- />- </section>-- {{#if this.repliesBelow}}+ (if @post.hidden "post--hidden post-hidden")+ (if @post.deleted "post--deleted deleted")+ (if+ @post.primary_group_name+ (concatClass+ (concat "post--group-" @post.primary_group_name)+ (concat "group-" @post.primary_group_name)+ )+ )+ (if @post.wiki "post--wiki wiki")+ (if @post.isWhisper "post--whisper whisper")+ (if+ (or+ @post.isModeratorAction+ (and @post.isWarning @post.firstPost)+ )+ "post--moderator moderator"+ "post--regular regular"+ )+ (if @post.user_suspended "post--user-suspended user-suspended")+ this.additionalClasses+ )+ parentSelector="div"+ }}+ ...attributes+ id={{this.id}}+ class={{concatClass+ "boxed"+ "onscreen-post"+ (if this.hasRepliesAbove "post--has-replies-above replies-above")+ (if+ @post.is_auto_generated "post--auto-generated is-auto-generated"+ )+ (if @post.via_email "post--via-email via-email")+ }}+ aria-label={{i18n+ "share.post"+ (hash [email protected]_number [email protected])+ }}+ role="region"+ data-post-id={{@post.id}}+ data-topic-id={{@post.topicId}}+ data-user-id={{@post.user_id}}+ >+ {{#if this.hasRepliesAbove}}+ <div class="post__row row"><section- id={{concat "embedded-posts__bottom--" @post.post_number}}- class="post__embedded-posts post__embedded-posts--bottom embedded-posts bottom"+ id={{concat "embedded-posts__top--" @post.post_number}}+ class="post__embedded-posts post__embedded-posts--top post__body embedded-posts top topic-body">- {{#each this.repliesBelow key="id" as |reply|}}+ <DButton+ class="post__collapse-button post__collapse-button-down collapse-down"+ @action={{this.toggleReplyAbove}}+ @icon="chevron-down"+ @title="post.collapse"+ />+ {{#each this.repliesAbove.value key="id" as |reply|}}<PostEmbedded- role="region"- aria-label={{i18n- "post.sr_embedded_reply_description"- [email protected]_number- username=reply.username- }}@post={{reply}}+ @above={{true}}@highlightTerm={{this.search.highlightTerm}}/>{{/each}}-- <DButton- class="post__collapse-button post__collapse-button-up collapse-up"- @action={{this.toggleRepliesBelow}}- @ariaLabel="post.sr_collapse_replies"- @icon="chevron-up"- @title="post.collapse"+ </section>+ </div>+ {{/if}}+ {{#if (and (not @post.deletedAt) @post.notice)}}+ <div class="post__row row">+ <PostNotice @post={{@post}} />+ </div>+ {{/if}}+ <div class="post__row row">+ <PostAvatar @post={{@post}} />+ <div class="post__body topic-body clearfix">+ <PluginOutlet+ @name="post-metadata"+ @outletArgs={{postOutletArgs}}+ >+ <PostMetaData+ @post={{@post}}+ @editPost={{@editPost}}+ @hasRepliesAbove={{this.hasRepliesAbove}}+ @isReplyingDirectlyToPostAbove={{this.isReplyingDirectlyToPostAbove}}+ @multiSelect={{@multiSelect}}+ @repliesAbove={{this.repliesAbove}}+ @selectBelow={{@selectBelow}}+ @selectReplies={{@selectReplies}}+ @selected={{@selected}}+ @showHistory={{@showHistory}}+ @showRawEmail={{@showRawEmail}}+ @togglePostSelection={{@togglePostSelection}}+ @toggleReplyAbove={{this.toggleReplyAbove}}/>+ </PluginOutlet>+ <div+ class={{concatClass+ "post__regular regular"+ (unless this.repliesShown "post__contents contents")+ (if+ this.isReplyToTabDisplayed+ "post__contents--avoid-tab avoid-tab"+ )+ }}+ >+ <PluginOutlet+ @name="post-content-cooked-html"+ @outletArgs={{postOutletArgs}}+ >+ <PostCookedHtml+ @post={{@post}}+ @highlightTerm={{this.search.highlightTerm}}+ />+ </PluginOutlet>++ {{#if @post.requestedGroupName}}+ <div class="post__group-request group-request">+ <a href={{this.groupRequestUrl}}>+ {{i18n "groups.requests.handle"}}+ </a>+ </div>+ {{/if}}- {{#if this.canLoadMoreRepliesBelow}}+ {{#if (and @post.cooked_hidden @post.can_see_hidden_post)}}+ {{! template-lint-disable no-invalid-interactive }}+ <a+ class="post__expand-hidden expand-hidden"+ {{on "click" @expandHidden}}+ >+ {{i18n "post.show_hidden"}}+ </a>+ {{/if}}++ {{#if+ (and+ (not this.expandedFirstPost.isResolved)+ @post.expandablePost+ )+ }}<DButton- class="post__load-more load-more-replies"- @label="post.load_more_replies"- @action={{this.loadMoreReplies}}+ class="post__expand-button expand-post"+ @action={{this.expandFirstPost}}+ @translatedLabel={{if+ this.expandedFirstPost.isPending+ (i18n "loading")+ (concat (i18n "post.show_full") "...")+ }}/>{{/if}}++ <section class="post__menu-area post-menu-area clearfix">+ <PostMenu+ @post={{@post}}+ @prevPost={{@prevPost}}+ @nextPost={{@nextPost}}+ @canCreatePost={{@canCreatePost}}+ @changeNotice={{@changeNotice}}+ @changePostOwner={{@changePostOwner}}+ @copyLink={{this.copyLink}}+ @deletePost={{@deletePost}}+ @editPost={{@editPost}}+ @filteredRepliesView={{this.filteredRepliesView}}+ @grantBadge={{@grantBadge}}+ @lockPost={{@lockPost}}+ @permanentlyDeletePost={{@permanentlyDeletePost}}+ @rebakePost={{@rebakePost}}+ @recoverPost={{@recoverPost}}+ @repliesShown={{this.repliesShown}}+ @replyToPost={{@replyToPost}}+ @share={{this.share}}+ @showFlags={{@showFlags}}+ @showLogin={{@showLogin}}+ @showPagePublish={{@showPagePublish}}+ @showReadIndicator={{@showReadIndicator}}+ @toggleLike={{this.toggleLike}}+ @togglePostType={{@togglePostType}}+ @toggleReplies={{this.toggleReplies}}+ @toggleWiki={{@toggleWiki}}+ @unhidePost={{@unhidePost}}+ @unlockPost={{@unlockPost}}+ />+ </section>++ {{#if this.repliesBelow}}+ <section+ id={{concat "embedded-posts__bottom--" @post.post_number}}+ class="post__embedded-posts post__embedded-posts--bottom embedded-posts bottom"+ >+ {{#each this.repliesBelow key="id" as |reply|}}+ <PostEmbedded+ role="region"+ aria-label={{i18n+ "post.sr_embedded_reply_description"+ [email protected]_number+ username=reply.username+ }}+ @post={{reply}}+ @highlightTerm={{this.search.highlightTerm}}+ />+ {{/each}}++ <DButton+ class="post__collapse-button post__collapse-button-up collapse-up"+ @action={{this.toggleRepliesBelow}}+ @ariaLabel="post.sr_collapse_replies"+ @icon="chevron-up"+ @title="post.collapse"+ />++ {{#if this.canLoadMoreRepliesBelow}}+ <DButton+ class="post__load-more load-more-replies"+ @label="post.load_more_replies"+ @action={{this.loadMoreReplies}}+ />+ {{/if}}+ </section>+ {{/if}}+ </div>++ <section class="post__actions post-actions">+ <PostActionsSummary @post={{@post}} /></section>- {{/if}}+ <PostLinks @post={{@post}} />+ </div></div>-- <section class="post__actions post-actions">- <PostActionsSummary @post={{@post}} />- </section>- <PostLinks @post={{@post}} />- </div>- </div>- {{#if this.shouldShowTopicMap}}- <div class="post__topic-map topic-map --op">- <TopicMap- @model={{@post.topic}}- @cancelFilter={{@cancelFilter}}- @topicDetails={{@post.topic.details}}- @postStream={{@post.topic.postStream}}- @showPMMap={{eq @post.topic.archetype "private_message"}}- @showInvite={{@showInvite}}- @removeAllowedGroup={{@removeAllowedGroup}}- @removeAllowedUser={{@removeAllowedUser}}- />- </div>- {{/if}}- </article>+ {{#if this.shouldShowTopicMap}}+ <div class="post__topic-map topic-map --op">+ <TopicMap+ @model={{@post.topic}}+ @cancelFilter={{@cancelFilter}}+ @topicDetails={{@post.topic.details}}+ @postStream={{@post.topic.postStream}}+ @showPMMap={{eq @post.topic.archetype "private_message"}}+ @showInvite={{@showInvite}}+ @removeAllowedGroup={{@removeAllowedGroup}}+ @removeAllowedUser={{@removeAllowedUser}}+ />+ </div>+ {{/if}}+ </article>+ </PluginOutlet>+ {{/let}}{{/if}}</template>}diff --git a/app/assets/javascripts/discourse/app/components/post/avatar.gjs b/app/assets/javascripts/discourse/app/components/post/avatar.gjsindex 5d5b4cb815e..3ec7a6b72b8 100644--- a/app/assets/javascripts/discourse/app/components/post/avatar.gjs+++ b/app/assets/javascripts/discourse/app/components/post/avatar.gjs@@ -1,13 +1,11 @@import Component from "@glimmer/component";+import { hash } from "@ember/helper";+import PluginOutlet from "discourse/components/plugin-outlet";import UserAvatar from "discourse/components/user-avatar";import UserAvatarFlair from "discourse/components/user-avatar-flair";import icon from "discourse/helpers/d-icon";export default class PostAvatar extends Component {- get userWasDeleted() {- return !this.args.post.user_id;- }-get size() {return this.args.size || "large";}@@ -21,26 +19,40 @@ export default class PostAvatar extends Component {};}+ get userWasDeleted() {+ return !this.args.post.user_id;+ }+<template><div class="topic-avatar">- <div class="post-avatar">- {{#if this.userWasDeleted}}- {{icon "trash-can" class="deleted-user-avatar"}}- {{else}}- <UserAvatar- tabindex="-1"- @hideTitle={{true}}- @lazy={{true}}- @avatarClasses="main-avatar"- @size={{this.size}}- @user={{this.user}}- />- <UserAvatarFlair @user={{@post}} />- {{/if}}- {{#if @displayPosterName}}- <div class="post-avatar-user-info"></div>- {{/if}}- </div>+ <PluginOutlet+ @name="post-avatar"+ @outletArgs={{hash+ post=@post+ size=this.size+ user=this.user+ userWasDeleted=this.userWasDeleted+ }}+ >+ <div class="post-avatar">+ {{#if this.userWasDeleted}}+ {{icon "trash-can" class="deleted-user-avatar"}}+ {{else}}+ <UserAvatar+ tabindex="-1"+ @hideTitle={{true}}+ @lazy={{true}}+ @avatarClasses="main-avatar"+ @size={{this.size}}+ @user={{this.user}}+ />+ <UserAvatarFlair @user={{@post}} />+ {{/if}}+ {{#if @displayPosterName}}+ <div class="post-avatar-user-info"></div>+ {{/if}}+ </div>+ </PluginOutlet></div></template>}diff --git a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.jsindex 7992c214814..d1285e76221 100644--- a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js+++ b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js@@ -56,7 +56,8 @@ export default class ScrollingPostStream extends MountWidget {"showReadIndicator","streamFilters","lastReadPostNumber",- "highestPostNumber"+ "highestPostNumber",+ "topicPageQueryParams");}diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjsindex 0e0897cdb14..39fbc03fdcb 100644--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs@@ -867,6 +867,11 @@ class PluginApi {}/**+ * @deprecated+ *+ * This function is now an alias to `api.addTrackedPostProperties`.+ * Use that function instead.+ ** Add more attributes to the Post's `attrs` object passed through to widgets.* You'll need to do this if you've added attributes to the serializer for a* Post and want to use them when you're rendering.@@ -880,7 +885,15 @@ class PluginApi {***/includePostAttributes(...attributes) {- includeAttributes(...attributes);+ // TODO (glimmer-post-stream): we can keep this function as an alias to addTrackedPostProperties but it is useful to+ // deprecate it for now to get warnings for code that is incompatible with the Glimmer Post Stream because if an+ // extension is using it, then it is very likely that there is other code that is incompatible+ deprecated(+ "`api.includePostAttributes` has been deprecated. Use `api.addTrackedPostProperties` instead.",+ POST_STREAM_DEPRECATION_OPTIONS+ );++ this.addTrackedPostProperties(...attributes);}/**diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.jsindex de5f984762f..95b970b7a60 100644--- a/app/assets/javascripts/discourse/app/models/post.js+++ b/app/assets/javascripts/discourse/app/models/post.js@@ -396,6 +396,13 @@ export default class Post extends RestModel {return this.post_type === this.site.post_types.moderator_action;}+ get isSmallAction() {+ return (+ this.post_type === this.site.post_types.small_action ||+ this.action_code === "split_topic"+ );+ }+get liked() {return !!this.likeAction?.get("acted");}diff --git a/app/assets/javascripts/discourse/app/templates/topic.gjs b/app/assets/javascripts/discourse/app/templates/topic.gjsindex 544417a7a03..d123027f4cb 100644--- a/app/assets/javascripts/discourse/app/templates/topic.gjs+++ b/app/assets/javascripts/discourse/app/templates/topic.gjs@@ -1,5 +1,6 @@import { array, concat, fn, hash } from "@ember/helper";import { on } from "@ember/modifier";+import { getProperties } from "@ember/object";import { LinkTo } from "@ember/routing";import RouteTemplate from "ember-route-template";import { and, eq } from "truth-helpers";@@ -482,6 +483,10 @@ export default RouteTemplate(@showPagePublish={{routeAction "showPagePublish"}}@filteringRepliesToPostNumber={{@controller.replies_to_post_number}}@updateTopicPageQueryParams={{@controller.updateTopicPageQueryParams}}+ @topicPageQueryParams={{getProperties+ @controller+ @controller.queryParams+ }}/>{{/unless}}diff --git a/app/assets/javascripts/discourse/app/widgets/post-stream.js b/app/assets/javascripts/discourse/app/widgets/post-stream.jsindex c8f7ec89fff..66141a7ff13 100644--- a/app/assets/javascripts/discourse/app/widgets/post-stream.js+++ b/app/assets/javascripts/discourse/app/widgets/post-stream.js@@ -392,6 +392,7 @@ export default createWidget("post-stream", {toggleReplyAbove: () =>this.sendWidgetAction("toggleReplyAbove", post),toggleWiki: () => this.sendWidgetAction("toggleWiki", post),+ topicPageQueryParams: attrs.topicPageQueryParams,unhidePost: () => this.sendWidgetAction("unhidePost", post),unlockPost: () => this.sendWidgetAction("unlockPost", post),updateTopicPageQueryParams: () =>diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.jsindex 2515247328b..54d4a313706 100644--- a/app/assets/javascripts/discourse/app/widgets/post.js+++ b/app/assets/javascripts/discourse/app/widgets/post.js@@ -1219,6 +1219,7 @@ registerWidgetShim(@toggleReplies={{@toggleReplies}}@toggleReplyAbove={{@data.toggleReplyAbove}}@toggleWiki={{@data.toggleWiki}}+ @topicPageQueryParams={{@data.topicPageQueryParams}}@unhidePost={{@data.unhidePost}}@unlockPost={{@data.unlockPost}}@updateTopicPageQueryParams={{@data.updateTopicPageQueryParams}}