From 2fb8c03127165c7704180a14e57dc4795f55f009 Mon Sep 17 00:00:00 2001 From: Dean Vigoren Date: Sat, 16 Mar 2024 14:57:58 -0600 Subject: [PATCH] Reverted the chat for for adding timestamps back to what was present in version 2.4.3 of SC to eliminate the issues that other systems are seeing. Reapproached the dnd 3.5e issues with chat messages and came up with a different solution that should fix that issue without affecting other systems. --- CHANGELOG.md | 19 ++++++++++- package.json | 2 +- simple-calendar-docs/docs/changelog.md | 19 ++++++++++- .../versioned_docs/version-2.4.x/changelog.md | 19 ++++++++++- src/classes/chat/chat-timestamp.test.ts | 20 ++++++------ src/classes/chat/chat-timestamp.ts | 32 ++++++++++++++----- src/classes/chat/index.test.ts | 12 +++---- src/classes/chat/index.ts | 3 +- src/classes/systems/D35E.test.ts | 12 +++++++ src/classes/systems/D35E.ts | 10 ++++++ src/index.ts | 2 +- src/module.json | 2 +- 12 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 src/classes/systems/D35E.test.ts create mode 100644 src/classes/systems/D35E.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c99c361..c8bde9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,25 @@ # Change Log +## 2.4.13 - Chat Bug Fixes + +![](https://img.shields.io/badge/release%20date-March%2016%2C%202024-blue) +![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.13/module.zip) + +### Chat Bug Fixes + +Due to a change to support a bug in the DnD 3.5E system a bug was introduced for other systems that caused chat messages to occasionally duplicate (just the display) or have certain interactive elements missing. + +Trying to get that change to work has been unsuccessful, so I have reverted the chat message changes to what they were in version 2.4.3 of Simple Calendar. This should address the issues with the duplicated chat messages and missing interactive elements. + +I have approached the bug in the DnD 3.5E system in a different way that fixes the issue without causing issues for other systems. + +Sorry for the inconvenience, and thank you for your patience while I worked to resolve this issue. + +
+ ## 2.4.12 - Bug Fixes -![](https://img.shields.io/badge/release%20date-March%2009%2C%202024-blue) +![](https://img.shields.io/badge/release%20date-March%2013%2C%202024-blue) ![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.12/module.zip) ### Bug Fixes diff --git a/package.json b/package.json index 6ff0e0e..244dcc0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "foundryvtt-simple-calendar", "description": "A simple calendar module for keeping track of game days and events.", - "version": "2.4.12", + "version": "2.4.13", "author": "Dean Vigoren (vigorator)", "keywords": [ "foundryvtt", diff --git a/simple-calendar-docs/docs/changelog.md b/simple-calendar-docs/docs/changelog.md index c776b1e..0aea357 100644 --- a/simple-calendar-docs/docs/changelog.md +++ b/simple-calendar-docs/docs/changelog.md @@ -1,8 +1,25 @@ # Change Log +## 2.4.13 - Chat Bug Fixes + +![](https://img.shields.io/badge/release%20date-March%2016%2C%202024-blue) +![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.13/module.zip) + +### Chat Bug Fixes + +Due to a change to support a bug in the DnD 3.5E system a bug was introduced for other systems that caused chat messages to occasionally duplicate (just the display) or have certain interactive elements missing. + +Trying to get that change to work has been unsuccessful, so I have reverted the chat message changes to what they were in version 2.4.3 of Simple Calendar. This should address the issues with the duplicated chat messages and missing interactive elements. + +I have approached the bug in the DnD 3.5E system in a different way that fixes the issue without causing issues for other systems. + +Sorry for the inconvenience, and thank you for your patience while I worked to resolve this issue. + +
+ ## 2.4.12 - Bug Fixes -![](https://img.shields.io/badge/release%20date-March%2009%2C%202024-blue) +![](https://img.shields.io/badge/release%20date-March%2013%2C%202024-blue) ![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.12/module.zip) ### Bug Fixes diff --git a/simple-calendar-docs/versioned_docs/version-2.4.x/changelog.md b/simple-calendar-docs/versioned_docs/version-2.4.x/changelog.md index c776b1e..0aea357 100644 --- a/simple-calendar-docs/versioned_docs/version-2.4.x/changelog.md +++ b/simple-calendar-docs/versioned_docs/version-2.4.x/changelog.md @@ -1,8 +1,25 @@ # Change Log +## 2.4.13 - Chat Bug Fixes + +![](https://img.shields.io/badge/release%20date-March%2016%2C%202024-blue) +![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.13/module.zip) + +### Chat Bug Fixes + +Due to a change to support a bug in the DnD 3.5E system a bug was introduced for other systems that caused chat messages to occasionally duplicate (just the display) or have certain interactive elements missing. + +Trying to get that change to work has been unsuccessful, so I have reverted the chat message changes to what they were in version 2.4.3 of Simple Calendar. This should address the issues with the duplicated chat messages and missing interactive elements. + +I have approached the bug in the DnD 3.5E system in a different way that fixes the issue without causing issues for other systems. + +Sorry for the inconvenience, and thank you for your patience while I worked to resolve this issue. + +
+ ## 2.4.12 - Bug Fixes -![](https://img.shields.io/badge/release%20date-March%2009%2C%202024-blue) +![](https://img.shields.io/badge/release%20date-March%2013%2C%202024-blue) ![GitHub release](https://img.shields.io/github/downloads-pre/vigoren/foundryvtt-simple-calendar/v2.4.12/module.zip) ### Bug Fixes diff --git a/src/classes/chat/chat-timestamp.test.ts b/src/classes/chat/chat-timestamp.test.ts index 4083a1e..d7cebe0 100644 --- a/src/classes/chat/chat-timestamp.test.ts +++ b/src/classes/chat/chat-timestamp.test.ts @@ -40,28 +40,30 @@ describe("Chat Timestamp Tests", () => { test("Add Game Time To Message", async () => { const cm = { - isAuthor: true, setFlag: jest.fn((mn: string, key: string, data: any) => { - cm.flags[mn] = {}; - cm.flags[mn][key] = data; + cm.flags[key] = data; return Promise.resolve(); }), flags: >{}, updateSource: jest.fn((obj: Record) => { cm.flags = obj["flags"]; - }) + }), + _source: { + flags: >{} + } }; //@ts-ignore - await ChatTimestamp.addGameTimeToMessage(cm); + ChatTimestamp.addGameTimeToMessage(cm); - expect(cm.setFlag).toHaveBeenCalledTimes(1); + expect(cm.updateSource).toHaveBeenCalledTimes(1); expect(cm.flags["foundryvtt-simple-calendar"]["sc-timestamps"]).toEqual({ id: "a", timestamp: tCal.toSeconds() }); - cm.isAuthor = false; //@ts-ignore - await ChatTimestamp.addGameTimeToMessage(cm); - expect(cm.setFlag).toHaveBeenCalledTimes(1); + game.system.id = "D35E"; + //@ts-ignore + ChatTimestamp.addGameTimeToMessage(cm); + expect(cm._source.flags["foundryvtt-simple-calendar"]["sc-timestamps"]).toEqual({ id: "a", timestamp: tCal.toSeconds() }); }); test("Get Formatted Chat Timestamp", () => { diff --git a/src/classes/chat/chat-timestamp.ts b/src/classes/chat/chat-timestamp.ts index fa0684d..06f71b8 100644 --- a/src/classes/chat/chat-timestamp.ts +++ b/src/classes/chat/chat-timestamp.ts @@ -2,18 +2,34 @@ import { ModuleName } from "../../constants"; import { CalManager, SC } from "../index"; import { FormatDateTime } from "../utilities/date-time"; import PF2E from "../systems/pf2e"; +import D35E from "../systems/D35E"; export class ChatTimestamp { public static addGameTimeToMessage(chatMessage: ChatMessage) { - if (chatMessage.isAuthor) { - const cal = CalManager.getActiveCalendar(); - const flagData: { id: string; timestamp: number } = { - id: cal.id, - timestamp: cal.toSeconds() - }; - return chatMessage.setFlag(ModuleName, "sc-timestamps", flagData); + console.log("ChatTimestamp.addGameTimeToMessage"); + const cal = CalManager.getActiveCalendar(); + const flagData: { id: string; timestamp: number } = { + id: cal.id, + timestamp: cal.toSeconds() + }; + if (D35E.isD35E) { + // the updateSource function call creates an infinite loop in D35E so we just need to update the source directly, which isn't as safe. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + chatMessage._source.flags[ModuleName] = { "sc-timestamps": flagData }; + } else { + //Updating the message flags then updating the source with its own flags ensures what we do not wright over another modules message settings. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + const messageFlags = chatMessage.flags; + if (!Object.prototype.hasOwnProperty.call(messageFlags, ModuleName)) { + messageFlags[ModuleName] = {}; + } + messageFlags[ModuleName]["sc-timestamps"] = flagData; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + chatMessage.updateSource({ flags: messageFlags }); } - return Promise.resolve(); } public static getFormattedChatTimestamp(chatMessage: ChatMessage) { diff --git a/src/classes/chat/index.test.ts b/src/classes/chat/index.test.ts index 0982243..a87033b 100644 --- a/src/classes/chat/index.test.ts +++ b/src/classes/chat/index.test.ts @@ -18,20 +18,16 @@ describe("Chat Tests", () => { test("Create Chat Message", async () => { let cm = {}; - jest.spyOn(ChatTimestamp, "addGameTimeToMessage").mockImplementation(async () => { - return cm; - }); - //@ts-ignore - let rcm = await Chat.createChatMessage(cm); + jest.spyOn(ChatTimestamp, "addGameTimeToMessage").mockImplementation(() => {}); + //@ts-ignore - expect(rcm).toBe(cm); + expect(Chat.createChatMessage(cm, {}, "")).toBe(true); expect(ChatTimestamp.addGameTimeToMessage).toHaveBeenCalledTimes(1); //@ts-ignore game.user.isGM = true; //@ts-ignore - rcm = await Chat.createChatMessage(cm, {}, ""); - expect(rcm).toBe(cm); + expect(Chat.createChatMessage(cm, {}, "")).toBe(true); expect(ChatTimestamp.addGameTimeToMessage).toHaveBeenCalledTimes(2); }); diff --git a/src/classes/chat/index.ts b/src/classes/chat/index.ts index e8914e8..db8a0d0 100644 --- a/src/classes/chat/index.ts +++ b/src/classes/chat/index.ts @@ -12,7 +12,8 @@ export class Chat { ChatMessage.prototype.export = new Proxy(ChatMessage.prototype.export, handler); } public static createChatMessage(chatMessage: ChatMessage) { - return ChatTimestamp.addGameTimeToMessage(chatMessage); + ChatTimestamp.addGameTimeToMessage(chatMessage); + return true; } public static onRenderChatMessage(chatMessage: ChatMessage, html: JQuery) { diff --git a/src/classes/systems/D35E.test.ts b/src/classes/systems/D35E.test.ts new file mode 100644 index 0000000..a9deb55 --- /dev/null +++ b/src/classes/systems/D35E.test.ts @@ -0,0 +1,12 @@ +/** + * @jest-environment jsdom + */ +import "../../../__mocks__/index"; +import { jest, beforeEach, describe, expect, test } from "@jest/globals"; +import D35E from "./D35E"; + +describe("Systems/D35E Class Tests", () => { + test("Is D35E", () => { + expect(D35E.isD35E).toBe(false); + }); +}); diff --git a/src/classes/systems/D35E.ts b/src/classes/systems/D35E.ts new file mode 100644 index 0000000..45eb096 --- /dev/null +++ b/src/classes/systems/D35E.ts @@ -0,0 +1,10 @@ +import { FoundryVTTGameData } from "../foundry-interfacing/game-data"; + +export default class D35E { + /** + * Is the current system pathfinder 1e? + */ + public static get isD35E() { + return FoundryVTTGameData.systemID === "D35E"; + } +} diff --git a/src/index.ts b/src/index.ts index da19217..0fad6db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ Hooks.on("createCombatant", SC.createCombatant.bind(SC)); Hooks.on("updateCombat", SC.combatUpdate.bind(SC)); Hooks.on("deleteCombat", SC.combatDelete.bind(SC)); Hooks.on("pauseGame", SC.gamePaused.bind(SC)); -Hooks.on("createChatMessage", Chat.createChatMessage); +Hooks.on("preCreateChatMessage", Chat.createChatMessage); Hooks.on("renderChatMessage", Chat.onRenderChatMessage); Hooks.on("renderMainApp", MainApp.setWidthHeight); Hooks.on("renderNoteSheet", NoteSheet.SetHeight); diff --git a/src/module.json b/src/module.json index 024f2bb..1d6ff0e 100644 --- a/src/module.json +++ b/src/module.json @@ -3,7 +3,7 @@ "name": "foundryvtt-simple-calendar", "title": "Simple Calendar", "description": "A simple calendar module for keeping track of game days and events.", - "version": "2.4.12", + "version": "2.4.13", "authors": [ { "name": "Dean Vigoren (Vigorator)",