From 74f8390f1d879350ebb6516fade2b1d83d1601e7 Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Wed, 8 Nov 2023 09:08:42 -0800
Subject: Move muted threads to new persistence + context (#1838)

---
 src/view/com/posts/FeedItem.tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/view/com/posts/FeedItem.tsx')

diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx
index aeee3e20a..772bb2561 100644
--- a/src/view/com/posts/FeedItem.tsx
+++ b/src/view/com/posts/FeedItem.tsx
@@ -33,6 +33,7 @@ import {isEmbedByEmbedder} from 'lib/embeds'
 import {MAX_POST_LINES} from 'lib/constants'
 import {countLines} from 'lib/strings/helpers'
 import {logger} from '#/logger'
+import {useMutedThreads, useToggleThreadMute} from '#/state/muted-threads'
 
 export const FeedItem = observer(function FeedItemImpl({
   item,
@@ -50,6 +51,8 @@ export const FeedItem = observer(function FeedItemImpl({
 }) {
   const store = useStores()
   const pal = usePalette('default')
+  const mutedThreads = useMutedThreads()
+  const toggleThreadMute = useToggleThreadMute()
   const {track} = useAnalytics()
   const [deleted, setDeleted] = useState(false)
   const [limitLines, setLimitLines] = useState(
@@ -114,11 +117,11 @@ export const FeedItem = observer(function FeedItemImpl({
     Linking.openURL(translatorUrl)
   }, [translatorUrl])
 
-  const onToggleThreadMute = React.useCallback(async () => {
+  const onToggleThreadMute = React.useCallback(() => {
     track('FeedItem:ThreadMute')
     try {
-      await item.toggleThreadMute()
-      if (item.isThreadMuted) {
+      const muted = toggleThreadMute(item.rootUri)
+      if (muted) {
         Toast.show('You will no longer receive notifications for this thread')
       } else {
         Toast.show('You will now receive notifications for this thread')
@@ -126,7 +129,7 @@ export const FeedItem = observer(function FeedItemImpl({
     } catch (e) {
       logger.error('Failed to toggle thread mute', {error: e})
     }
-  }, [track, item])
+  }, [track, toggleThreadMute, item])
 
   const onDeletePost = React.useCallback(() => {
     track('FeedItem:PostDelete')
@@ -360,7 +363,7 @@ export const FeedItem = observer(function FeedItemImpl({
             likeCount={item.post.likeCount}
             isReposted={!!item.post.viewer?.repost}
             isLiked={!!item.post.viewer?.like}
-            isThreadMuted={item.isThreadMuted}
+            isThreadMuted={mutedThreads.includes(item.rootUri)}
             onPressReply={onPressReply}
             onPressToggleRepost={onPressToggleRepost}
             onPressToggleLike={onPressToggleLike}
-- 
cgit 1.4.1

