From ad7ebd1756956724e0b167d88f924e707401a9aa Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
Date: Thu, 18 Sep 2025 03:48:14 +0700
Subject: fuck yeah

---
 front/src/components/composer/Composer.tsx | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

(limited to 'front/src/components/composer/Composer.tsx')

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}`);
     }
-- 
cgit v1.2.3

