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

Muted users: part 2 #4699

Merged
merged 8 commits into from May 1, 2021
Merged

Muted users: part 2 #4699

merged 8 commits into from May 1, 2021

Conversation

WesleyAC
Copy link
Contributor

The continuation of #4678. I moved the CaughtUp fix to #4698, since that's somewhat orthogonal (although this PR doesn't work terribly well without it).

All of the comments by @gnprice in #4678 should be resolved in this.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks @WesleyAC ! This looks good -- comments below, all I think pretty small.

src/webview/generateInboundEvents.js Show resolved Hide resolved
.message-muted {
.message[data-mute-state="hidden"] {
Copy link
Member

Choose a reason for hiding this comment

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

Then the rest of these first four commits (i.e. everything in those commits apart from adding the _ plumbing) would be best squashed together. That will simplify the changes quite a bit, because there's a lot of bits like this one that do one thing in an earlier commit and then go a different way in a later commit.

Which is a very natural and useful thing to do while drafting how something should work! Just when it's done, it's quite helpful to clean up the series so it's optimized for the reader to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I sort of assumed that the whole diff would be larger than I wanted, but looking back at it it's actually pretty simple, which is nice.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah 😄

There's actually one further squashing I had in mind relative to your new revision, which is:

$ git uvr --shortstat
3dc5af6 webview: Add initial support for hiding muted messages.
4 files changed, 63 insertions(+), 2 deletions(-)
229ddf0 webview [nfc]: Pass GetText into messageAsHtml.
4 files changed, 14 insertions(+), 3 deletions(-)
a1e0775 messageAsHtml: Translate user-muted message.
2 files changed, 5 insertions(+), 5 deletions(-)

to squash those first and third changes (therefore coming after the "pass GetText in" change). The resulting change is
5 files changed, 63 insertions(+), 2 deletions(-)

so actually not any bigger than the version that doesn't translate the text, and it cleans the history up further.

Everything else looks good, so I'll just merge now and make that change on the way.

src/webview/html/messageAsHtml.js Outdated Show resolved Hide resolved
Comment on lines +948 to +957
const targetType = target.matches('.header')
? 'header'
: target.matches('a')
? 'link'
: 'message';
const messageNode = target.closest('.message');

if (
targetType === 'message'
&& messageNode
Copy link
Member

Choose a reason for hiding this comment

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

This is still a bit messy, but it's only extending a way that the existing logic in this function is already messy, and I think it's fine for now.

When I merge this, I may try splitting the conditionals in this function up to follow the style of the click handler above:

  • first, see if target matches .header, if so act on that and return.
  • then, see if matches a, if so act on that and return.
  • then, see if muted message, if so act on that and return.
  • finally, act on default case.

because I think that'll make it somewhat clearer, and also the difference in clarity will grow rapidly if we add any more cases here.

static/translations/messages_en.json Outdated Show resolved Hide resolved
src/pm-conversations/PmConversationList.js Outdated Show resolved Hide resolved
src/pm-conversations/PmConversationList.js Outdated Show resolved Hide resolved
Comment on lines 70 to 76
export const getUnreadPmsTotal: Selector<number> = createSelector(
getUnreadPms,
unreadPms => unreadPms.reduce((total, pm) => total + pm.unread_message_ids.length, 0),
getMutedUsers,
(unreadPms, mutedUsers) =>
unreadPms
.filter(pm => !mutedUsers.has(pm.sender_id))
.reduce((total, pm) => total + pm.unread_message_ids.length, 0),
Copy link
Member

Choose a reason for hiding this comment

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

This logic isn't necessary -- the server guarantees that messages from muted users will never be unread. See API docs:
https://chat.zulip.org/api/mute-user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we've got a server bug, then :)

I think even once we fix that, it's prudent to keep this code in case of similar future problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Started a discussion on #backend > muted users on CZO for the backend bug part of this.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, and it looks like the outcome of that thread is that this is an existing mobile bug! We're not maintaining the unread state correctly.

Specifically, when we handle EVENT_NEW_MESSAGE (i.e. the Redux action we make from a message event) in each of the unread sub-reducers, we have logic like this:

      if (message.sender_id === getOwnUserId(globalState)) {
        return state;
      }

and instead it should be checking something like message.flags.includes('read'). So we should fix that.

Then I don't think it makes sense to also have logic here specific to muted users. The job of this bit of code is to count up part of the unreads data; if we have future bugs where the unreads data is wrong, we should fix the bugs by making the unreads data correct.

(If for example we did have a server bug in the future that gave us incorrect unreads data, the place I'd want to put a workaround like this is at the input end, to make the data correct in Redux. One reason is that that makes sure it's fixed consistently for all the different places we might be using that data.)

src/users/UserList.js Outdated Show resolved Hide resolved
src/users/UserList.js Outdated Show resolved Hide resolved
gnprice added a commit that referenced this pull request Apr 28, 2021
Originally discussed here:
  #4440 (comment)
(with a bit of additional rationale) when this question first came up.

It's come up a couple more times since then, as we've continued
converting a lot of our components to functions with Hooks:
  #4555 (comment)
  #4699 (comment)
so it's definitely time to have it written down in a proper place.
@WesleyAC
Copy link
Contributor Author

@gnprice Thanks for the review! I made all the changes, should be good to go.

@gnprice gnprice merged commit 3682ee4 into zulip:master May 1, 2021
@gnprice
Copy link
Member

gnprice commented May 1, 2021

Looks good, thanks -- merged!

I edited the series slightly from this:

3dc5af6 webview: Add initial support for hiding muted messages.
229ddf0 webview [nfc]: Pass GetText into messageAsHtml.
a1e0775 messageAsHtml: Translate user-muted message.
b7016f8 PmConversationList [nfc]: Convert to functional component.
8f67bab pm-conversations [nfc]: Get Dispatch via useDispatch.
a88f2f3 PmConversationList: Hide PMs from muted users.
9b72a8c autocomplete: Hide muted users.
3d21aed unreads: Don't show PMs from muted users in unread count.
82197a5 UserList [nfc]: Convert to functional component.
571df77 UserList: Hide muted users.

to this:

cd28e88 webview [nfc]: Pass GetText into messageAsHtml.
5f816db webview: Hide messages from muted users, with option to show them.
a56e0b4 PmConversationList [nfc]: Convert to functional component.
16ec0dc PmConversationList [nfc]: Get Dispatch via useDispatch.
e21138e PmConversationList: Hide PMs from muted users.
f688bfe autocomplete: Hide muted users.
b351de2 UserList [nfc]: Convert to functional component.
3682ee4 UserList: Hide muted users.

by squashing two commits as mentioned at #4699 (comment) , and dropping the unreads change discussed at #4699 (comment) .

One thing we'll still need before #4655 is complete is to fix the unread-state bug that we learned about in that latter thread.

@WesleyAC
Copy link
Contributor Author

WesleyAC commented May 1, 2021

Thanks! Followed up with #4710 for the unreads change.

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.

None yet

3 participants