REFACTOR: Remove `Discourse.SiteSettings` from topic tracking state

This commit is contained in:
Robin Ward 2020-07-21 11:58:28 -04:00
parent f6c40075e5
commit 531793e98f
2 changed files with 11 additions and 4 deletions

View File

@ -27,14 +27,14 @@ function isUnseen(topic) {
return !topic.is_seen;
}
function hasMutedTags(topicTagIds, mutedTagIds) {
function hasMutedTags(topicTagIds, mutedTagIds, siteSettings) {
if (!mutedTagIds || !topicTagIds) {
return false;
}
return (
(Discourse.SiteSettings.remove_muted_tags_from_latest === "always" &&
(siteSettings.remove_muted_tags_from_latest === "always" &&
topicTagIds.any(tagId => mutedTagIds.includes(tagId))) ||
(Discourse.SiteSettings.remove_muted_tags_from_latest === "only_muted" &&
(siteSettings.remove_muted_tags_from_latest === "only_muted" &&
topicTagIds.every(tagId => mutedTagIds.includes(tagId)))
);
}
@ -81,7 +81,13 @@ const TopicTrackingState = EmberObject.extend({
if (["new_topic", "latest"].includes(data.message_type)) {
const mutedTagIds = User.currentProp("muted_tag_ids");
if (hasMutedTags(data.payload.topic_tag_ids, mutedTagIds)) {
if (
hasMutedTags(
data.payload.topic_tag_ids,
mutedTagIds,
this.siteSettings
)
) {
return;
}
}

View File

@ -47,6 +47,7 @@ export default {
const topicTrackingState = TopicTrackingState.create({
messageBus: MessageBus,
siteSettings,
currentUser
});
app.register("topic-tracking-state:main", topicTrackingState, {