Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.11] - 2025-01-15

### Fixed
- Restored compatibility with PopOut! by cloning sidebar base options before overriding defaults so Combat Tracker and other stock tabs keep their pop-out buttons when realtime sync is enabled.
- When syncing existing Session Recaps via the "Sync with Archivist" button, the `sessionDate` flag is now properly detected and updated when the `session_date` changes in Archivist, ensuring correct date display and chronological sorting in the Recaps folder.

## [1.3.10] - 2025-01-15

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "cameron.b.llewellyn@gmail.com"
}
],
"version": "1.3.10",
"version": "1.3.11",
"compatibility": {
"minimum": "13.341",
"verified": "13.346"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archivist-sync",
"version": "1.3.10",
"version": "1.3.11",
"description": "A simple Foundry VTT module for fetching world data from an API endpoint using an API key.",
"type": "module",
"scripts": {
Expand Down
87 changes: 87 additions & 0 deletions scripts/dialogs/sync-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,50 @@ export class SyncDialog extends foundry.applications.api.HandlebarsApplicationMi
}
}

// Reorder all recaps after any sessionDate changes (from diffs or imports)
const hasRecapDiffs = selectedDiffs.some(
(d) => d.type === 'Session' && d.changes?.sessionDate
);
if (hasRecapDiffs || selectedImports.some((i) => i.type === 'Session')) {
try {
const recapsFolderId = await Utils.ensureJournalFolder('Recaps');
const entries = (game.journal?.contents || [])
.filter((j) => (j.folder?.id || null) === (recapsFolderId || null))
.filter(
(j) =>
String(
(j.getFlag(CONFIG.MODULE_ID, 'archivist') || {}).sheetType ||
''
) === 'recap'
);
const withDates = entries.map((j) => ({
j,
dateMs: (() => {
const iso = String(
j.getFlag(CONFIG.MODULE_ID, 'sessionDate') || ''
).trim();
const t = iso ? new Date(iso).getTime() : NaN;
return Number.isFinite(t) ? t : Number.POSITIVE_INFINITY; // undated go to end
})(),
}));
withDates.sort((a, b) => a.dateMs - b.dateMs);
let index = 0;
for (const { j } of withDates) {
const desired = index * 1000;
index += 1;
if (j.sort !== desired) {
try {
await j.update({ sort: desired }, { render: false });
} catch (_) {
/* ignore */
}
}
}
} catch (_) {
/* ignore ordering failures */
}
}

ui.notifications?.info?.('Archivist sync applied.');
// Force-refresh core directories and any open Archivist windows so UI reflects new docs
await this._refreshUIAfterSync?.();
Expand Down Expand Up @@ -420,6 +464,20 @@ export class SyncDialog extends foundry.applications.api.HandlebarsApplicationMi
if (flagImg !== archImg)
changes.image = { from: flagImg, to: archImg };
}
// Session date diff: compare Archivist session_date with Foundry sessionDate flag
if (type === 'Session' && arch.session_date) {
try {
const currentDate = String(
j.getFlag(CONFIG.MODULE_ID, 'sessionDate') || ''
).trim();
const archDate = String(arch.session_date || '').trim();
if (archDate && currentDate !== archDate) {
changes.sessionDate = { from: currentDate || null, to: archDate };
}
} catch (_) {
/* ignore */
}
}
// Links diff: only outgoing links (from_id == this sheet's archivistId), ignore alias
try {
const wantList = outgoing.get(archId) || [];
Expand Down Expand Up @@ -586,6 +644,35 @@ export class SyncDialog extends foundry.applications.api.HandlebarsApplicationMi
await j.setFlag(CONFIG.MODULE_ID, 'archivist', nextFlags);
// Hub image flag removed
}
if (changes.sessionDate) {
// Update sessionDate flag to match Archivist session_date (same as world setup)
const archDate = String(changes.sessionDate.to || '').trim();
if (archDate) {
try {
await j.setFlag(
CONFIG.MODULE_ID,
'sessionDate',
archDate
);
// Also update sort order if this is a recap in the Recaps folder
const sheetType = String(
(j.getFlag(CONFIG.MODULE_ID, 'archivist') || {}).sheetType || ''
).toLowerCase();
if (sheetType === 'recap' || sheetType === 'session') {
try {
const sortValue = new Date(archDate).getTime();
if (Number.isFinite(sortValue)) {
await j.update({ sort: sortValue }, { render: false });
}
} catch (_) {
/* ignore sort update failures */
}
}
} catch (_) {
/* ignore */
}
}
}
if (changes.links) {
const buckets = {
character: 'characters',
Expand Down
5 changes: 5 additions & 0 deletions templates/sync-dialog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<th style="width: 80px; text-align: center;">Title</th>
<th style="width: 100px; text-align: center;">Description</th>
<th style="width: 80px; text-align: center;">Image</th>
<th style="width: 80px; text-align: center;">Date</th>
<th style="width: 80px; text-align: center;">Links</th>
</tr>
</thead>
Expand All @@ -54,6 +55,10 @@
{{#if d.changes.image}}<i class="fas fa-check"
style="color: var(--arch-success);"></i>{{/if}}
</td>
<td style="text-align: center;">
{{#if d.changes.sessionDate}}<i class="fas fa-check"
style="color: var(--arch-success);"></i>{{/if}}
</td>
<td style="text-align: center;">
{{#if d.changes.links}}<i class="fas fa-check"
style="color: var(--arch-success);"></i>{{/if}}
Expand Down