カスタムユーザーフィールドに含まれるキーワードを含む投稿をブロックするテーマコンポーネントに取り組んでいます。これは、デスクトップ表示の最新またはトップにリストされているときに、返信とトピックの両方を非表示にするのに役立ちますが、アプリまたはモバイルで表示すると、トピックがブロックされたという通知が追加されますが、コンテンツにブロックされたクラスが適用されません。トピック内の返信のブロックは、モバイルまたはアプリで問題なく機能します。
components を確認したところ、モバイルで異なる .hbs が使用されているようには見えませんでしたが、他に何か見落としていることはありますか?
const discourseComputed = require("discourse-common/utils/decorators").default;
function addIgnoredTopicClass() {
if (currentUser) {
api.container.lookup('store:main').find('user', currentUser.username).then((user) => {
const blocklist = user.user_fields[1];
const case_sensitive = user.user_fields[2];
const whole_words = user.user_fields[3];
const blocked = blocklist.split(",").map(function(item) {
if (case_sensitive) {
return item.trim();
} else {
return item.trim().toLowerCase();
}
});
let classList = this._super(...arguments);
let elem = document.querySelectorAll("[data-topic-id='" + this.topic.id.toString() + "']")[0];
console.log(elem);
const title = (case_sensitive) ? this.topic.fancy_title : this.topic.fancy_title.toLowerCase();
const excerpt = (case_sensitive) ? this.topic.excerpt : this.topic.excerpt.toLowerCase();
let result = "";
for (let index = 0; index < blocked.length; ++index) {
let pattern = (whole_words) ? new RegExp('(?:\\b|\\s|^)' + blocked[index] + '(?:\\b|\\s|$)') : new RegExp(blocked[index]);
// console.log(pattern)
if (pattern.test(title)) {
classList += "blocker-blocked"
const found = blocked.filter(text => title.includes(text));
if (found.length >= 2) {
const last = found.pop();
result = found.join(', ') + ' and ' + last;
} else {
result = found.join(', ');
}
const newNode = document.createElement("a");
const textNode = document.createTextNode("Blocked for containing " + result + ".");
newNode.classList.add("block-notice")
newNode.appendChild(textNode);
newNode.onclick = function() { showComment(this); };
elem.children[0].insertBefore(newNode, elem.children[0].children[0]);
for (let index = 0; index < elem.children.length; ++index) {
if (elem.children[index].classList.contains('main-link')) {
elem.children[index].classList.add("blocker-blocked");
}
}
newNode.classList.remove("blocker-blocked");
}
}
// console.log(classList);
return classList;
});
}
}
api.modifyClass("component:topic-list-item", {
@discourseComputed()
unboundClassNames() {
return addIgnoredTopicClass.call(this);
}
});
api.modifyClass("component:latest-topic-list-item", {
@discourseComputed()
unboundClassNames() {
return addIgnoredTopicClass.call(this);
}
});