Skip to content

settings_page: Add marks as read on scroll options#5294

Closed
SilentCruzer wants to merge 1 commit intozulip:mainfrom
SilentCruzer:markRead
Closed

settings_page: Add marks as read on scroll options#5294
SilentCruzer wants to merge 1 commit intozulip:mainfrom
SilentCruzer:markRead

Conversation

@SilentCruzer
Copy link
Copy Markdown
Contributor

Closes: #5241

Making a draft pull request since I am not sure about the implementation.

The main change is basically changing the type of the variable doNotMarkMessagesAsRead from boolean to a string union.

Added a dropdown menu on the settings page to choose the options from the string union.

So the messages will mark as read based on the option.

Also, the tests for doNotMarkMessagesAsRead are written on migrations-test.js. If the implementation is correct can I get a few pointers for the new tests.

Screenshots:

@SilentCruzer SilentCruzer changed the title settings_page: Add marks ad read on scroll options settings_page: Add marks as read on scroll options Mar 12, 2022
Copy link
Copy Markdown
Contributor

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! See some comments below, and also a substantive comment about what options to offer, at #5241 (comment).

Comment thread src/settings/SettingsScreen.js Outdated
import React, { useCallback } from 'react';
import type { Node } from 'react';

import { View, Text, Picker } from 'react-native';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see a deprecation notice at the top of the doc:

image

Deprecated. Use one of the community packages instead.

From the list at the handy link they give, I think @react-native-picker/picker looks like the best choice.

Comment thread src/webview/MessageList.js Outdated
auth: getAuth(state),
debug,
doNotMarkMessagesAsRead:
!marksMessagesAsRead(props.narrow) || globalSettings.doNotMarkMessagesAsRead,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We shouldn't remove the first part, !marksMessagesAsRead(props.narrow). It makes it so that some views never automatically mark as read; see the comments in marksMessagesAsRead for why.

Comment thread src/settings/SettingsScreen.js Outdated
style={[
styles.listItem,
{
height: 56,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 56?

Copy link
Copy Markdown
Contributor Author

@SilentCruzer SilentCruzer May 5, 2022

Choose a reason for hiding this comment

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

Sorry about that, I should have mentioned it earlier. I just made a rough UI for testing the feature. I was planning to make a proper code for that after I made the correct implementation.

Comment thread src/settings/SettingsScreen.js Outdated
},
]}
>
<Text style={{ fontSize: 15 }}>Mark messages read on scroll</Text>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use ZulipTextIntl for this.

Comment thread src/settings/SettingsScreen.js Outdated
<View>
<Picker
selectedValue={doNotMarkMessagesAsRead}
style={{ width: 150 }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 150?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same as this comment

Comment thread src/webview/js/js.js
});
if (!doNotMarkMessagesAsRead) {
setMessagesReadAttributes(rangeHull);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like the place where the setting actually takes effect; is that right? It seems like this bit should be replaced with something different, instead of removed altogether.

Copy link
Copy Markdown
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 @SilentCruzer! A couple more comments, in addition to the things @chrisbobbe mentioned.

Comment thread src/webview/handleOutboundEvents.js Outdated
Comment on lines +187 to +193
if (doNotMarkMessagesAsRead === 'stream' && !isStreamOrTopicNarrow(props.narrow)) {
return;
}
if (doNotMarkMessagesAsRead === 'topic' && !isTopicNarrow(props.narrow)) {
return;
}
if (doNotMarkMessagesAsRead === 'never') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From this implementation, it looks like the meaning of this value is more like "do mark messages as read", rather than "do not mark messages as read".

In that case, let's rename it to match its meaning. One good name would be shouldMarkAsReadOnScroll.

Comment thread src/reduxTypes.js Outdated
// Possibly this should be per-account. If so it should probably be put
// on the server, so it can also be cross-device for the account.
doNotMarkMessagesAsRead: boolean,
doNotMarkMessagesAsRead: 'all' | 'stream' | 'topic' | 'never',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Whenever changing a type that appears in the Redux state, we'll want a migration to update the user's existing data.

See discussion here:
https://github.com/zulip/zulip-mobile/blob/main/docs/howto/new-feature.md#redux-state-migrations

Comment on lines +264 to +267
const marksMessagesAsRead = (
narrow: Narrow,
shouldMarkAsReadOnScroll: 'never' | 'always' | 'conversation',
): 'never' | 'always' | 'conversation' =>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Except for the search, starred, and mentioned narrows, every other narrows should depend on the currently chosen setting. That's why I added this extra parameter

Comment thread src/webview/js/js.js
endMessageId: rangeHull.last,
});
if (!doNotMarkMessagesAsRead) {
if (shouldMarkAsReadOnScroll === 'always' || shouldMarkAsReadOnScroll === 'conversation') {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This conditional is not entirely correct.

setMessagesReadAttributes(rangeHull), should only work if the chosen setting is 'always' or the settings is 'conversation' and the current narrow is a topic or pm.

Is there a way to check which narrow we are currently in the js.js file?

@gnprice
Copy link
Copy Markdown
Member

gnprice commented Sep 2, 2022

Thanks again @SilentCruzer for working on this! Closing this PR in favor of #5469.

@gnprice gnprice closed this Sep 2, 2022
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.

Option to mark as read only in conversation views

3 participants