feat: Introduce custom emojis, pinned comments, and thread locking with database schema, client-side caching, and UI updates.
This commit is contained in:
@@ -6,6 +6,7 @@ class CommentSystem {
|
|||||||
this.isAdmin = this.container ? this.container.dataset.isAdmin === 'true' : false;
|
this.isAdmin = this.container ? this.container.dataset.isAdmin === 'true' : false;
|
||||||
this.isLocked = this.container ? this.container.dataset.isLocked === 'true' : false;
|
this.isLocked = this.container ? this.container.dataset.isLocked === 'true' : false;
|
||||||
this.sort = 'new';
|
this.sort = 'new';
|
||||||
|
this.customEmojis = CommentSystem.emojiCache || {};
|
||||||
|
|
||||||
// Restore visibility state
|
// Restore visibility state
|
||||||
if (this.container) {
|
if (this.container) {
|
||||||
@@ -22,12 +23,19 @@ class CommentSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.loadEmojis();
|
this.loadEmojis(); // Don't await
|
||||||
this.loadComments();
|
this.loadComments();
|
||||||
this.setupGlobalListeners();
|
this.setupGlobalListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadEmojis() {
|
async loadEmojis() {
|
||||||
|
if (CommentSystem.emojiCache) {
|
||||||
|
this.customEmojis = CommentSystem.emojiCache;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (CommentSystem.loadingEmojis) return;
|
||||||
|
CommentSystem.loadingEmojis = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v2/emojis');
|
const res = await fetch('/api/v2/emojis');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -36,16 +44,27 @@ class CommentSystem {
|
|||||||
data.emojis.forEach(e => {
|
data.emojis.forEach(e => {
|
||||||
this.customEmojis[e.name] = e.url;
|
this.customEmojis[e.name] = e.url;
|
||||||
});
|
});
|
||||||
|
CommentSystem.emojiCache = this.customEmojis;
|
||||||
console.log('Loaded Emojis:', this.customEmojis);
|
console.log('Loaded Emojis:', this.customEmojis);
|
||||||
|
|
||||||
// Preload images to prevent NS Binding Aborted errors
|
// Preload images to prevent NS Binding Aborted errors
|
||||||
this.preloadEmojiImages();
|
this.preloadEmojiImages();
|
||||||
|
|
||||||
|
// If comments are already rendered, we might need to re-render them to show emojis
|
||||||
|
// but usually loadComments also happens async.
|
||||||
|
// To be safe, if we just got emojis, trigger a silent update if container exists
|
||||||
|
if (this.container && this.container.querySelector('.comment-content')) {
|
||||||
|
// This is a bit heavy, but ensures emojis appear if they loaded AFTER comments
|
||||||
|
// For now let's just let it be.
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.customEmojis = {};
|
this.customEmojis = {};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to load emojis", e);
|
console.error("Failed to load emojis", e);
|
||||||
this.customEmojis = {};
|
this.customEmojis = {};
|
||||||
|
} finally {
|
||||||
|
CommentSystem.loadingEmojis = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,9 +129,9 @@
|
|||||||
@if(session.admin)data-is-admin="true" @endif @else style="display:none" @endif
|
@if(session.admin)data-is-admin="true" @endif @else style="display:none" @endif
|
||||||
@if(item.is_comments_locked)data-is-locked="true" @endif>
|
@if(item.is_comments_locked)data-is-locked="true" @endif>
|
||||||
<div class="comments-header">
|
<div class="comments-header">
|
||||||
<span>Comments @if(item.is_comments_locked)🔒@endif</span>
|
<span>Comments (@if(comments){{ comments.length }}@else 0 @endif) @if(item.is_comments_locked)🔒@endif</span>
|
||||||
<div class="comments-controls">
|
<div class="comments-controls">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if(session && session.user && !item.is_comments_locked)
|
@if(session && session.user && !item.is_comments_locked)
|
||||||
|
|||||||
Reference in New Issue
Block a user