From 6acaaf956e4f147fbcfddb691633b91e4bc0a71b Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sat, 2 Mar 2024 19:28:42 -0500 Subject: [PATCH] fix bug with message list hasMore persisting --- src-tauri/.idea/workspace.xml | 148 +++++++++++++++++++++++ src/components/messaging/MessageList.tsx | 40 +++--- 2 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 src-tauri/.idea/workspace.xml diff --git a/src-tauri/.idea/workspace.xml b/src-tauri/.idea/workspace.xml new file mode 100644 index 0000000..eaa9a70 --- /dev/null +++ b/src-tauri/.idea/workspace.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 4 +} + + + + + + + + + + + 1709176435458 + + + + + + \ No newline at end of file diff --git a/src/components/messaging/MessageList.tsx b/src/components/messaging/MessageList.tsx index 7598e47..94d39b0 100644 --- a/src/components/messaging/MessageList.tsx +++ b/src/components/messaging/MessageList.tsx @@ -44,25 +44,34 @@ function MessageList({ guild, channel }: Props) { const ref = React.useRef(null); const { width } = useResizeObserver({ ref }); - // handles the permission check React.useEffect(() => { const permission = Permissions.getPermission(app.account!.id, guild, channel); - setCanView(permission.has("READ_MESSAGE_HISTORY")); - }, [guild, channel]); + const hasPermission = permission.has("READ_MESSAGE_HISTORY"); + setCanView(hasPermission); + + if (!hasPermission) { + logger.debug("User cannot view this channel. Aborting initial message fetch."); + return; + } - // handles the initial fetch of channel messages - React.useEffect(() => { - if (!canView) return; if (guild && channel && channel.messages.count === 0) { channel.getMessages(app, true).then((r) => { - if (r !== 50) setHasMore(false); - else setHasMore(true); + if (r < 50) { + setHasMore(false); + } }); } - }, [guild, channel, canView]); + + return () => { + logger.debug("MessageList unmounted"); + setHasMore(true); + setCanView(false); + }; + }, [guild, channel]); const fetchMore = React.useCallback(() => { if (!channel.messages.count) { + logger.warn("channel has no messages, aborting!"); return; } // get last group @@ -77,16 +86,17 @@ function MessageList({ guild, channel }: Props) { const before = lastGroup.messages[0].id; logger.debug(`Fetching 50 messages before ${before} for channel ${channel.id}`); channel.getMessages(app, false, 50, before).then((r) => { - if (r !== 50) setHasMore(false); - else setHasMore(true); + if (r < 50) { + setHasMore(false); + } }); - }, [channel, messageGroups, setHasMore]); + }, [channel, messageGroups]); const renderGroup = React.useCallback( (group: MessageGroupType) => ( ), - [], + [messageGroups], ); return ( @@ -110,11 +120,13 @@ function MessageList({ guild, channel }: Props) { display: "flex", justifyContent: "center", alignContent: "center", - marginBottom: 30, + margin: 30, }} color="var(--primary)" /> } + // FIXME: seems to be broken in react-infinite-scroll-component when using inverse + scrollThreshold={0.5} scrollableTarget="scrollable-div" endMessage={