diff options
Diffstat (limited to 'front/src/components/composer')
-rw-r--r-- | front/src/components/composer/Composer.tsx | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/front/src/components/composer/Composer.tsx b/front/src/components/composer/Composer.tsx index daa5af6..43d38cd 100644 --- a/front/src/components/composer/Composer.tsx +++ b/front/src/components/composer/Composer.tsx @@ -15,9 +15,11 @@ function Composer({ replying?: Poast; }) { const [loc, navigate] = useLocation(); - const { api, composerData } = useLocalState((s) => ({ + const { api, composerData, addNotification, setComposerData } = useLocalState((s) => ({ api: s.api, composerData: s.composerData, + addNotification: s.addNotification, + setComposerData: s.setComposerData, })); const our = api!.airlock.our!; const [input, setInput] = useState(replying ? `${replying}: ` : ""); @@ -39,7 +41,32 @@ function Composer({ // TODO make it user choosable const res = await api!.addPost(input); if (res) { + // Check for mentions in the post (ship names starting with ~) + const mentions = input.match(/~[a-z-]+/g); + if (mentions) { + mentions.forEach(mention => { + if (mention !== our) { // Don't notify self-mentions + addNotification({ + type: "mention", + from: our, + message: `You mentioned ${mention} in a post`, + }); + } + }); + } + + // If this is a reply, add notification + if (composerData?.type === "reply" && composerData.post?.trill?.author !== our) { + addNotification({ + type: "reply", + from: our, + message: `You replied to ${composerData.post.trill.author}'s post`, + postId: composerData.post.trill.id, + }); + } + setInput(""); + setComposerData(null); // Clear composer data after successful post toast.success("post sent"); navigate(`/feed/${our}`); } |