mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-25 06:11:20 -04:00
FIX: don't show new topic notifications in homepag for suppressed categories
This commit is contained in:
parent
7516643f11
commit
80041b874c
3 changed files with 61 additions and 55 deletions
|
@ -1,4 +1,6 @@
|
|||
import NotificationLevels from 'discourse/lib/notification-levels';
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { on } from "ember-addons/ember-computed-decorators";
|
||||
|
||||
function isNew(topic) {
|
||||
return topic.last_read_post_number === null &&
|
||||
|
@ -15,24 +17,25 @@ function isUnread(topic) {
|
|||
const TopicTrackingState = Discourse.Model.extend({
|
||||
messageCount: 0,
|
||||
|
||||
_setup: function() {
|
||||
@on("init")
|
||||
_setup() {
|
||||
this.unreadSequence = [];
|
||||
this.newSequence = [];
|
||||
this.states = {};
|
||||
}.on('init'),
|
||||
},
|
||||
|
||||
establishChannels() {
|
||||
const tracker = this;
|
||||
|
||||
const process = function(data){
|
||||
const process = data => {
|
||||
if (data.message_type === "delete") {
|
||||
tracker.removeTopic(data.topic_id);
|
||||
tracker.incrementMessageCount();
|
||||
}
|
||||
|
||||
if (data.message_type === "new_topic" || data.message_type === "latest") {
|
||||
const ignored_categories = Discourse.User.currentProp("muted_category_ids");
|
||||
if(_.include(ignored_categories, data.payload.category_id)){
|
||||
const muted_category_ids = Discourse.User.currentProp("muted_category_ids");
|
||||
if (_.include(muted_category_ids, data.payload.category_id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +76,13 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
|
||||
const filter = this.get("filter");
|
||||
|
||||
if (filter === Discourse.Utilities.defaultHomepage()) {
|
||||
const suppressed_from_homepage_category_ids = Discourse.Site.currentProp("suppressed_from_homepage_category_ids");
|
||||
if (_.include(suppressed_from_homepage_category_ids, data.payload.category_id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((filter === "all" || filter === "latest" || filter === "new") && data.message_type === "new_topic") {
|
||||
this.addIncoming(data.topic_id);
|
||||
}
|
||||
|
@ -109,10 +119,10 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
this.set("incomingCount", 0);
|
||||
},
|
||||
|
||||
hasIncoming: function(){
|
||||
const count = this.get('incomingCount');
|
||||
return count && count > 0;
|
||||
}.property('incomingCount'),
|
||||
@computed("incomingCount")
|
||||
hasIncoming(incomingCount) {
|
||||
return incomingCount && incomingCount > 0;
|
||||
},
|
||||
|
||||
removeTopic(topic_id) {
|
||||
delete this.states["t" + topic_id];
|
||||
|
@ -124,7 +134,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
if (Em.isEmpty(topics)) { return; }
|
||||
|
||||
const states = this.states;
|
||||
topics.forEach(function(t) {
|
||||
topics.forEach(t => {
|
||||
const state = states['t' + t.get('id')];
|
||||
|
||||
if (state) {
|
||||
|
@ -135,9 +145,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
unread = postsCount - state.last_read_post_number;
|
||||
|
||||
if (newPosts < 0) { newPosts = 0; }
|
||||
if (!state.last_read_post_number) {
|
||||
unread = 0;
|
||||
}
|
||||
if (!state.last_read_post_number) { unread = 0; }
|
||||
if (unread < 0) { unread = 0; }
|
||||
|
||||
t.setProperties({
|
||||
|
@ -201,11 +209,9 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
if ((filter === "new" || filter === "unread") && !list.more_topics_url) {
|
||||
|
||||
const ids = {};
|
||||
list.topics.forEach(function(r){
|
||||
ids["t" + r.id] = true;
|
||||
});
|
||||
list.topics.forEach(r => ids["t" + r.id] = true);
|
||||
|
||||
_.each(tracker.states, function(v, k){
|
||||
_.each(tracker.states, (v, k) => {
|
||||
|
||||
// we are good if we are on the list
|
||||
if (ids[k]) { return; }
|
||||
|
@ -232,7 +238,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
countNew(category_id) {
|
||||
return _.chain(this.states)
|
||||
.where(isNew)
|
||||
.where(function(topic){ return topic.category_id === category_id || !category_id;})
|
||||
.where(topic => topic.category_id === category_id || !category_id)
|
||||
.value()
|
||||
.length;
|
||||
},
|
||||
|
@ -242,10 +248,9 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
resetNew() {
|
||||
const self = this;
|
||||
Object.keys(this.states).forEach(function (id) {
|
||||
if (self.states[id].last_read_post_number === null) {
|
||||
delete self.states[id];
|
||||
Object.keys(this.states).forEach(id => {
|
||||
if (this.states[id].last_read_post_number === null) {
|
||||
delete this.states[id];
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -253,7 +258,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
countUnread(category_id) {
|
||||
return _.chain(this.states)
|
||||
.where(isUnread)
|
||||
.where(function(topic){ return topic.category_id === category_id || !category_id;})
|
||||
.where(topic => topic.category_id === category_id || !category_id)
|
||||
.value()
|
||||
.length;
|
||||
},
|
||||
|
@ -270,7 +275,6 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
lookupCount(name, category) {
|
||||
|
||||
if (name === "latest") {
|
||||
return this.lookupCount("new", category) +
|
||||
this.lookupCount("unread", category);
|
||||
|
@ -290,21 +294,17 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
loadStates(data) {
|
||||
// not exposed
|
||||
const states = this.states;
|
||||
|
||||
if (data) {
|
||||
_.each(data,function(topic){
|
||||
states["t" + topic.topic_id] = topic;
|
||||
});
|
||||
_.each(data,topic => states["t" + topic.topic_id] = topic);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
TopicTrackingState.reopenClass({
|
||||
createFromStates(data) {
|
||||
|
||||
createFromStates(data) {
|
||||
// TODO: This should be a model that does injection automatically
|
||||
const container = Discourse.__container__,
|
||||
messageBus = container.lookup('message-bus:main'),
|
||||
|
@ -316,6 +316,7 @@ TopicTrackingState.reopenClass({
|
|||
instance.establishChannels();
|
||||
return instance;
|
||||
},
|
||||
|
||||
current() {
|
||||
if (!this.tracker) {
|
||||
const data = PreloadStore.get('topicTrackingStates');
|
||||
|
|
|
@ -71,6 +71,10 @@ class Site
|
|||
end
|
||||
end
|
||||
|
||||
def suppressed_from_homepage_category_ids
|
||||
categories.select { |c| c.suppress_from_homepage == true }.map(&:id)
|
||||
end
|
||||
|
||||
def archetypes
|
||||
Archetype.list.reject { |t| t.id == Archetype.private_message }
|
||||
end
|
||||
|
|
|
@ -11,7 +11,8 @@ class SiteSerializer < ApplicationSerializer
|
|||
:uncategorized_category_id, # this is hidden so putting it here
|
||||
:is_readonly,
|
||||
:disabled_plugins,
|
||||
:user_field_max_length
|
||||
:user_field_max_length,
|
||||
:suppressed_from_homepage_category_ids
|
||||
|
||||
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
|
||||
has_many :post_action_types, embed: :objects
|
||||
|
|
Loading…
Add table
Reference in a new issue