Skip to content

Commit

Permalink
Merge pull request #591 from vigoren/develop
Browse files Browse the repository at this point in the history
2.4.13
  • Loading branch information
vigoren authored Mar 16, 2024
2 parents d0297ed + 2fb8c03 commit 1e57dfb
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 32 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

<hr/>

## 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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 18 additions & 1 deletion simple-calendar-docs/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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.

<hr/>

## 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
Expand Down
19 changes: 18 additions & 1 deletion simple-calendar-docs/versioned_docs/version-2.4.x/changelog.md
Original file line number Diff line number Diff line change
@@ -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.

<hr/>

## 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
Expand Down
20 changes: 11 additions & 9 deletions src/classes/chat/chat-timestamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Record<string, any>>{},
updateSource: jest.fn((obj: Record<string, any>) => {
cm.flags = obj["flags"];
})
}),
_source: {
flags: <Record<string, any>>{}
}
};

//@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", () => {
Expand Down
32 changes: 24 additions & 8 deletions src/classes/chat/chat-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions src/classes/chat/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ describe("Chat Tests", () => {

test("Create Chat Message", async () => {
let cm = {};
jest.spyOn(ChatTimestamp, "addGameTimeToMessage").mockImplementation(async () => {
return <ChatMessage>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);
});

Expand Down
3 changes: 2 additions & 1 deletion src/classes/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/classes/systems/D35E.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
10 changes: 10 additions & 0 deletions src/classes/systems/D35E.ts
Original file line number Diff line number Diff line change
@@ -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";
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down

0 comments on commit 1e57dfb

Please sign in to comment.