Skip to content

Node.js based forum software built for the modern web

fix: add dedicated purge button to chat messages, same patter as posts

Barış Soner Uşaklıcdde44e5013a
diff --git a/public/language/en-GB/modules.json b/public/language/en-GB/modules.json
index c3a0f3ee20..e3049b1b1e 100644
--- a/public/language/en-GB/modules.json
+++ b/public/language/en-GB/modules.json
@@ -34,6 +34,7 @@
"chat.thirty-days": "30 Days",
"chat.three-months": "3 Months",
"chat.delete-message-confirm": "Are you sure you wish to delete this message?",
+ "chat.purge-message-confirm": "Are you sure you wish to permanently delete this message?",
"chat.retrieving-users": "Retrieving users...",
"chat.view-users-list": "View users list",
"chat.pinned-messages": "Pinned Messages",
diff --git a/public/scss/chats.scss b/public/scss/chats.scss
index 02193d9af0..b030ad5f75 100644
--- a/public/scss/chats.scss
+++ b/public/scss/chats.scss
@@ -68,7 +68,7 @@ body.page-user-chats {
opacity: 0;
transition: $transition-fade;
&:has([aria-expanded="true"]) { opacity: 1; }
- [data-action="restore"], [data-action="unpin"] { display: none; }
+ [data-action="restore"], [data-action="unpin"], [data-action="purge"] { display: none; }
}
&:hover {
.controls { opacity: 1; }
@@ -78,7 +78,7 @@ body.page-user-chats {
.message-body { opacity: 0.3; }
.message-body-wrapper .controls {
[data-action] { display: none; }
- [data-action="restore"] { display: block; }
+ [data-action="restore"], [data-action="purge"] { display: block; }
}
}
&.pinned {
diff --git a/public/src/client/chats.js b/public/src/client/chats.js
index a1a9851267..8bb2a8aff5 100644
--- a/public/src/client/chats.js
+++ b/public/src/client/chats.js
@@ -499,6 +499,9 @@ define('forum/chats', [
case 'restore':
messages.restore(messageId, roomId);
break;
+ case 'purge':
+ messages.purge(messageId, roomId);
+ break;
case 'pin':
pinnedMessages.pin(messageId, roomId);
break;
diff --git a/public/src/client/chats/messages.js b/public/src/client/chats/messages.js
index 0f9bb92124..0494b5b35d 100644
--- a/public/src/client/chats/messages.js
+++ b/public/src/client/chats/messages.js
@@ -418,17 +418,29 @@ define('forum/chats/messages', [
return;
}
- api.del(`/chats/${roomId}/messages/${encodeURIComponent(messageId)}`, {}).then(() => {
+ api.del(`/chats/${roomId}/messages/${encodeURIComponent(messageId)}/state`, {}).then(() => {
components.get('chat/message', messageId).toggleClass('deleted', true);
}).catch(alerts.error);
});
};
messages.restore = function (messageId, roomId) {
- api.post(`/chats/${roomId}/messages/${encodeURIComponent(messageId)}`, {}).then(() => {
+ api.put(`/chats/${roomId}/messages/${encodeURIComponent(messageId)}/state`, {}).then(() => {
components.get('chat/message', messageId).toggleClass('deleted', false);
}).catch(alerts.error);
};
+ messages.purge = function (messageId, roomId) {
+ modals.confirm('[[modules:chat.purge-message-confirm]]', function (ok) {
+ if (!ok) {
+ return;
+ }
+
+ api.del(`/chats/${roomId}/messages/${encodeURIComponent(messageId)}`, {}).then(() => {
+ components.get('chat/message', messageId).remove();
+ }).catch(alerts.error);
+ });
+ };
+
return messages;
});
diff --git a/src/views/partials/chats/message.tpl b/src/views/partials/chats/message.tpl
index 216c7b5878..779c311b75 100644
--- a/src/views/partials/chats/message.tpl
+++ b/src/views/partials/chats/message.tpl
@@ -37,6 +37,9 @@
<li>
<a href="#" class="dropdown-item rounded-1" data-action="delete" role="menuitem"><span class="d-inline-flex align-items-center gap-2"><i class="fa fa-fw fa-trash text-muted"></i> {{tx("topic:delete")}}</span></a>
</li>
+ <li>
+ <a href="#" class="dropdown-item rounded-1" data-action="purge" role="menuitem"><span class="d-inline-flex align-items-center gap-2"><i class="fa fa-fw fa-eraser text-muted"></i> {{tx("topic:purge")}}</span></a>
+ </li>
<li>
<a href="#" class="dropdown-item rounded-1" data-action="restore" role="menuitem"><span class="d-inline-flex align-items-center gap-2"><i class="fa fa-fw fa-repeat text-muted"></i> {{tx("topic:restore")}}</span></a>
</li>