Fix issue #111: Entry sync on foundry keeps creating new journal entries
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-16 16:57:28 +00:00
parent b5d5e570d5
commit eead3c9be8
4 changed files with 93 additions and 14 deletions

View File

@@ -138,9 +138,10 @@ note stands as a page of one JournalEntry named **Dragonroll**. The module creat
adopts one the GM already made under that name, marking it as the notes' journal — and renders each
note's markdown into page HTML with Foundry's own renderer. Notes are written in Dragonroll, so this
copy runs one way: a note made or edited in the campaign rewrites its page on the next reconcile, and
a note deleted there takes its page with it. Pages the campaign does not own — the GM's own pages in
that journal — are left alone, and nothing written in the journal travels back. Autosync off stops it
too, like the rest of the sync.
a note deleted there takes its page with it. A page standing under a note's title but carrying no
Dragonroll mark is claimed as that note's page, so a lost pairing does not double it. Any other page in
that journal — the GM's own — is left alone, and nothing written in the journal travels back. Autosync
off stops it too, like the rest of the sync.
The module calls these Dragonroll routes with the campaign sync token (no Dragonroll login):

View File

@@ -1474,8 +1474,9 @@ async function initializeSceneSync() {
// stands as a page of one JournalEntry named "Dragonroll". Notes are written in
// Dragonroll, so this copy runs one way — the reconcile writes each note into its
// page and drops the page of a note the campaign deleted. Nothing of the journal
// is read back, and the GM's own pages in that journal are left alone: only the
// ones this module made carry the `dragonroll-foundry.noteId` flag.
// is read back. A page the module made carries the `dragonroll-foundry.noteId`
// flag; one without it that stands under a note's title is claimed as that note's
// page rather than doubled, and any other page is the GM's own and left alone.
const NOTES_JOURNAL_NAME = "Dragonroll";
let noteSyncRunning = false;
@@ -1599,10 +1600,30 @@ async function reconcileDragonrollNotes() {
await applyDragonrollNotePage(page, entry);
if (!entry.foundryPageId) await mapDragonrollNote(entry._id, page.id);
} else {
const created = await createDragonrollNotePage(journal, entry);
if (created) {
retainedPageIds.add(created.id);
await mapDragonrollNote(entry._id, created.id);
// A page under the note's title that carries no Dragonroll mark — one the
// module made before the campaign kept its mapping, or one whose flag was
// lost — is claimed as that note's page instead of adding a second page of
// the same name. Like the item sync's same-name adoption, this is what keeps
// a note from being written as a new page on every reconcile.
const sameName = (journal.pages?.contents || []).find((candidate) => (
String(candidate.name ?? "") === notePageTitle(entry)
&& !dragonrollNoteId(candidate)
&& !retainedPageIds.has(candidate.id)
));
if (sameName) {
retainedPageIds.add(sameName.id);
await applyDragonrollNotePage(sameName, entry);
await mapDragonrollNote(entry._id, sameName.id);
} else {
const created = await createDragonrollNotePage(journal, entry);
if (created) {
retainedPageIds.add(created.id);
// The create carries the note's flag, but a world that drops it would leave
// the page unclaimed and the next reconcile would make another: mark it
// again the way the rest of the sync marks its documents.
await applyDragonrollNotePage(created, entry);
await mapDragonrollNote(entry._id, created.id);
}
}
}
}