mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Hide post replies content for ignored users (#7320)
This commit is contained in:
parent
9c2e6b9a54
commit
131eba0366
@ -80,7 +80,6 @@ export function transformBasicPost(post) {
|
|||||||
expandablePost: false,
|
expandablePost: false,
|
||||||
replyCount: post.reply_count,
|
replyCount: post.reply_count,
|
||||||
locked: post.locked,
|
locked: post.locked,
|
||||||
ignored: post.ignored,
|
|
||||||
userCustomFields: post.user_custom_fields
|
userCustomFields: post.user_custom_fields
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -619,6 +619,15 @@ const User = RestModel.extend({
|
|||||||
return ajax(`${userPath(this.get("username"))}/notification_level.json`, {
|
return ajax(`${userPath(this.get("username"))}/notification_level.json`, {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { notification_level: level, expiring_at: expiringAt }
|
data: { notification_level: level, expiring_at: expiringAt }
|
||||||
|
}).then(() => {
|
||||||
|
const currentUser = Discourse.User.current();
|
||||||
|
if (currentUser) {
|
||||||
|
if (level === "normal" || level === "mute") {
|
||||||
|
currentUser.ignored_users.removeObject(this.get("username"));
|
||||||
|
} else if (level === "ignore") {
|
||||||
|
currentUser.ignored_users.addObject(this.get("username"));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ export default class PostCooked {
|
|||||||
this.expanding = false;
|
this.expanding = false;
|
||||||
this._highlighted = false;
|
this._highlighted = false;
|
||||||
this.decoratorHelper = decoratorHelper;
|
this.decoratorHelper = decoratorHelper;
|
||||||
|
this.currentUser = decoratorHelper.widget.currentUser;
|
||||||
|
this.ignoredUsers = this.currentUser ? this.currentUser.ignored_users : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(prev) {
|
update(prev) {
|
||||||
@ -29,7 +31,7 @@ export default class PostCooked {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
const $html = $(`<div class='cooked'>${this.attrs.cooked}</div>`);
|
const $html = this._computeCooked();
|
||||||
this._insertQuoteControls($html);
|
this._insertQuoteControls($html);
|
||||||
this._showLinkCounts($html);
|
this._showLinkCounts($html);
|
||||||
this._fixImageSizes($html);
|
this._fixImageSizes($html);
|
||||||
@ -212,6 +214,16 @@ export default class PostCooked {
|
|||||||
expandContract = iconHTML(desc, { title: "post.expand_collapse" });
|
expandContract = iconHTML(desc, { title: "post.expand_collapse" });
|
||||||
$(".title", $aside).css("cursor", "pointer");
|
$(".title", $aside).css("cursor", "pointer");
|
||||||
}
|
}
|
||||||
|
if (this.ignoredUsers && this.ignoredUsers.length > 0) {
|
||||||
|
const username = $aside
|
||||||
|
.find(".title")
|
||||||
|
.text()
|
||||||
|
.trim()
|
||||||
|
.slice(0, -1);
|
||||||
|
if (username.length > 0 && this.ignoredUsers.includes(username)) {
|
||||||
|
$aside.find("p").replaceWith(`<i>${I18n.t("post.ignored")}</i>`);
|
||||||
|
}
|
||||||
|
}
|
||||||
$(".quote-controls", $aside).html(expandContract + navLink);
|
$(".quote-controls", $aside).html(expandContract + navLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +253,20 @@ export default class PostCooked {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_computeCooked() {
|
||||||
|
if (
|
||||||
|
this.ignoredUsers &&
|
||||||
|
this.ignoredUsers.length > 0 &&
|
||||||
|
this.ignoredUsers.includes(this.attrs.username)
|
||||||
|
) {
|
||||||
|
return $(
|
||||||
|
`<div class='cooked post-ignored'>${I18n.t("post.ignored")}</div>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $(`<div class='cooked'>${this.attrs.cooked}</div>`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PostCooked.prototype.type = "Widget";
|
PostCooked.prototype.type = "Widget";
|
||||||
|
@ -657,7 +657,12 @@ export default createWidget("post", {
|
|||||||
} else {
|
} else {
|
||||||
classNames.push("regular");
|
classNames.push("regular");
|
||||||
}
|
}
|
||||||
if (attrs.ignored) {
|
if (
|
||||||
|
this.currentUser &&
|
||||||
|
this.currentUser.ignored_users &&
|
||||||
|
this.currentUser.ignored_users.length > 0 &&
|
||||||
|
this.currentUser.ignored_users.includes(attrs.username)
|
||||||
|
) {
|
||||||
classNames.push("post-ignored");
|
classNames.push("post-ignored");
|
||||||
}
|
}
|
||||||
if (addPostClassesCallbacks) {
|
if (addPostClassesCallbacks) {
|
||||||
|
@ -6,8 +6,7 @@ class BasicPostSerializer < ApplicationSerializer
|
|||||||
:avatar_template,
|
:avatar_template,
|
||||||
:created_at,
|
:created_at,
|
||||||
:cooked,
|
:cooked,
|
||||||
:cooked_hidden,
|
:cooked_hidden
|
||||||
:ignored
|
|
||||||
|
|
||||||
def name
|
def name
|
||||||
object.user && object.user.name
|
object.user && object.user.name
|
||||||
@ -36,21 +35,11 @@ class BasicPostSerializer < ApplicationSerializer
|
|||||||
else
|
else
|
||||||
I18n.t('flagging.user_must_edit')
|
I18n.t('flagging.user_must_edit')
|
||||||
end
|
end
|
||||||
elsif ignored
|
|
||||||
I18n.t('ignored.hidden_content')
|
|
||||||
else
|
else
|
||||||
object.filter_quotes(@parent_post)
|
object.filter_quotes(@parent_post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored
|
|
||||||
return false unless SiteSetting.ignore_user_enabled?
|
|
||||||
object.is_first_post? &&
|
|
||||||
scope.current_user&.id != object.user_id &&
|
|
||||||
IgnoredUser.where(user_id: scope.current_user&.id,
|
|
||||||
ignored_user_id: object.user_id).exists?
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_name?
|
def include_name?
|
||||||
SiteSetting.enable_names?
|
SiteSetting.enable_names?
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
:top_category_ids,
|
:top_category_ids,
|
||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:groups,
|
:groups,
|
||||||
:second_factor_enabled
|
:second_factor_enabled,
|
||||||
|
:ignored_users
|
||||||
|
|
||||||
def groups
|
def groups
|
||||||
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
||||||
@ -157,6 +158,10 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
CategoryUser.lookup(object, :muted).pluck(:category_id)
|
CategoryUser.lookup(object, :muted).pluck(:category_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ignored_users
|
||||||
|
IgnoredUser.where(user: object.id).joins(:ignored_user).pluck(:username)
|
||||||
|
end
|
||||||
|
|
||||||
def top_category_ids
|
def top_category_ids
|
||||||
omitted_notification_levels = [CategoryUser.notification_levels[:muted], CategoryUser.notification_levels[:regular]]
|
omitted_notification_levels = [CategoryUser.notification_levels[:muted], CategoryUser.notification_levels[:regular]]
|
||||||
CategoryUser.where(user_id: object.id)
|
CategoryUser.where(user_id: object.id)
|
||||||
|
@ -2247,6 +2247,7 @@ en:
|
|||||||
quote_reply: "Quote"
|
quote_reply: "Quote"
|
||||||
edit_reason: "Reason: "
|
edit_reason: "Reason: "
|
||||||
post_number: "post {{number}}"
|
post_number: "post {{number}}"
|
||||||
|
ignored: "Hidden content"
|
||||||
wiki_last_edited_on: "wiki last edited on"
|
wiki_last_edited_on: "wiki last edited on"
|
||||||
last_edited_on: "post last edited on"
|
last_edited_on: "post last edited on"
|
||||||
reply_as_new_topic: "Reply as linked Topic"
|
reply_as_new_topic: "Reply as linked Topic"
|
||||||
|
@ -10,7 +10,7 @@ RSpec.describe WebHookPostSerializer do
|
|||||||
|
|
||||||
it 'should only include the required keys' do
|
it 'should only include the required keys' do
|
||||||
count = serialized_for_user(admin).keys.count
|
count = serialized_for_user(admin).keys.count
|
||||||
difference = count - 35
|
difference = count - 34
|
||||||
|
|
||||||
expect(difference).to eq(0), lambda {
|
expect(difference).to eq(0), lambda {
|
||||||
message = ""
|
message = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user