Suppression des messages pour les objets payés

This commit is contained in:
Vincent Vandemeulebrouck 2021-04-15 01:14:24 +02:00
parent 94bc70a2c9
commit e0ce7d1e33
3 changed files with 51 additions and 19 deletions

View File

@ -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));
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 });
}
}

View File

@ -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;
}
}

View File

@ -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];