Skip to content
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

Fix: Prevent marking messages as read when tab inactive #1927

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

really-not-lavacat
Copy link

Description

When chat in Cinny is opened in browser, but tab isn't active, Cinny marks messages in chat as read anyway, which is really confusing for the conversation partner (for conversation partner it looks like you ignore them).

This PR adds check of document.hidden. When tab is inactive, markAsRead will do nothing when calling it.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Copy link

github-actions bot commented Sep 5, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@really-not-lavacat
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

ajbura added a commit to cinnyapp/cla that referenced this pull request Sep 5, 2024
Copy link

@nekoedges nekoedges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, should not make anything bad

@greentore
Copy link
Contributor

Doesn't really work for me. I think you should use document.hasFocus() instead.

@really-not-lavacat
Copy link
Author

@greentore done! now markAsRead checks both document.hidden and document.hasFocus() (they're doing different things, so I included both checks)

@greentore
Copy link
Contributor

I can't think of situation where document.hidden and document.hasFocus() both return true at the same time, so the first one is probably redundant.

@really-not-lavacat
Copy link
Author

When I said and, I meant that I used or statement, so there's no need for both checks to return true at the same time. document.hidden and document.hasFocus()performing different checks, so I included both.

Comment on lines +4 to +7
// Won't mark messages (or whatever in room) as read when tab inactive
// or when browser is inactive (i.e. user interacts with some another app)
if (document.hidden || !document.hasFocus()) return;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a wrong place to add such conditioning as this function intent is to mark room as read. A good place for require changes would be the code where markAsRead is called (i guess in useEventArrive hook in RoomTimeline.tsx file)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are right. Thanks for suggestions, I'll rewrite my code when I'll have enough time!

@really-not-lavacat really-not-lavacat marked this pull request as draft September 29, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants