Extends Chat Message, issue with model data

I intend to extends ChatMessage to add a field to the schema. and then add it to the renderTemplate data to be shown. But during the "getHTML" function the value that I added to the schema is always empty. Do I have to setup something else to make it reach getHTML with the proper value ? The class extending the ChatMessage
export default class MyChatMessage extends ChatMessage {
static defineSchema() {
return {
...super.defineSchema(),
postcontent: new foundry.data.fields.HTMLField({ textSearch: true }),
};
}

async getHTML() {
console.log("getHTML");
console.dir(this);
return super.getHTML();
}

}
export default class MyChatMessage extends ChatMessage {
static defineSchema() {
return {
...super.defineSchema(),
postcontent: new foundry.data.fields.HTMLField({ textSearch: true }),
};
}

async getHTML() {
console.log("getHTML");
console.dir(this);
return super.getHTML();
}

}
Inside my "init" hook
CONFIG.ChatMessage.documentClass = documents.MyChatMessage;
CONFIG.ChatMessage.template = "systems/mysystem/templates/chat_messages/chat_message.hbs";
CONFIG.ChatMessage.documentClass = documents.MyChatMessage;
CONFIG.ChatMessage.template = "systems/mysystem/templates/chat_messages/chat_message.hbs";
The calling code
ChatMessage.create({
speaker: ChatMessage.getSpeaker({ actor: this }),
user: game.user.id,
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
sound: CONFIG.sounds.dice,
rolls: [roll],
content: "<div>Content</div>",
postcontent: "<div>PostContent</div>"
}, { rollMode: roll_mode });
ChatMessage.create({
speaker: ChatMessage.getSpeaker({ actor: this }),
user: game.user.id,
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
sound: CONFIG.sounds.dice,
rolls: [roll],
content: "<div>Content</div>",
postcontent: "<div>PostContent</div>"
}, { rollMode: roll_mode });
6 Replies
Wildos
WildosOP•4w ago
I am using FoundryVTT 11.315, if it is relevant
Ethaks
Ethaks•4w ago
You cannot ever change the base document schema, only the system's.
Wildos
WildosOP•4w ago
ChatMessage does not have a 'system' field, should I create it or does it mean I can't alter its model and need to find another way to store the data ?
Ethaks
Ethaks•4w ago
v12 gives chat messages system fields that you can use. If you absolutely have to stay with v11, you have to resort to storing data in flags.
Wildos
WildosOP•4w ago
Ok, thank you for the informations. I will have to use flag then. 🙂
Leo The League Lion
Leo The League Lion•4w ago
@Wildos gave :vote: LeaguePoints™ to @Ethaks (#7 • 392)
Want results from more Discord servers?
Add your server