From 5b6c77497f20a4be9df5fc6e267c443ee9caad55 Mon Sep 17 00:00:00 2001 From: WombatFromHell Date: Sat, 3 Oct 2020 23:54:07 -0600 Subject: [PATCH] Don't detect matches on self-posts --- src/core/notifications.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/notifications.ts b/src/core/notifications.ts index 14e0f3f2..7ab91aa1 100644 --- a/src/core/notifications.ts +++ b/src/core/notifications.ts @@ -88,20 +88,21 @@ const matchNotification = async (nEvent: NotifyEvent) => { const loggedInUsername = (await getUsername())?.toLowerCase(); const matches = (await getSetting("notifications")) as string[]; const parentAuthor = nEvent?.eventData?.parentAuthor?.toLowerCase(); + const postAuthor = nEvent?.eventData?.post?.author?.toLowerCase(); const postEventBody = nEvent?.eventData?.post?.body?.toLowerCase(); const postEventHasMe = postEventBody?.includes(loggedInUsername); const parentAuthorIsMe = parentAuthor === loggedInUsername; + const postAuthorIsMe = postAuthor === loggedInUsername; const postEventHasMatches = matches?.reduce((acc, m) => { const mToLower = m.toLowerCase(); - const matchesBody = postEventBody.indexOf(mToLower) > -1; const wasAdded = acc.find((x) => x.toLowerCase() === mToLower.trim()); // trim extra trailing space from phrase matches for posterity - if (!parentAuthorIsMe && matchesBody && !wasAdded) acc.push(m.trim()); + if (postEventBody.indexOf(mToLower) > -1 && !wasAdded) acc.push(m.trim()); return acc; }, [] as string[]); if (postEventHasMe) return "Someone mentioned your name."; else if (parentAuthorIsMe) return "Someone replied to you."; - else if (arrHas(postEventHasMatches)) { + else if (!postAuthorIsMe && arrHas(postEventHasMatches)) { const message = `Someone mentioned: ${postEventHasMatches.join(", ")}`; return `${message.slice(0, 115)}...`; } else return null;