Simplify ChatMessage whispers
Les messages dans les TMRs sont envoyés au GM Simplification des messages de tchat liés à un actor: on peut utiliser les Owners (car les GMs sont owner). Au lieu de passer le name de l'Actor (qui peut être incorrect si deux actors ont le même, mais pas les mêmes propriétaires), on passe directement l'actor pour déterminer mles destinataires de messages
This commit is contained in:
@ -8,15 +8,20 @@ import { RdDTimestamp } from "./time/rdd-timestamp.js";
|
||||
*/
|
||||
export class ChatUtility {
|
||||
|
||||
static async init() {
|
||||
Hooks.on("renderChatMessage", async (app, html, msg) => await ChatUtility.onRenderChatMessage(app, html, msg))
|
||||
Hooks.on("createChatMessage", async (chatMessage, options, id) => await ChatUtility.onCreateChatMessage(chatMessage, options, id))
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static onSocketMessage(sockmsg) {
|
||||
switch (sockmsg.msg) {
|
||||
case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.data);
|
||||
case "msg_user_ui_notifications": return ChatUtility.onNotifyUser(sockmsg.data);
|
||||
case "msg_gm_chat_message": return ChatUtility.handleGMChatMessage(sockmsg.data)
|
||||
case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.data)
|
||||
case "msg_user_ui_notifications": return ChatUtility.onNotifyUser(sockmsg.data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static notifyUser(userId, level = 'info', message) {
|
||||
const socketData = {
|
||||
@ -78,77 +83,90 @@ export class ChatUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async createChatWithRollMode(name, chatOptions) {
|
||||
let rollMode = game.settings.get("core", "rollMode")
|
||||
switch (rollMode) {
|
||||
static async createChatWithRollMode(messageData, actor = undefined) {
|
||||
switch (game.settings.get("core", "rollMode")) {
|
||||
case "blindroll": // GM only
|
||||
if (!game.user.isGM) {
|
||||
ChatUtility.blindMessageToGM(chatOptions);
|
||||
|
||||
chatOptions.whisper = [game.user.id];
|
||||
chatOptions.content = "Message envoyé en aveugle au Gardien";
|
||||
ChatUtility.blindMessageToGM(messageData)
|
||||
messageData.whisper = [game.user];
|
||||
messageData.content = "Message envoyé en aveugle au Gardien"
|
||||
}
|
||||
else {
|
||||
chatOptions.whisper = ChatUtility.getUsers(user => user.isGM);
|
||||
messageData.whisper = ChatUtility.getGMs()
|
||||
}
|
||||
break;
|
||||
default:
|
||||
chatOptions.whisper = ChatUtility.getWhisperRecipients(rollMode, name);
|
||||
break;
|
||||
break
|
||||
case "gmroll":
|
||||
messageData.whisper = ChatUtility.getOwners(actor)
|
||||
break
|
||||
case "selfroll":
|
||||
messageData.whisper = [game.user]
|
||||
break
|
||||
}
|
||||
chatOptions.alias = chatOptions.alias || name;
|
||||
return await ChatMessage.create(chatOptions);
|
||||
messageData.alias = messageData.alias ?? actor?.name ?? game.user.name
|
||||
return await ChatMessage.create(messageData)
|
||||
}
|
||||
|
||||
static getOwners(document) {
|
||||
return game.users.filter(it => document.getUserLevel(it) == CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)
|
||||
}
|
||||
|
||||
static getUserAndGMs() {
|
||||
return [game.user, ...ChatUtility.getGMs()]
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static prepareChatMessage(rollMode, name) {
|
||||
return {
|
||||
user: game.user.id,
|
||||
whisper: ChatUtility.getWhisperRecipients(rollMode, name)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipients(rollMode, name) {
|
||||
switch (rollMode) {
|
||||
case "blindroll": return ChatUtility.getUsers(user => user.isGM);
|
||||
case "gmroll": return ChatUtility.getWhisperRecipientsAndGMs(name);
|
||||
case "selfroll": return [game.user.id];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
static getOwners(actor) {
|
||||
return game.users.filter(it => actor.getUserLevel(it) == CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipientsAndGMs(...names) {
|
||||
let recipients = [...ChatMessage.getWhisperRecipients('GM')]
|
||||
names.forEach(name => recipients.push(...ChatMessage.getWhisperRecipients(name)))
|
||||
return recipients
|
||||
static getMultipleActorsOwners(...actors) {
|
||||
return Misc.concat(actors.map(it => it == undefined ? [] : ChatUtility.getOwners(it)))
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getUsers(filter) {
|
||||
return game.users.filter(filter).map(user => user.id);
|
||||
return game.users.filter(filter)
|
||||
}
|
||||
|
||||
static getGMs() {
|
||||
return game.users.filter(user => user.isGM)
|
||||
}
|
||||
|
||||
static applyRollMode(chatMessageData = {}, rollMode = game.settings.get("core", "rollMode")) {
|
||||
switch (rollMode) {
|
||||
case "blindroll":
|
||||
chatMessageData.blind = true
|
||||
chatMessageData.whisper = ChatUtility.getGMs()
|
||||
break
|
||||
case "gmroll":
|
||||
chatMessageData.whisper = ChatUtility.getGMs()
|
||||
chatMessageData.blind = false
|
||||
break
|
||||
case "roll":
|
||||
chatMessageData.whisper = ChatUtility.getUsers(user => user.active)
|
||||
chatMessageData.blind = false
|
||||
break
|
||||
case "selfroll":
|
||||
chatMessageData.whisper = [game.user]
|
||||
chatMessageData.blind = false
|
||||
break
|
||||
}
|
||||
return chatMessageData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static blindMessageToGM(chatOptions) {
|
||||
let chatGM = foundry.utils.duplicate(chatOptions);
|
||||
chatGM.whisper = ChatUtility.getUsers(user => user.isGM);
|
||||
chatGM.content = "Message aveugle de " + game.user.name + "<br>" + chatOptions.content;
|
||||
console.log("blindMessageToGM", chatGM);
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_gm_chat_message", data: chatGM });
|
||||
const chatGM = foundry.utils.duplicate(chatOptions)
|
||||
chatGM.content = "Message aveugle de " + game.user.name + "<br>" + chatOptions.content
|
||||
console.log("blindMessageToGM", chatGM)
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_gm_chat_message", data: chatGM })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static handleGMChatMessage(socketData) {
|
||||
console.log("blindMessageToGM", socketData);
|
||||
if (game.user.isGM) { // message privé pour GM only
|
||||
socketData.user = game.user.id;
|
||||
ChatMessage.create(socketData);
|
||||
if (Misc.firstConnectedGM()) {
|
||||
ChatMessage.create({
|
||||
user: game.user.id,
|
||||
whisper: ChatUtility.getGMs(),
|
||||
content: socketData.content
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user