gfsd
This commit is contained in:
+54
-8
@@ -27,6 +27,8 @@ class CommentSystem {
|
||||
if (this.displayMode === 1) this.sort = 'old';
|
||||
|
||||
this.customEmojis = CommentSystem.emojiCache || {};
|
||||
this._selfPostedCommentIds = new Set();
|
||||
this._pendingSelfCommentTexts = new Set();
|
||||
|
||||
this.icons = {
|
||||
reply: `<i class="fa-solid fa-reply"></i>`,
|
||||
@@ -472,6 +474,34 @@ class CommentSystem {
|
||||
}
|
||||
}
|
||||
|
||||
_isSelfComment(data) {
|
||||
if (!data) return false;
|
||||
if (data.id && this._selfPostedCommentIds?.has(data.id)) return true;
|
||||
if (data.body && this._pendingSelfCommentTexts?.has(data.body)) return true;
|
||||
|
||||
const session = window.f0ckSession || {};
|
||||
const currentUserId = session.id || session.user_id;
|
||||
if (currentUserId && data.user_id && parseInt(data.user_id, 10) === parseInt(currentUserId, 10)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentUsername = session.user || this.user;
|
||||
if (currentUsername && data.username && currentUsername.toLowerCase() === data.username.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (session.is_anon && data.is_anon) {
|
||||
if (data.anon_fingerprint && session.fingerprint && data.anon_fingerprint === session.fingerprint) {
|
||||
return true;
|
||||
}
|
||||
if (data.anon_short_fingerprint && session.fingerprint && session.fingerprint.includes(data.anon_short_fingerprint)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handleLiveComment(data) {
|
||||
if (!this.container || !this.itemId) return;
|
||||
// 1. Check if comment belongs to this item
|
||||
@@ -537,14 +567,20 @@ class CommentSystem {
|
||||
|
||||
// Danmaku: fire one-shot for other users' comments.
|
||||
// Own comment is handled by the optimistic submit path (fire + addItem).
|
||||
// The _loadDanmaku re-render will add this comment to the items rotation.
|
||||
const currentUser = window.f0ckSession?.user;
|
||||
if (window.danmakuInstance && data.username !== currentUser) {
|
||||
const isSelf = this._isSelfComment(data);
|
||||
if (window.danmakuInstance && !isSelf) {
|
||||
window.danmakuInstance.fire(
|
||||
data.body,
|
||||
data.display_name || data.username || '?',
|
||||
data.username_color || null
|
||||
);
|
||||
window.danmakuInstance.addItem({
|
||||
id: data.id,
|
||||
content: data.body,
|
||||
video_time: data.video_time ?? null,
|
||||
display_name: data.display_name || data.username || '?',
|
||||
username_color: data.username_color || null
|
||||
});
|
||||
}
|
||||
|
||||
// Update backlinks for live comment
|
||||
@@ -3448,6 +3484,7 @@ class CommentSystem {
|
||||
} else {
|
||||
this.isMainSubmitting = true;
|
||||
}
|
||||
this._pendingSelfCommentTexts.add(text);
|
||||
|
||||
let retryCount = 0;
|
||||
const maxRetries = 20; // Allow several minutes of retrying during restart
|
||||
@@ -3534,7 +3571,7 @@ class CommentSystem {
|
||||
// For 4xx errors, we stop and show the error to user (likely validation or auth)
|
||||
const json = await res.json().catch(() => ({}));
|
||||
alert('Error: ' + (json.message || `Status ${res.status}`));
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId);
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId, text);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3692,6 +3729,11 @@ class CommentSystem {
|
||||
poll: null
|
||||
};
|
||||
|
||||
if (json.comment?.id) {
|
||||
this._selfPostedCommentIds.add(json.comment.id);
|
||||
}
|
||||
this._pendingSelfCommentTexts.delete(text);
|
||||
|
||||
// Danmaku: fire immediately (one-shot) + add to future rotation
|
||||
if (window.danmakuInstance) {
|
||||
window.danmakuInstance.fire(
|
||||
@@ -3700,6 +3742,7 @@ class CommentSystem {
|
||||
session.username_color || null
|
||||
);
|
||||
window.danmakuInstance.addItem({
|
||||
id: newComment.id,
|
||||
content: text,
|
||||
video_time: newComment.video_time ?? null,
|
||||
display_name: session.display_name || currentUsername || '?',
|
||||
@@ -3810,10 +3853,10 @@ class CommentSystem {
|
||||
}
|
||||
|
||||
this._silentSync();
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId);
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId, text);
|
||||
} else {
|
||||
alert('Error: ' + json.message);
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId);
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId, text);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`[CommentSystem] Submit attempt ${retryCount + 1} failed:`, err);
|
||||
@@ -3825,7 +3868,7 @@ class CommentSystem {
|
||||
setTimeout(attemptSubmit, delay);
|
||||
} else {
|
||||
alert('Failed to send comment after multiple attempts. Please check your connection.');
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId);
|
||||
this._finishSubmit(submitBtn, originalBtnHtml, parentId, text);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -3857,7 +3900,10 @@ class CommentSystem {
|
||||
console.log('[ensureBtn] done, button in DOM:', !!contentEl.querySelector('.load-full-comment-btn'));
|
||||
}
|
||||
|
||||
_finishSubmit(btn, originalHtml, parentId) {
|
||||
_finishSubmit(btn, originalHtml, parentId, submittedText = null) {
|
||||
if (submittedText) {
|
||||
this._pendingSelfCommentTexts?.delete(submittedText);
|
||||
}
|
||||
if (parentId) {
|
||||
this.pendingSubmissions.delete(parentId);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user