Fix issue #111: Entry sync on foundry keeps creating new journal entries
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user