diff --git a/src/components/common/messaging/bars/PinnedMessage.tsx b/src/components/common/messaging/bars/PinnedMessage.tsx
index 39bea70a..8919ef74 100644
--- a/src/components/common/messaging/bars/PinnedMessage.tsx
+++ b/src/components/common/messaging/bars/PinnedMessage.tsx
@@ -282,8 +282,8 @@ export default observer(
const unhide = () => setHidden(false);
const renderer = getRenderer(channel);
useEffect(() => {
- // Subscribe to the update event for pinned messages
- const unsubscribe = internalSubscribe(
+ // Subscribe to the update and delete events for pinned messages
+ const unsubscribeUpdate = internalSubscribe(
"PinnedMessage",
"update",
(newMessage: unknown) => {
@@ -294,8 +294,22 @@ export default observer(
}
);
- // Cleanup subscription on unmount
- return () => unsubscribe();
+ const unsubscribeDelete = internalSubscribe(
+ "PinnedMessage",
+ "delete",
+ (deletedMessageId: unknown) => {
+ const message = deletedMessageId as MessageI;
+ renderer.pinned_messages = renderer.pinned_messages.filter(
+ (msg) => msg._id !== deletedMessageId
+ );
+ }
+ );
+
+ // Cleanup subscriptions on unmount
+ return () => {
+ unsubscribeUpdate();
+ unsubscribeDelete();
+ };
}, [renderer]);
diff --git a/src/controllers/modals/components/DeleteMessage.tsx b/src/controllers/modals/components/DeleteMessage.tsx
index 29f94746..3358707d 100644
--- a/src/controllers/modals/components/DeleteMessage.tsx
+++ b/src/controllers/modals/components/DeleteMessage.tsx
@@ -3,6 +3,7 @@ import { Text } from "preact-i18n";
import { ModalForm } from "@revoltchat/ui";
import Message from "../../../components/common/messaging/Message";
+import { internalEmit } from "../../../lib/eventEmitter";
import { ModalProps } from "../types";
/**
@@ -29,8 +30,9 @@ export default function DeleteMessage({
element: ,
},
}}
- callback={() => target.delete()}
- submit={{
+ callback={() => {
+ target.delete(); internalEmit("PinnedMessage", "delete", target._id);
+ }} submit={{
palette: "error",
children: ,
}}