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

Return if receive own message #10618

Merged

Conversation

DRBragg
Copy link
Contributor

@DRBragg DRBragg commented Oct 5, 2020

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

If you have dev.to open in multiple tabs and you send a message in a chat channel you will get an unread notification in the other tabs for your own message. This PR fixes that by simply exiting from the receiveNewMessage callback early if the message received is your own (same user id).

Possible related refactoring: the receiveNewMessage function already had a few checks that I think were supposed to solve this exact issue but didn't. We may be able to adjust or remove them completely but I would want someone who is more familiar with this feature (preact & pusher) to look at it first and make sure I'm not messing something else up.

receiveNewMessage = (e) => {
    if (
      (window.location.pathname.startsWith('/connect') &&
        e.user_id === window.currentUser.id &&
        e.channel_type !== 'direct') ||
      window.location.pathname.includes(e.chat_channel_adjusted_slug)
    ) {
      return;
    }
    /// rest of function excluded
}

Basically the function returns if the user: is already in the chat area ('/connect') AND is the same user that sent the message AND the message is for a non-direct channel. I don't see any reason why we wouldn't just return if the user is the same user that sent the message.

receiveNewMessage = (e) => {
    if (
      e.user_id === window.currentUser.id ||
      window.location.pathname.includes(e.chat_channel_adjusted_slug)
    ) {
      return;
    }
    /// rest of function excluded
}

Related Tickets & Documents

Fixes issue #10606

Added tests?

  • yes
  • no, because they aren't needed
  • no, because I need help

There aren't any tests for this particular utility yet and I don't fell confident enough to start a test suite from scratch.

Added to documentation?

  • docs.forem.com
  • readme
  • no documentation needed

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 5, 2020
@CLAassistant
Copy link

CLAassistant commented Oct 5, 2020

CLA assistant check
All committers have signed the CLA.

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 6, 2020
@citizen428
Copy link
Contributor

Thanks for the PR and congrats on your first contribution to our codebase @DRBragg! 🎉

@DRBragg
Copy link
Contributor Author

DRBragg commented Oct 6, 2020

Thanks @citizen428. I was a little confused when you said "first contribution" but then I realized all my previous contributions have been helping others contribute 😅

@@ -174,8 +175,7 @@ class UnopenedChannelNotice extends Component {
<div>
{channel.request_type === 'mentioned'
? 'You got mentioned in'
: 'New Message from'}
{' '}
: 'New Message from'}{' '}
Copy link
Contributor

Choose a reason for hiding this comment

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

Prettier in action.

Copy link
Contributor

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

🚀 Thank you for your PR @DRBragg. 👏🏻

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 6, 2020
@nickytonline nickytonline merged commit 1fa54e3 into forem:master Oct 6, 2020
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Oct 6, 2020
boardfish pushed a commit to boardfish/forem that referenced this pull request Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants