Bouton pour supprimer les anciens messages
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# 13.0
|
# 13.0
|
||||||
|
|
||||||
|
## 13.0.24 - Le grand oubli d'Illysis
|
||||||
|
|
||||||
|
- ajout d'un bouton pour supprimer les anciens messages du tchat
|
||||||
|
|
||||||
## 13.0.23 - Le marché d'Illysis
|
## 13.0.23 - Le marché d'Illysis
|
||||||
|
|
||||||
- Améliorations
|
- Améliorations
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { RdDTextEditor } from "./apps/rdd-text-roll-editor.js";
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class providing helper methods to get the list of users, and
|
* Class providing helper methods around the Chat message
|
||||||
*/
|
*/
|
||||||
export class ChatUtility {
|
export class ChatUtility {
|
||||||
|
|
||||||
@@ -233,7 +233,12 @@ export class ChatUtility {
|
|||||||
static async setTimestamp(chatMessage) {
|
static async setTimestamp(chatMessage) {
|
||||||
await chatMessage.setFlag(SYSTEM_RDD, 'rdd-timestamp', game.system.rdd.calendrier.getTimestamp());
|
await chatMessage.setFlag(SYSTEM_RDD, 'rdd-timestamp', game.system.rdd.calendrier.getTimestamp());
|
||||||
}
|
}
|
||||||
// TODO: find ChatLog to change the action for data-action flush
|
|
||||||
|
static getISODate(chatMessage) {
|
||||||
|
const date = new Date(chatMessage.timestamp);
|
||||||
|
return date?.toISOString().substring(0, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// async flush() {
|
// async flush() {
|
||||||
// const question = game.i18n.localize("AreYouSure");
|
// const question = game.i18n.localize("AreYouSure");
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { ChatUtility } from "../chat-utility.js"
|
||||||
|
import { Misc } from "../misc.js"
|
||||||
|
import { RdDTimestamp } from "../time/rdd-timestamp.js"
|
||||||
|
|
||||||
|
const fields = foundry.applications.fields
|
||||||
|
|
||||||
|
export class DialogFlushByDate {
|
||||||
|
|
||||||
|
static async init() {
|
||||||
|
Hooks.on("renderChatMessageHTML", async (app, html, msg) => await ChatUtility.onRenderChatMessage(app, html, msg))
|
||||||
|
Hooks.on("createChatMessage", async (chatMessage, options, id) => await ChatUtility.onCreateChatMessage(chatMessage, options, id))
|
||||||
|
Hooks.once("renderChatLog", async () => await DialogFlushByDate.onFirstRenderChatLog())
|
||||||
|
}
|
||||||
|
|
||||||
|
static async onFirstRenderChatLog() {
|
||||||
|
if (game.user.isGM) {
|
||||||
|
const content = await foundry.applications.handlebars.renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat/button-flush-by-date.hbs')
|
||||||
|
const flushButton = document.querySelector("#chat-controls button[data-action='flush']")
|
||||||
|
flushButton.insertAdjacentHTML("afterend", content)
|
||||||
|
flushButton.parentElement.querySelector("button[name='flush-by-date']")?.addEventListener(
|
||||||
|
"click", e => {
|
||||||
|
if (game.messages.size > 0) {
|
||||||
|
DialogFlushByDate.create()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui.notifications.info("Aucun message à supprimer!")
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async create() {
|
||||||
|
const dates = DialogFlushByDate.getChatMessageDates(game.messages)
|
||||||
|
|
||||||
|
const selectGroup = fields.createFormGroup({
|
||||||
|
input: fields.createSelectInput({
|
||||||
|
options: dates.map(it => { return { label: `${it.dateTerre} | ${it.dateReve}`, value: it.timestamp } }),
|
||||||
|
name: 'timestamp'
|
||||||
|
}),
|
||||||
|
label: 'Messages antérieurs au',
|
||||||
|
hint: 'Supprimer les messages antérieurs à la date'
|
||||||
|
})
|
||||||
|
|
||||||
|
const selected = await foundry.applications.api.DialogV2.input({
|
||||||
|
window: { title: "Supprimer les messages du tchat" },
|
||||||
|
content: selectGroup.outerHTML,
|
||||||
|
ok: {
|
||||||
|
label: "Supprimer",
|
||||||
|
icon: "fa-solid fa-trash-can",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (selected) {
|
||||||
|
const timestamp = Number.parseInt(selected.timestamp)
|
||||||
|
const toDelete = game.messages.filter(it => it.timestamp < timestamp)
|
||||||
|
toDelete.forEach(it => it.delete())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static getChatMessageDates(messages) {
|
||||||
|
const datesTerre = Object.values(Misc.classifyFirst(messages,
|
||||||
|
m => ChatUtility.getISODate(m),
|
||||||
|
m => DialogFlushByDate.chatMessageDates(m)))
|
||||||
|
const timestamps = new Set(datesTerre.map(it => it.timestamp))
|
||||||
|
const datesReve = Object.values(Misc.classifyFirst(messages,
|
||||||
|
m => RdDTimestamp.fromChatMessage(m).isoDate(),
|
||||||
|
m => DialogFlushByDate.chatMessageDates(m)))
|
||||||
|
const dates = [...datesTerre, ...datesReve.filter(it => !timestamps.has(it.timestamp))]
|
||||||
|
return dates.sort(Misc.ascending(it => it.timestamp))
|
||||||
|
}
|
||||||
|
|
||||||
|
static chatMessageDates(it) {
|
||||||
|
return {
|
||||||
|
timestamp: it.timestamp,
|
||||||
|
dateTerre: new Date(it.timestamp).toLocaleDateString(),
|
||||||
|
dateReve: RdDTimestamp.fromChatMessage(it).formatDate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -134,12 +134,12 @@ export class Misc {
|
|||||||
return itemsBy
|
return itemsBy
|
||||||
}
|
}
|
||||||
|
|
||||||
static classifyFirst(items, classifier) {
|
static classifyFirst(items, classifier, classified = it => it) {
|
||||||
let itemsBy = {};
|
let itemsBy = {};
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const classification = classifier(item);
|
const classification = classifier(item);
|
||||||
if (!itemsBy[classification]) {
|
if (!itemsBy[classification]) {
|
||||||
itemsBy[classification] = item;
|
itemsBy[classification] = classified(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return itemsBy;
|
return itemsBy;
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ import { Migrations } from './migrations.js'
|
|||||||
import RollDialog from "./roll/roll-dialog.mjs"
|
import RollDialog from "./roll/roll-dialog.mjs"
|
||||||
import ChatRollResult from "./roll/chat-roll-result.mjs"
|
import ChatRollResult from "./roll/chat-roll-result.mjs"
|
||||||
import ExportPdf from "./actor/export-pdf/export-pdf.mjs"
|
import ExportPdf from "./actor/export-pdf/export-pdf.mjs"
|
||||||
|
import { DialogFlushByDate } from "./chat/dialog-flush-by-date.mjs"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RdD system
|
* RdD system
|
||||||
@@ -300,6 +301,7 @@ export class SystemReveDeDragon {
|
|||||||
ExportPdf.init()
|
ExportPdf.init()
|
||||||
RollDialog.init()
|
RollDialog.init()
|
||||||
ChatRollResult.init()
|
ChatRollResult.init()
|
||||||
|
DialogFlushByDate.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
initSettings() {
|
initSettings() {
|
||||||
|
|||||||
@@ -222,6 +222,9 @@ export class RdDTimestamp {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromChatMessage(chatMessage) {
|
||||||
|
return new RdDTimestamp(chatMessage.getFlag(SYSTEM_RDD, 'rdd-timestamp'))
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Constructeur d'un timestamp.
|
* Constructeur d'un timestamp.
|
||||||
* Selon les paramètres, l'objet construit se base su:
|
* Selon les paramètres, l'objet construit se base su:
|
||||||
@@ -231,7 +234,7 @@ export class RdDTimestamp {
|
|||||||
* @param indexMinute: la minute de la journée à utiliser pour ce timestamp
|
* @param indexMinute: la minute de la journée à utiliser pour ce timestamp
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor({ indexDate, indexMinute = undefined }) {
|
constructor({ indexDate = 0, indexMinute = undefined }) {
|
||||||
this.indexDate = indexDate
|
this.indexDate = indexDate
|
||||||
this.indexMinute = indexMinute ?? 0
|
this.indexMinute = indexMinute ?? 0
|
||||||
}
|
}
|
||||||
@@ -269,6 +272,10 @@ export class RdDTimestamp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isoDate() {
|
||||||
|
return `${this.annee.paddedString(4)}-${this.mois.paddedString(2)}-${this.jour.paddedString(2)}`
|
||||||
|
}
|
||||||
|
|
||||||
formatDate() {
|
formatDate() {
|
||||||
const jour = this.jour + 1;
|
const jour = this.jour + 1;
|
||||||
const mois = RdDTimestamp.definition(this.mois).label;
|
const mois = RdDTimestamp.definition(this.mois).label;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<button type="button" class="ui-control icon fa-solid fa-trash-can" name="flush-by-date"
|
||||||
|
data-tooltip=""
|
||||||
|
aria-label="Effacer le tchat par date"
|
||||||
|
data-action="flush-by-date"></button>
|
||||||
Reference in New Issue
Block a user