FIX: do not show user status on posts twice (#18458)

This commit is contained in:
Andrei Prigorshnev 2022-10-04 10:35:27 +04:00 committed by GitHub
parent ba2c5c7948
commit fe12817cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 14 deletions

View File

@ -122,7 +122,9 @@ export default createWidget("poster-name", {
} }
} }
const afterNameContents = this.afterNameContents(attrs); const afterNameContents =
applyDecorators(this, "after-name", attrs, this.state) || [];
nameContents = nameContents.concat(afterNameContents); nameContents = nameContents.concat(afterNameContents);
const contents = [ const contents = [
@ -160,19 +162,16 @@ export default createWidget("poster-name", {
); );
} }
if (this.siteSettings.enable_user_status) {
this.addUserStatus(contents, attrs);
}
return contents; return contents;
}, },
afterNameContents(attrs) { addUserStatus(contents, attrs) {
const contents = []; if (attrs.user && attrs.user.status) {
if (
this.siteSettings.enable_user_status &&
attrs.user &&
attrs.user.status
) {
contents.push(this.attach("post-user-status", attrs.user.status)); contents.push(this.attach("post-user-status", attrs.user.status));
} }
contents.push(...applyDecorators(this, "after-name", attrs, this.state));
return contents;
}, },
}); });

View File

@ -19,6 +19,10 @@ acceptance("Topic - User Status", function (needs) {
const response = cloneJSON(TopicFixtures["/t/299/1.json"]); const response = cloneJSON(TopicFixtures["/t/299/1.json"]);
response.post_stream.posts.forEach((post) => { response.post_stream.posts.forEach((post) => {
post.user_status = status; post.user_status = status;
// we need the poster's name to be different from username
// so when display_name_on_posts = true, both name and username will be shown:
post.name = "Evil T";
}); });
return helper.response(200, response); return helper.response(200, response);
@ -35,6 +39,19 @@ acceptance("Topic - User Status", function (needs) {
"all posts has user status" "all posts has user status"
); );
}); });
test("shows user status next to avatar on posts when displaying names on posts is enabled", async function (assert) {
this.siteSettings.enable_user_status = true;
this.siteSettings.display_name_on_posts = true;
await visit("/t/-/299/1");
assert.equal(
queryAll(".topic-post .user-status-message").length,
3,
"all posts has user status"
);
});
}); });
acceptance("Topic - User Status - live updates", function (needs) { acceptance("Topic - User Status - live updates", function (needs) {

View File

@ -78,10 +78,6 @@ $quote-share-maxwidth: 150px;
.user-title a { .user-title a {
color: var(--primary-med-or-secondary-med); color: var(--primary-med-or-secondary-med);
} }
.user-status-message {
margin-left: 0.3em;
}
} }
// global styles for the cooked HTML content in posts (and preview) // global styles for the cooked HTML content in posts (and preview)