이건 쉽게 할 수 있습니다. 토픽 모델(topic model)에는 이미 답글을 남겼는지 여부를 보여주는 속성이 하나 있는데, 이름은 posted입니다. 이전에 제가 작성한 컴포넌트( Composer tip under specific tag topics )에서 답글 여부를 판별하는 로직을 구현해 두었습니다. 코딩 기초가 있다면 제가 작성한 코드를 참고해 보세요. API의 decorateCookedElement 메서드와 결합하면 답글을 남기지 않은 경우 콘텐츠를 숨기는 기능을 구현할 수 있습니다.
구체적인 코드는 최근 너무 바빠서 작성하기가 귀찮습니다.
<script type="text/discourse-plugin" version="1.6.0">
const user = api.getCurrentUser();
const I18n = require("I18n");
const pid = "post_hider"
const tl4_css = `
.d-editor-preview [data-theme-hide] {
background: var(--tertiary);
color: var(--secondary);
border-top: 2px solid var(--secondary);
position: sticky;
top: 0;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
}
.d-editor-preview [data-theme-hide]::before {
content: "本帖子被设为隐藏";
}
`
api.addPostClassesCallback((attrs) => {
if (attrs?.cooked?.includes(`<div data-theme-hide="true">`)) {
return ["hiddened"]; // css 추가용, 이후 css 작성은 알아서 하세요
} else {
return [];
}
});
if (!user) {
api.decorateCookedElement((el, helper) => {
function hide_post() {
setTimeout( () => {
try {
// document.querySelector(`[data-post-id="${helper?.widget?.attrs?.id}"]`)?.parentElement?.remove();
} catch (err) {
console.log(el);
console.log(err);
}
}, 1000);
}
if (el?.querySelector(`[data-theme-hide="true"]`)) {
el.innerHTML = `<p>帖子已被社区隐藏</p>`; // 이 줄을 수정하세요
hide_post();
}
}, {
id: pid,
afterAdopt: true,
onlyStream: true,
});
}
</script>
갑자기 떠올랐는데, 이전에 로그인하지 않은 사용자에게 전체 게시물을 숨기려고 사용했던 코드가 하나 있습니다. 참고용으로 사용하세요.