Blind Chat Messages

Anyone have good examples of creating a chat message that should only be visible to a connected GM, but might be created by any connected client?
C
Calego932d ago
What I've got:
const messageData = {
whisper: ChatMessage.getWhisperRecipients('gm'),
blind: !game.user.isGM,
user: game.user.data._id,
type: CONST.CHAT_MESSAGE_TYPES.WHISPER,
speaker: { alias: game.i18n.localize(`${this.MODULE_NAME}.MESSAGE_HEADER`) },
content: html,
}
const messageData = {
whisper: ChatMessage.getWhisperRecipients('gm'),
blind: !game.user.isGM,
user: game.user.data._id,
type: CONST.CHAT_MESSAGE_TYPES.WHISPER,
speaker: { alias: game.i18n.localize(`${this.MODULE_NAME}.MESSAGE_HEADER`) },
content: html,
}
however, the created chat message is visible plain as day to the creator It looks to me like ChatMessage.isVisible makes a chat message visible to the creating user always (comments mine):
get visible() {
// if this has whisper recipients
if ( this.data.whisper.length ) {
// if its a roll, always yes (`isContentVisible` has more rules)
if ( this.data.type === CONST.CHAT_MESSAGE_TYPES.ROLL ) return true;

// if this chat message's user is the same as the logged in user --> true
// or if the logged in user matches one of the recipients
return (this.data.user === game.user.id) || (this.data.whisper.indexOf(game.user.id) !== -1);
}
return true;
}
get visible() {
// if this has whisper recipients
if ( this.data.whisper.length ) {
// if its a roll, always yes (`isContentVisible` has more rules)
if ( this.data.type === CONST.CHAT_MESSAGE_TYPES.ROLL ) return true;

// if this chat message's user is the same as the logged in user --> true
// or if the logged in user matches one of the recipients
return (this.data.user === game.user.id) || (this.data.whisper.indexOf(game.user.id) !== -1);
}
return true;
}
Trying to feed the api the GM's user id as speaker makes an error that the user lacks permission
C
Calego932d ago
Looks like this isn't strictly possible... https://gitlab.com/foundrynet/foundryvtt/-/issues/4317
GitLab
Suggestion: Private GM / Blind / Self Roll should also apply to cha...
Currently, if you just type some text into the chat box (i.e. not a roll), it does not honour the current default roll setting (public, private, blind, self)....
C
Calego932d ago
workaround time
M
Mana932d ago
You need to hook into renderChatMessage and do html.remove() for non-GMs or something. Or possibly just hide them, in case Foundry gets huffy about the DOM element being missing.
C
Calego932d ago
If I put a flag to help distinguish which cards are mine, I can catch them in a renderChatMessage hook and nuke them yeah. Hiding them is probably a better play which would be easiest if I can set a class on the overall chat message instead of just its contents cssClass on messageData? noope :has would solve me... https://caniuse.com/css-has
M
Mana932d ago
renderChatMessage happens before the chat message is actually visible, so as long as you aren't turning the hook async, you can modify it all you like before it gets shown.
C
Calego920d ago
Yeah I ended up adding a class to the html in the hook if the message has my flag. It's annoying to me that I need to make code which runs on every message to affect only mine though. I gave my thumbsup to the issue I linked. @drl2 you might find this thread insightful
Want results from more Discord servers?
Add your server
More Posts
compendium shennaneginsTIL about `CompendiumContent.getDocuments` taking nedb queries. ``` game.packs.get('dnd5e.heroes').gwith just a parent class and the class name, is there a way to instantiate a new class?JamesB and @veterini have a question for y'all in #coc7-dev https://discord.com/channels/7323252527More Hooks 5ehttps://github.com/ElfFriend-DnD/foundryvtt-more-hooks-5e I'm going to try to use this library to hacreateEmbeddedDocuments issueI'm going to throw my code in a thread so I don't clutter this channel up with a wall of textBase Item@otigon it occurs to me that the new `baseItem` property on weapons and such is probably of interestCompendium loadinghmm ghost, I added some console.time tags here and there to measure the difference between loading oSkill and Ability bonusesA massive enhancement of Skills and Ability Checks/Saves allows them to be individually affected by 150 Sheet Changes@sdenec @lordzeel Sheet Changes required: - New Cog-menu for Ability Scores and Skills to support neDocumentData shennaneginsTIL: It is possible to `update` an Actor or Item's `data.data` with arbitrary information that isn'tflag shenanneginsTIL you can set the `flags` key on a document to whatever you want to (e.g. a string). This is a surraaeAfter some discussion yesterday in #active-effects , I decided to try to create a system-agnostic modevMode json changed warningI checked the module repo and I honestly can't figure out where I would plug in my code. I'd be guesS3 File Picker SettingsCan someone with an S3 configuration give me a test of the FilePicker settings api and tell me if a item preCreate@sol.folango @mrprimate (pinging you two in particular because you do import stuff involving existinItem Macro Compendium WorkflowOkay, here's a long one that's a bit of a doozy. I'm looking at setting up some sort of tooling/workItem Specific Crit DetailsOh that critical hit thing is gonna hit MRE too isn't it... hrm...1.5.x 72%@dnd5e No action required (but suggested 🙂 ) The 1.5.0 milestone is ~72% complete. It has a due daV9 Tabs IssueIf you never figured this out, here's why this happened: A small change in `Tabs` during v9 causes sDeck Creation MacroI created a macro to fill out a 52-card deck, you set the ID of the deck and the base URL of the foldevmode-issues@arcanist figured out, the flex layout elements have `pointer-events: none`, so anything injected wi