From 5da82f5eb7abd3a9968d6dc878b922d0dcb55a73 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Wed, 12 Apr 2023 16:08:28 +0700
Subject: [PATCH] added hide message button
---
.../channels/messages/hideMessageButton.tsx | 84 +++++++++++++++++++
src/components/channels/messages/item.tsx | 7 +-
src/pages/channels/[id].tsx | 15 +++-
3 files changed, 97 insertions(+), 9 deletions(-)
create mode 100644 src/components/channels/messages/hideMessageButton.tsx
diff --git a/src/components/channels/messages/hideMessageButton.tsx b/src/components/channels/messages/hideMessageButton.tsx
new file mode 100644
index 00000000..d6d4255c
--- /dev/null
+++ b/src/components/channels/messages/hideMessageButton.tsx
@@ -0,0 +1,84 @@
+import { RelayContext } from '@components/relaysProvider';
+
+import { dateToUnix } from '@utils/getDate';
+
+import HideIcon from '@assets/icons/hide';
+
+import * as AlertDialog from '@radix-ui/react-alert-dialog';
+import * as Tooltip from '@radix-ui/react-tooltip';
+import useLocalStorage from '@rehooks/local-storage';
+import { getEventHash, signEvent } from 'nostr-tools';
+import { useCallback, useContext } from 'react';
+
+export const HideMessageButton = ({ id }: { id: string }) => {
+ const [pool, relays]: any = useContext(RelayContext);
+ const [activeAccount]: any = useLocalStorage('activeAccount', {});
+
+ const hideMessage = useCallback(() => {
+ const event: any = {
+ content: '',
+ created_at: dateToUnix(),
+ kind: 43,
+ pubkey: activeAccount.pubkey,
+ tags: [['e', id]],
+ };
+ event.id = getEventHash(event);
+ event.sig = signEvent(event, activeAccount.privkey);
+
+ // publish note
+ pool.publish(event, relays);
+ }, [id, activeAccount.privkey, activeAccount.pubkey, pool, relays]);
+
+ return (
+
+
+
+
+
+
+
+
+
+
+ Hide this message
+
+
+
+
+
+
+
+
+ Are you absolutely sure?
+
+ This action cannot be undone. This will permanently hide this message and you will never see this again
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/src/components/channels/messages/item.tsx b/src/components/channels/messages/item.tsx
index ecc5d39d..7aae21ac 100644
--- a/src/components/channels/messages/item.tsx
+++ b/src/components/channels/messages/item.tsx
@@ -1,9 +1,8 @@
+import { HideMessageButton } from '@components/channels/messages/hideMessageButton';
import { MuteButton } from '@components/channels/messages/muteButton';
import { ReplyButton } from '@components/channels/messages/replyButton';
import { MessageUser } from '@components/chats/messageUser';
-import HideIcon from '@assets/icons/hide';
-
import { memo } from 'react';
const ChannelMessageItem = ({ data }: { data: any }) => {
@@ -22,9 +21,7 @@ const ChannelMessageItem = ({ data }: { data: any }) => {
diff --git a/src/pages/channels/[id].tsx b/src/pages/channels/[id].tsx
index 1a02c121..1cd62f1d 100644
--- a/src/pages/channels/[id].tsx
+++ b/src/pages/channels/[id].tsx
@@ -32,6 +32,7 @@ export default function Page() {
const resetChannelReply = useResetAtom(channelReplyAtom);
const muted = useRef(new Set());
+ const hided = useRef(new Set());
useEffect(() => {
// reset channel reply
@@ -41,12 +42,12 @@ export default function Page() {
[
{
authors: [activeAccount.pubkey],
- kinds: [44],
+ kinds: [43, 44],
since: 0,
},
{
'#e': [id],
- kinds: [42, 43],
+ kinds: [42],
since: 0,
},
],
@@ -54,8 +55,14 @@ export default function Page() {
(event: any) => {
if (event.kind === 44) {
muted.current = muted.current.add(event.tags[0][1]);
- } else if (event.kind === 42) {
- if (!muted.current.has(event.pubkey)) {
+ } else if (event.kind === 43) {
+ hided.current = hided.current.add(event.tags[0][1]);
+ } else {
+ if (muted.current.has(event.pubkey)) {
+ console.log('muted');
+ } else if (hided.current.has(event.id)) {
+ console.log('hided');
+ } else {
setMessages((messages) => [event, ...messages]);
}
}