From b01a3c5554f8b8b7064343f5bb9ae874c4932133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Tue, 17 Aug 2021 17:20:53 +0200 Subject: [PATCH 1/3] Hide reply mention button from current user --- .../common/messaging/bars/ReplyBar.tsx | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/components/common/messaging/bars/ReplyBar.tsx b/src/components/common/messaging/bars/ReplyBar.tsx index a327f161..a5c94ed2 100644 --- a/src/components/common/messaging/bars/ReplyBar.tsx +++ b/src/components/common/messaging/bars/ReplyBar.tsx @@ -14,6 +14,8 @@ import { getRenderer } from "../../../../lib/renderer/Singleton"; import { dispatch, getState } from "../../../../redux"; import { Reply } from "../../../../redux/reducers/queue"; +import { useClient } from "../../../../context/revoltjs/RevoltClient"; + import IconButton from "../../../ui/IconButton"; import Markdown from "../../../markdown/Markdown"; @@ -95,6 +97,7 @@ export default observer(({ channel, replies, setReplies }: Props) => { ); }, [replies, setReplies]); + const client = useClient(); const renderer = getRenderer(channel); if (renderer.state !== "RENDER") return null; @@ -153,34 +156,36 @@ export default observer(({ channel, replies, setReplies }: Props) => { - { - let state = false; - setReplies( - replies.map((_, i) => { - if (i === index) { - state = !_.mention; - return { - ..._, - mention: !_.mention, - }; - } + {message.author_id !== client.user!._id && ( + { + let state = false; + setReplies( + replies.map((_, i) => { + if (i === index) { + state = !_.mention; + return { + ..._, + mention: !_.mention, + }; + } - return _; - }), - ); + return _; + }), + ); - dispatch({ - type: "SECTION_TOGGLE_SET", - id: "mention", - state, - }); - }}> - - {" "} - {reply.mention ? "ON" : "OFF"} - - + dispatch({ + type: "SECTION_TOGGLE_SET", + id: "mention", + state, + }); + }}> + + {" "} + {reply.mention ? "ON" : "OFF"} + + + )} setReplies( From 29ed48fa706ec554ebcea873e73e2cec7bd0e302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Tue, 17 Aug 2021 17:29:25 +0200 Subject: [PATCH 2/3] Disable mention behavior on self-replies --- .../common/messaging/bars/ReplyBar.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/common/messaging/bars/ReplyBar.tsx b/src/components/common/messaging/bars/ReplyBar.tsx index a5c94ed2..5ed804a2 100644 --- a/src/components/common/messaging/bars/ReplyBar.tsx +++ b/src/components/common/messaging/bars/ReplyBar.tsx @@ -104,6 +104,25 @@ export default observer(({ channel, replies, setReplies }: Props) => { const ids = replies.map((x) => x.id); const messages = renderer.messages.filter((x) => ids.includes(x._id)); + useEffect(() => { + let mentionsChanged = false; + const modified = replies.map((reply) => { + const message = messages.find((x) => reply.id === x._id); + if (message?.author_id === client.user!._id && reply.mention) { + mentionsChanged = true; + return { + ...reply, + mention: false, + }; + } + + return reply; + }); + if (mentionsChanged) { + setReplies(modified); + } + }, [replies, setReplies, client.user, messages]); + return (
{replies.map((reply, index) => { From 5ab1773f01e0003c2b519a7a06827ff2bfdb349f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Tue, 17 Aug 2021 20:52:11 +0200 Subject: [PATCH 3/3] Moved reply mention disable into internal event handler --- .../common/messaging/bars/ReplyBar.tsx | 60 ++++++++----------- src/lib/ContextMenus.tsx | 6 +- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/src/components/common/messaging/bars/ReplyBar.tsx b/src/components/common/messaging/bars/ReplyBar.tsx index 5ed804a2..1b83430d 100644 --- a/src/components/common/messaging/bars/ReplyBar.tsx +++ b/src/components/common/messaging/bars/ReplyBar.tsx @@ -3,6 +3,7 @@ import { File, XCircle } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; import { SYSTEM_USER_ID } from "revolt.js"; import { Channel } from "revolt.js/dist/maps/Channels"; +import { Message } from "revolt.js/dist/maps/Messages"; import styled from "styled-components"; import { Text } from "preact-i18n"; @@ -80,49 +81,36 @@ const Base = styled.div` // ! FIXME: Move to global config const MAX_REPLIES = 4; export default observer(({ channel, replies, setReplies }: Props) => { - useEffect(() => { - return internalSubscribe( - "ReplyBar", - "add", - (id) => - replies.length < MAX_REPLIES && - !replies.find((x) => x.id === id) && - setReplies([ - ...replies, - { - id: id as string, - mention: getState().sectionToggle.mention ?? false, - }, - ]), - ); - }, [replies, setReplies]); - const client = useClient(); + + useEffect(() => { + return internalSubscribe("ReplyBar", "add", (_message) => { + const message = _message as Message; + if ( + replies.length >= MAX_REPLIES || + replies.find((x) => x.id === message._id) + ) + return; + + setReplies([ + ...replies, + { + id: message._id, + mention: + message.author_id === client.user!._id + ? false + : getState().sectionToggle.mention ?? false, + }, + ]); + }); + }, [replies, setReplies, client.user]); + const renderer = getRenderer(channel); if (renderer.state !== "RENDER") return null; const ids = replies.map((x) => x.id); const messages = renderer.messages.filter((x) => ids.includes(x._id)); - useEffect(() => { - let mentionsChanged = false; - const modified = replies.map((reply) => { - const message = messages.find((x) => reply.id === x._id); - if (message?.author_id === client.user!._id && reply.mention) { - mentionsChanged = true; - return { - ...reply, - mention: false, - }; - } - - return reply; - }); - if (mentionsChanged) { - setReplies(modified); - } - }, [replies, setReplies, client.user, messages]); - return (
{replies.map((reply, index) => { diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx index 1898024d..dc27ea14 100644 --- a/src/lib/ContextMenus.tsx +++ b/src/lib/ContextMenus.tsx @@ -79,7 +79,7 @@ type Action = | { action: "retry_message"; message: QueuedMessage } | { action: "cancel_message"; message: QueuedMessage } | { action: "mention"; user: string } - | { action: "reply_message"; id: string } + | { action: "reply_message"; target: Message } | { action: "quote_message"; content: string } | { action: "edit_message"; id: string } | { action: "delete_message"; target: Message } @@ -246,7 +246,7 @@ function ContextMenus(props: Props) { case "reply_message": { - internalEmit("ReplyBar", "add", data.id); + internalEmit("ReplyBar", "add", data.target); } break; @@ -695,7 +695,7 @@ function ContextMenus(props: Props) { if (message && !queued) { generateAction({ action: "reply_message", - id: message._id, + target: message, }); if (