LOEFD
Join ServerBlind 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?
What I've got:
however, the created chat message is visible plain as day to the creator
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;
}
Trying to feed the api the GM's user id as
speaker
makes an error that the user lacks permissionworkaround time
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.
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-hasrenderChatMessage 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.
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.
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