צריך עזרה במציאת הסיבה לרשימת נושאים שלא מתעדכנת לאחר לחיצה על התראה של נושא חדש/תגובה

When you do something like this

this.topics = something_else

You’re redefining that property to something else. This is fine if nothing else is watching that property, but in this case, several things are watching the topics array.

For example

If you do this on a development installation, Ember will throw errors in the console like so.

.

So, the key takeaway here is to do something like this instead.

this.set("topics", something_else)

until the @tracked decorator lands in Discourse.

So, if you try something like this

api.modifyClass("component:topic-list", {
  @on("didReceiveAttrs")
  removeIgnoredUsers() {
    const filtered = this.topics.filter(
      topic => !ignored.includes(topic.posters[0].user.username)
    );
    this.set("topics", filtered);
  }
});

It should work on both desktop and mobile on theme creator.

However…

If you try that on development installation, you’ll see another error.

So this should tell you something. The topics array is being used in many different places. So it’s not a good idea to muck around with it - especially since your use case is primarily visual and there are no security implications involved.

Here’s what I suggest: Take a step back and try a different approach. Instead of trying to modify the array, do something much simpler. If an ignored user created the topic, add a CSS class and hide it with CSS.

You do that with something like this - I left some comments if you want to follow along but you can delete them when you’re ready to use it.

This goes in the initilizer file:

import { apiInitializer } from "discourse/lib/api";
import discourseComputed from "discourse-common/utils/decorators";

export default apiInitializer("0.11.1", api => {
  // set an id for your modifications
  const PLUGIN_ID = "hide-ignored-op-topics";

  // The class name you want to add. The space at the start is required
  const IGNORED_TOPIC_CLASS_STRING = " ignored-op-topic";

  // get current user
  const user = api.getCurrentUser();

  // not logged in, bail
  if (!user) {
    return;
  }

  // get a list of ignored users
  const ignored = user.ignored_users;

  // helper function to avoid duplicating code
  const addIgnoredTopicClass = context => {
    // get classes from core / other plugins and themes
    let classList = context._super(...arguments);

    // create your condition
    const shouldAddClass = ignored.includes(
      context.topic.posters[0].user.username
    );

    // add ignored class if condition is true
    if (shouldAddClass) {
      classList += IGNORED_TOPIC_CLASS_STRING;
    }

    // return the classList plus the modifications if any
    return classList;
  };

  // add the class to the default topic list like on the "latest" page
  api.modifyClass("component:topic-list-item", {
    pluginId: PLUGIN_ID,
    @discourseComputed()
    unboundClassNames() {
      return addIgnoredTopicClass(this);
    }
  });

  // do the same for the categories page topic list
  api.modifyClass("component:latest-topic-list-item", {
    pluginId: PLUGIN_ID,
    @discourseComputed()
    unboundClassNames() {
      return addIgnoredTopicClass(this);
    }
  });
});

and this goes in /common/common.css

// we don't use display: none; here because we don't want to mess with load-more
.ignored-op-topic {
  height: 0;
  width: 0;
  position: fixed;
  bottom: 0;
}