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

feature: Topic muting #914

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feature: Topic muting #914

wants to merge 7 commits into from

Conversation

mkp6781
Copy link
Contributor

@mkp6781 mkp6781 commented Feb 8, 2021

I have rebased @sumanthvrao branch for topic muting on to the main. I have modified some of the code and logic to accommodate the changes in data structures and added tests while maintaining the same commit structure as earlier.
In the 4th commit, I am yet to add the tests for the two new functions. I will be working on this soon.

Continues work on #467

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Feb 8, 2021
@mkp6781 mkp6781 changed the title Issue 745 Topic muting Feb 8, 2021
@mkp6781 mkp6781 changed the title Topic muting feature: Topic muting Feb 8, 2021
@mkp6781
Copy link
Contributor Author

mkp6781 commented Feb 8, 2021

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Feb 8, 2021
Copy link
Member

@Ezio-Sarthak Ezio-Sarthak left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up 👍. This provisionally looks a great add-on! Leaving some comments inline :)

On manual testing, I observed that the unread count for All_msg changes even for muting topics in a muted stream. This edge case could be handled accordingly. (And potentially later in tests too)

minor: Typo in first commit message: API class => API call

def test_toggle_topic_muted_status(self, mocker, model,
stream_dict,
initial_muted_topics, op,
response={'result': 'success'}):
Copy link
Member

Choose a reason for hiding this comment

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

We could add tests for {result: error} too for non-existent topics perhaps?

model.toggle_topic_muted_status(1, 'Stream 1', 'party')
request = {
'stream': 'Stream 1',
'topic': 'party',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe parameterize topics, so as to handle cases for non-existing topics? (See my above comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made an API call with a non-existing topic in the request but it still returned a 'success' response. I'm not sure why that is the case. Maybe it's an issue in zulip api?

Copy link
Member

Choose a reason for hiding this comment

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

Ah right. I just looked over API events for topic muting and it seems like the response will be succeeded regardless of whether any messages have been sent to the specified topic.

The edge cases for error handling might be:

  • muting already muted topic
  • unumting an already unmuted topic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look at this API events for topic muting but it did not mention anything about non-existent topics which you pointed out. I raised an issue regarding the same in the api repo.

The edge cases for error handling might be:

* muting already muted topic

* unumting an already unmuted topic
        request = {
            'stream': stream_name,
            'topic': topic_name,
            'op': 'remove'
            if self.is_muted_topic(stream_id, topic_name)
            else 'add'
        }

This is the code for initializing the request variable for the api call. Depending on the topic's current state(muted/not muted), 'op' is assigned a value which can toggle the state. So there would'nt be an error case as such!
One thing I could do is rename 'op' in parametrize to 'expected_op'?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think renaming is fruitful. As you said, the update event wouldn't be called in the edge cases I mentioned 👍

currently_muted = self.model.is_muted_topic(button.stream_id,
button.topic_name)
type_of_action = "unmuting" if currently_muted else "muting"
question = urwid.Text(("bold", "Confirm " + type_of_action
Copy link
Member

Choose a reason for hiding this comment

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

On manual testing, I found the bold attribute isn't working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea noticed that now. We don't need it to be bold anyways so i'll leave it as an empty string.

self.stream_id, self.topic_name)] = self.count
self.model.unread_counts['unread_topics'].pop(
(self.stream_id, self.topic_name), None)
self.model.unread_counts['all_msg'] -= self.count
Copy link
Member

Choose a reason for hiding this comment

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

This needs an edge case handling. (See my review bullet)

Copy link
Member

Choose a reason for hiding this comment

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

I haven't checked other updates, though I could still reproduce this bug (i.e., subtracting unreads in the case of a muted stream)

README.md Outdated
Comment on lines 207 to 211
### Topic list actions
| Command | Key Combination |
|------------------------------------------------------ | --------------------------------------------- |
| Mute/unmute Topics | <kbd>M</kbd> |

Copy link
Member

Choose a reason for hiding this comment

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

Note that we use auto-generated hotkeys now, thanks to your work in #926 :)

Comment on lines +312 to +348
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key('TOGGLE_MUTE_TOPIC', key):
self.controller.topic_muting_confirmation_popup(self)
return super().keypress(size, key)
Copy link
Member

Choose a reason for hiding this comment

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

We could add a test for this?

@Ezio-Sarthak
Copy link
Member

@zulipbot remove "PR needs review"
@zulipbot add "PR awaiting update"

@zulipbot zulipbot added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Apr 3, 2021
sumanthvrao and others added 7 commits April 24, 2021 09:42
This handles updating muting/unmuting topics in a stream
by sending the request to the server with the help of an
API call.

Tests added.
We make use of the PopUpConfirmation for confirmation if the user wishes
to continue performing muting/unmuting action of the displayed topic.
The TopicButton's stream_name and topic_name attribute allow us to display
the affected stream name and topic name in the view.

Tests added.
We register the event_type 'muted_topics' to the event queue on startup,
along with a handler method which responds to these events appropriately.
Depending on whether the topic is already muted or not, the handler method
calls the `mark_muted` or `mark_unmuted`. These two functions will update
the data structures which keeps track of message counts in a later commit.

Tests added
`model.unread_counts` and button counts are updated based on user action
of muting or unmuting.

During muting of a topic:
* We decrease All_msg count by the unread count of topic.
* If there are unread messages in the stream, we decrease its count by
  the same amount as well.

During unmuting of a topic:
* If there are unread messages in the stream, we replace 'M' with the
  correct unread count.
* If there are no unread messages, we remove the marked 'M'.

Tests to be added for mark_(un)muted.
Handles setting count of `model.unread_counts`.
Functions `_set_count_in_model` and `_set_count_in_view` are modified
to keep track of unread counts of muted topics when a new message is
recieved or an existing message is read. This ensures that the count
is in sync when the topic is unmuted later on.
New section 'Topic list actions' created in hotkeys.md.

New 'topic_list' category created in keys for mapping keys
belonging to topic list actions.
On pressing TOGGLE_MUTE_TOPIC, we now ask for confirmation before
performing the action of muting/unmuting topics.

Tests added.
@mkp6781
Copy link
Contributor Author

mkp6781 commented Apr 24, 2021

@zulipbot add "PR needs review"

@zulipbot
Copy link
Member

ERROR: Label " PR needs review" does not exist and was thus not added to this pull request.

@mkp6781
Copy link
Contributor Author

mkp6781 commented Apr 24, 2021

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Apr 24, 2021
@mkp6781
Copy link
Contributor Author

mkp6781 commented Apr 24, 2021

@zulipbot remove "PR awaiting update"

@zulipbot zulipbot removed the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Apr 24, 2021
@mkp6781
Copy link
Contributor Author

mkp6781 commented Apr 24, 2021

These commits deal with functionality aspects of this new feature.
In the 4th commit, I haven't added the test for mark_muted and mark_unmuted functions. I will do that in the next iteration.

@zulipbot
Copy link
Member

Heads up @mkp6781, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants