Skip to content

Commit

Permalink
馃洜 fixed channels having ncorrect Read status
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Sep 27, 2022
1 parent 2c33d9c commit ea94835
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions twake/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"react-i18next": "^11.15.3",
"react-moment": "^0.9.7",
"react-outside-click-handler": "^1.3.0",
"react-page-visibility": "^7.0.0",
"react-perfect-scrollbar": "^1.5.8",
"react-player": "^2.10.1",
"react-redux": "^7.2.0",
Expand Down Expand Up @@ -270,6 +271,7 @@
"@types/draft-js": "^0.11.2",
"@types/is-url": "^1.2.28",
"@types/markdown-draft-js": "^2.2.3",
"@types/react-page-visibility": "^6.4.1",
"babel-plugin-named-exports-order": "^0.0.2",
"craco-alias": "^2.1.1",
"eslint-plugin-storybook": "^0.5.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import User from 'app/features/users/services/current-user-service';
import { useChannelMembersReadSections } from 'app/features/channel-members/hooks/use-channel-members-read-sections';
import { delayRequest } from 'app/features/global/utils/managedSearchRequest';
import { useRefreshPublicOrPrivateChannels } from 'app/features/channels/hooks/use-public-or-private-channels';
import { usePageVisibility } from "react-page-visibility";

type Props = {
companyId: string;
Expand Down Expand Up @@ -82,13 +83,14 @@ export default ({ channelId, companyId, workspaceId, readonly }: Props) => {
};

const { refresh: refreshChannels } = useRefreshPublicOrPrivateChannels();
const isPageVisible = usePageVisibility();

useEffect(() => {
if (messages.length === 0) loadMore('history');
}, []);

useEffect(() => {
if (window.reachedEnd && atBottom && messages.length > 0 && !document.hidden) {
if (window.reachedEnd && atBottom && messages.length > 0 && isPageVisible) {
const seenMessages = messages.filter(message => {
const m = getMessage(message.id || message.threadId);
const currentUserId = User.getCurrentUserId();
Expand All @@ -110,8 +112,9 @@ export default ({ channelId, companyId, workspaceId, readonly }: Props) => {
await loadReadSections();
});
}
console.debug('visibility', messages);
}
}, [messages, messages.length, window.reachedEnd, document.hidden]);
}, [messages, messages.length, window.reachedEnd, isPageVisible]);

const { highlight, cancelHighlight, reachedHighlight } = useHighlightMessage();

Expand Down Expand Up @@ -160,7 +163,7 @@ export default ({ channelId, companyId, workspaceId, readonly }: Props) => {
}, [messages.length > 0]);

useEffect(() => {
if (messages.length && workspaceId === 'direct') {
if (messages.length) {
delayRequest('message-list-load-read-sections', async () => {
loadReadSections();
});
Expand Down

0 comments on commit ea94835

Please sign in to comment.