From e0ce7d1e339678b3508844802982f29477c34009 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 15 Apr 2021 01:14:24 +0200 Subject: [PATCH] =?UTF-8?q?Suppression=20des=20messages=20pour=20les=20obj?= =?UTF-8?q?ets=20pay=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/chat-utility.js | 45 ++++++++++++++++++++++++++++-------------- module/misc.js | 5 ++--- module/rdd-utility.js | 20 ++++++++++++++++++- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/module/chat-utility.js b/module/chat-utility.js index 7e95b705..38cc2733 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -1,3 +1,4 @@ +import { Misc } from "./misc.js"; /** * Class providing helper methods to get the list of users, and @@ -7,31 +8,45 @@ export class ChatUtility { /* -------------------------------------------- */ static onSocketMessage(sockmsg) { switch (sockmsg.msg) { - case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.part, sockmsg.gmId); + case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.data); } } /* -------------------------------------------- */ - static onRemoveMessages(part, gmId) { - if (game.user.id == gmId) { - const toDelete = game.messages.filter(it => it.data.content.includes(part)); - toDelete.forEach(it => it.delete()); + static onRemoveMessages(data) { + if (game.user.isGM || game.user.id == data.gmId) { + if (data.part){ + const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); + toDelete.forEach(it => it.delete()); + } + if (data.messageId){ + game.messages.get(data.messageId)?.delete(); + } } } - + /* -------------------------------------------- */ static removeChatMessageContaining(part) { - const gmId = game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id; + const removeMessageData = { + part: part, + gmId: Misc.connectedGM() + }; - if (!gmId || game.user.isGM) { - ChatUtility.onRemoveMessages(part, game.user.id); + if (game.user.isGM) { + ChatUtility.onRemoveMessages(removeMessageData); } else { - game.socket.emit("system.foundryvtt-reve-de-dragon", { - msg: "msg_delete_chat_message", data: { - part:part, - gmId: gmId, - }}); + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: removeMessageData }); + } + } + + static removeChatMessageId(messageId) { + const removeMessageData = { messageId: messageId, gmId: Misc.connectedGM() }; + if (game.user.isGM) { + ChatUtility.onRemoveMessages(removeMessageData); + } + else { + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: removeMessageData }); } } @@ -108,5 +123,5 @@ export class ChatUtility { ChatMessage.create(data); } } - + } diff --git a/module/misc.js b/module/misc.js index 1d71fab7..2faa6f8d 100644 --- a/module/misc.js +++ b/module/misc.js @@ -114,8 +114,7 @@ export class Misc { return Misc.data(it)?.data ?? {} } - static connectedGM() - { - return game.users.entities.find(u => u.isGM && u.active)?.id; + static connectedGM() { + return game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id; } } \ No newline at end of file diff --git a/module/rdd-utility.js b/module/rdd-utility.js index d1dd170a..bb5ed094 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -543,11 +543,29 @@ export class RdDUtility { // TODO: diminuer la quantité ou supprimer le message // message: => document.querySelector("#chat-log > li:nth-child(61) > div > div > span > a") // => ../../../..[@data-message-id] - + let chatMessageId = RdDUtility.findChatMessageId(event.currentTarget); + if (chatMessageId) { + ChatUtility.removeChatMessageId(chatMessageId); + } } }); } + static findChatMessageId(current) { + const isChatMessageWithId = it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'); + return RdDUtility.findNodeMatching(current, isChatMessageWithId)?.attributes.getNamedItem('data-message-id').value; + } + + static findNodeMatching(current, predicate) { + if (current) { + if (predicate(current)) { + return current; + } + return RdDUtility.findNodeMatching(current.parentElement, predicate); + } + return undefined; + } + static getSelectedActor(msgPlayer = '') { if (canvas.tokens.controlled.length == 1) { let token = canvas.tokens.controlled[0];