mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-09 15:52:40 +02:00
fix: preserve author info in cloned chats and force PGlite resync after clone
This commit is contained in:
parent
988847922f
commit
24472c0ea6
3 changed files with 17 additions and 12 deletions
|
|
@ -187,6 +187,12 @@ export default function NewChatPage() {
|
||||||
? membersData?.find((m) => m.user_id === msg.author_id)
|
? membersData?.find((m) => m.user_id === msg.author_id)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
// Preserve existing author info if member lookup fails (e.g., cloned chats)
|
||||||
|
const existingMsg = prev.find((m) => m.id === `msg-${msg.id}`);
|
||||||
|
const existingAuthor = existingMsg?.metadata?.custom?.author as
|
||||||
|
| { displayName?: string | null; avatarUrl?: string | null }
|
||||||
|
| undefined;
|
||||||
|
|
||||||
return convertToThreadMessage({
|
return convertToThreadMessage({
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
thread_id: msg.thread_id,
|
thread_id: msg.thread_id,
|
||||||
|
|
@ -194,8 +200,8 @@ export default function NewChatPage() {
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
author_id: msg.author_id,
|
author_id: msg.author_id,
|
||||||
created_at: msg.created_at,
|
created_at: msg.created_at,
|
||||||
author_display_name: member?.user_display_name ?? null,
|
author_display_name: member?.user_display_name ?? existingAuthor?.displayName ?? null,
|
||||||
author_avatar_url: member?.user_avatar_url ?? null,
|
author_avatar_url: member?.user_avatar_url ?? existingAuthor?.avatarUrl ?? null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,15 @@ export function useInbox(
|
||||||
|
|
||||||
async function startSync() {
|
async function startSync() {
|
||||||
try {
|
try {
|
||||||
|
// Check for force resync flag (e.g., after clone from public page)
|
||||||
|
if (localStorage.getItem("surfsense_force_notif_resync") === "true") {
|
||||||
|
console.log("[useInbox] Force resync flag detected, clearing notifications");
|
||||||
|
await client.db.exec("DELETE FROM notifications");
|
||||||
|
localStorage.removeItem("surfsense_force_notif_resync");
|
||||||
|
// Reset sync key to force a fresh sync
|
||||||
|
userSyncKeyRef.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
const cutoffDate = getSyncCutoffDate();
|
const cutoffDate = getSyncCutoffDate();
|
||||||
const userSyncKey = `inbox_${userId}_${cutoffDate}`;
|
const userSyncKey = `inbox_${userId}_${cutoffDate}`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -274,16 +274,6 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
|
||||||
CREATE INDEX IF NOT EXISTS idx_new_chat_messages_created_at ON new_chat_messages(created_at);
|
CREATE INDEX IF NOT EXISTS idx_new_chat_messages_created_at ON new_chat_messages(created_at);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Force resync notifications if flagged (e.g., after clone from public page)
|
|
||||||
if (
|
|
||||||
typeof window !== "undefined" &&
|
|
||||||
localStorage.getItem("surfsense_force_notif_resync") === "true"
|
|
||||||
) {
|
|
||||||
console.log("[Electric] Force resync flag detected, clearing notifications table");
|
|
||||||
await db.exec("DELETE FROM notifications");
|
|
||||||
localStorage.removeItem("surfsense_force_notif_resync");
|
|
||||||
}
|
|
||||||
|
|
||||||
const electricUrl = getElectricUrl();
|
const electricUrl = getElectricUrl();
|
||||||
|
|
||||||
// STEP 4: Create the client wrapper
|
// STEP 4: Create the client wrapper
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue