-
Notifications
You must be signed in to change notification settings - Fork 13.7k
regression: unread banner appears for thread messages after channel creation #36331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ export const useHandleUnread = ( | |
| const getMessage = Messages.use((state) => state.get); | ||
| const findFirstMessage = Messages.use((state) => state.findFirst); | ||
| const filterMessages = Messages.use((state) => state.filter); | ||
| const messagesCount = Messages.use((state) => state.records.size); | ||
|
|
||
| if (!chat) { | ||
| throw new Error('No ChatContext provided'); | ||
|
|
@@ -73,8 +74,9 @@ export const useHandleUnread = ( | |
| return; | ||
| } | ||
| setMessageJumpQueryStringParameter(message?._id); | ||
| chat.readStateManager.markAsRead(); | ||
| setUnreadCount(0); | ||
| }, [room._id, setUnreadCount, findFirstMessage, unread?.since]); | ||
| }, [room._id, setUnreadCount, findFirstMessage, unread?.since, chat.readStateManager]); | ||
|
|
||
| const handleMarkAsReadButtonClick = useCallback(() => { | ||
| chat.readStateManager.markAsRead(); | ||
|
|
@@ -181,6 +183,22 @@ export const useHandleUnread = ( | |
| [getMessage, setUnreadCount], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we find an alternative to this use effect? As it is, this is going to run every time the messagesCount prop changes (basically on every message). It seems costly for an operation that only needs to happen when the room is initialized.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this will run only once. In first run, the lastMessageDate will be set and there is a check to return early when lastMessageDate is set.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this is not expensive tasks. It is used only at one or two places all over the client. Plus it only runs once and loops around few messages. Next runs, it returns early. I dont think it is expensive. |
||
| // When a room is first opened, there’s no “off-screen” message yet, so we set | ||
| // an initial baseline timestamp (the newest message’s ts) as our anchor. | ||
| // This ensures our unread-count logic only starts counting messages that arrive | ||
| // after the initial load, rather than everything already in the DOM. | ||
| if (lastMessageDate === undefined && messagesCount > 0) { | ||
| const newest = findFirstMessage( | ||
| (r) => r.rid === room._id, | ||
| (a, b) => b.ts.getTime() - a.ts.getTime(), | ||
| ); | ||
| if (newest) { | ||
| setLastMessageDate(newest.ts); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid changing the value of a state that is in the dependency list
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. |
||
| } | ||
| } | ||
| }, [messagesCount, lastMessageDate, findFirstMessage, room._id]); | ||
|
|
||
| return { | ||
| innerRef: ref, | ||
| wrapperRef: messagesBoxRef, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed to be a fix for me. While clicking on the banner, It would take me to message. But when page is refreshed, the banner would reapper.