Hi, it's me again. As I said in my previous thread, I'm pretty bad at creating or editing Flarum extensions, but I can improve some things thanks to extend.php.
In other threads (Oshvam CyberGene CyberGene ), we have discussed how poorly the ignore tool works (FriendsOfFlarum ), as it only hides messages from ignored users but not their discussions. I can think of a thousand scenarios where this is necessary.
🆕 New features
- You will no longer see threads from ignored users on the front page.
- You will no longer see threads from ignored users in categories.
- You will no longer see private messages from ignored users.
🐛 Known bugs
- You can still search for an ignored user.
- Even if the user does not read your messages, you can still send private messages to the ignored user.
Just paste this code into your extend.php. You can adjust the ‘500’ parameter to set the script's loading milliseconds; I haven't found a more elegant way to do this. If @IanM can improve this or offer advice, I'll be listening 🙂
// Para ocultar los post de ignorados
(new Extend\Frontend('forum'))
->content(function ($document) {
$document->head[] = '<script>
(function() {
var hasRun = false;
function hideIgnoredDiscussions() {
if (typeof app === "undefined" || !app.session || !app.session.user) {
return;
}
var items = document.querySelectorAll(".DiscussionListItem");
if (items.length === 0) return;
var ignoredData = app.session.user.data.relationships.ignoredUsers.data;
var ignoredIds = ignoredData ? ignoredData.map(function(u) { return u.id; }) : [];
if (ignoredIds.length === 0) return;
var removed = 0;
items.forEach(function(item) {
var titleLink = item.querySelector(".DiscussionListItem-main");
if (!titleLink) return;
var href = titleLink.getAttribute("href");
var match = href ? href.match(/\/d\/(\d+)/) : null;
if (!match) return;
var discussion = app.store.getById("discussions", match[1]);
if (!discussion || !discussion.data) return;
var authorData = discussion.data.relationships.user.data;
if (!authorData) return;
if (ignoredIds.indexOf(authorData.id) !== -1) {
item.remove();
removed++;
}
});
if (removed > 0) {
console.log("Ocultadas " + removed + " discusiones de usuarios ignorados");
}
}
function waitAndHide() {
if (typeof app === "undefined" || !app.session || !app.session.user) {
setTimeout(waitAndHide, 500);
return;
}
var items = document.querySelectorAll(".DiscussionListItem");
if (items.length === 0) {
setTimeout(waitAndHide, 500);
return;
}
hideIgnoredDiscussions();
if (!hasRun) {
hasRun = true;
// Observer para scroll infinito
var observer = new MutationObserver(function() {
setTimeout(hideIgnoredDiscussions, 200);
});
var container = document.querySelector(".DiscussionList");
if (container) {
observer.observe(container, { childList: true, subtree: true });
}
// Detectar cambios de ruta (navegación SPA)
var originalPushState = history.pushState;
history.pushState = function() {
originalPushState.apply(this, arguments);
setTimeout(function() {
hasRun = false;
waitAndHide();
}, 500);
};
// También detectar popstate (botón atrás/adelante)
window.addEventListener("popstate", function() {
setTimeout(function() {
hasRun = false;
waitAndHide();
}, 500);
});
}
}
waitAndHide();
})();
</script>';
}),