-
-
Notifications
You must be signed in to change notification settings - Fork 286
Handle read events from server #535
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
Open
kaustubh-nair
wants to merge
3
commits into
zulip:main
Choose a base branch
from
kaustubh-nair:unread_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ def model(self, mocker, initial_data, user_profile): | |
| # NOTE: PATCH WHERE USED NOT WHERE DEFINED | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
| self.client.get_profile.return_value = user_profile | ||
| model = Model(self.controller) | ||
| return model | ||
|
|
@@ -81,7 +81,7 @@ def test_init_InvalidAPIKey_response(self, mocker, initial_data): | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| with pytest.raises(ServerConnectionFailure) as e: | ||
| model = Model(self.controller) | ||
|
|
@@ -103,7 +103,7 @@ def test_init_ZulipError_exception(self, mocker, initial_data, | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| with pytest.raises(ServerConnectionFailure) as e: | ||
| model = Model(self.controller) | ||
|
|
@@ -440,7 +440,7 @@ def test_success_get_messages(self, mocker, messages_successful_response, | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| # Setup mocks before calling get_messages | ||
| self.client.get_messages.return_value = messages_successful_response | ||
|
|
@@ -480,7 +480,7 @@ def test_get_message_false_first_anchor( | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| # Setup mocks before calling get_messages | ||
| messages_successful_response['anchor'] = 0 | ||
|
|
@@ -513,7 +513,7 @@ def test_fail_get_messages(self, mocker, error_response, | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| # Setup mock before calling get_messages | ||
| # FIXME This has no influence on the result | ||
|
|
@@ -593,7 +593,7 @@ def test__update_initial_data_raises_exception(self, mocker, initial_data): | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
|
|
||
| # Setup mocks before calling get_messages | ||
| self.client.register.return_value = initial_data | ||
|
|
@@ -627,7 +627,7 @@ def test_get_all_users(self, mocker, initial_data, user_list, user_dict, | |
| return_value=({}, set(), [], [])) | ||
| self.classify_unread_counts = mocker.patch( | ||
| 'zulipterminal.model.classify_unread_counts', | ||
| return_value=[]) | ||
| return_value=([], {})) | ||
| model = Model(self.controller) | ||
| assert model.user_dict == user_dict | ||
| assert model.users == user_list | ||
|
|
@@ -650,7 +650,7 @@ def test__handle_message_event_with_Falsey_log(self, mocker, | |
| model.found_newest = True | ||
| mocker.patch('zulipterminal.model.Model._update_topic_index') | ||
| index_msg = mocker.patch('zulipterminal.model.index_messages', | ||
| return_value={}) | ||
| return_value=initial_index) | ||
| model.msg_list = mocker.Mock(log=[]) | ||
| create_msg_box_list = mocker.patch('zulipterminal.model.' | ||
| 'create_msg_box_list', | ||
|
|
@@ -671,7 +671,7 @@ def test__handle_message_event_with_valid_log(self, mocker, | |
| model.found_newest = True | ||
| mocker.patch('zulipterminal.model.Model._update_topic_index') | ||
| index_msg = mocker.patch('zulipterminal.model.index_messages', | ||
| return_value={}) | ||
| return_value=initial_index) | ||
| model.msg_list = mocker.Mock(log=[mocker.Mock()]) | ||
| create_msg_box_list = mocker.patch('zulipterminal.model.' | ||
| 'create_msg_box_list', | ||
|
|
@@ -689,12 +689,37 @@ def test__handle_message_event_with_valid_log(self, mocker, | |
| assert_called_once_with(model, [message_fixture['id']], | ||
| last_message=expected_last_msg)) | ||
|
|
||
| @pytest.mark.parameter('unread_msgs', [ | ||
| ({'type': 'stream', 'stream_id': 5140, | ||
| 'subject': 'Test', 'display_recipient': 'PTEST'}), | ||
| ({'type': 'private', 'sender_id': '5140'}), | ||
| ({'type': 'private', 'display_recipient': | ||
| [{ | ||
| 'id': 5179, | ||
| 'is_mirror_dummy': False, | ||
| 'full_name': 'Boo Boo', | ||
| 'short_name': 'boo', | ||
| 'email': '[email protected]', | ||
| }, { | ||
| 'short_name': 'foo', | ||
| 'id': 5140, | ||
| 'is_mirror_dummy': False, | ||
| 'full_name': 'Foo Foo', | ||
| 'email': '[email protected]', | ||
| }, { | ||
| 'short_name': 'bar', | ||
| 'id': 5180, | ||
| 'is_mirror_dummy': False, | ||
| 'full_name': 'Bar Bar', | ||
| 'email': '[email protected]', | ||
| }]}), | ||
| ]) | ||
| def test__handle_message_event_with_flags(self, mocker, | ||
| model, message_fixture): | ||
| model.found_newest = True | ||
| mocker.patch('zulipterminal.model.Model._update_topic_index') | ||
| index_msg = mocker.patch('zulipterminal.model.index_messages', | ||
| return_value={}) | ||
| return_value=initial_index) | ||
| model.msg_list = mocker.Mock() | ||
| create_msg_box_list = mocker.patch('zulipterminal.model.' | ||
| 'create_msg_box_list', | ||
|
|
@@ -720,8 +745,9 @@ def test__handle_message_event_with_flags(self, mocker, | |
|
|
||
| @pytest.mark.parametrize('response, narrow, recipients, log', [ | ||
| ({'type': 'stream', 'stream_id': 1, 'subject': 'FOO', | ||
| 'id': 1}, [], frozenset(), ['msg_w']), | ||
| ({'type': 'private', 'id': 1}, | ||
| 'id': 1, 'display_recipient': 'a'}, [], frozenset(), ['msg_w']), | ||
| ({'type': 'private', 'id': 1, 'sender_id': 1, | ||
| 'display_recipient': []}, | ||
| [['is', 'private']], frozenset(), ['msg_w']), | ||
| ({'type': 'stream', 'id': 1, 'stream_id': 1, 'subject': 'FOO', | ||
| 'display_recipient': 'a'}, | ||
|
|
@@ -734,14 +760,15 @@ def test__handle_message_event_with_flags(self, mocker, | |
| 'display_recipient': 'a'}, | ||
| [['stream', 'c'], ['topic', 'b']], | ||
| frozenset(), []), | ||
| ({'type': 'private', 'id': 1, | ||
| ({'type': 'private', 'id': 1, 'sender_id': 5827, | ||
| 'display_recipient': [{'id': 5827}, {'id': 5}]}, | ||
| [['pm_with', '[email protected]']], | ||
| frozenset({5827, 5}), ['msg_w']), | ||
| ({'type': 'private', 'id': 1}, | ||
| ({'type': 'private', 'id': 1, 'sender_id': 5827, | ||
| 'display_recipient': []}, | ||
| [['is', 'search']], | ||
| frozenset(), []), | ||
| ({'type': 'private', 'id': 1, | ||
| ({'type': 'private', 'id': 1, 'sender_id': 5827, | ||
| 'display_recipient': [{'id': 5827}, {'id': 3212}]}, | ||
| [['pm_with', '[email protected]']], | ||
| frozenset({5827, 5}), []), | ||
|
|
@@ -759,7 +786,7 @@ def test__handle_message_event(self, mocker, user_profile, response, | |
| model.found_newest = True | ||
| mocker.patch('zulipterminal.model.Model._update_topic_index') | ||
| index_msg = mocker.patch('zulipterminal.model.index_messages', | ||
| return_value={}) | ||
| return_value=initial_index) | ||
| create_msg_box_list = mocker.patch('zulipterminal.model.' | ||
| 'create_msg_box_list', | ||
| return_value=["msg_w"]) | ||
|
|
@@ -1297,7 +1324,7 @@ def test_update_read_status(self, mocker, model, event_op, | |
| == flags_before) | ||
|
|
||
| if event_op == 'add': | ||
| set_count.assert_called_once_with(list(changed_ids), | ||
| set_count.assert_called_once_with(list(event_message_ids), | ||
| self.controller, -1) | ||
| elif event_op == 'remove': | ||
| set_count.assert_not_called() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of hacky - we don't have
sender_idfor stream messages ininitial_data['unread_msgs']Though on close inspection this piece of code doesn't seem to be doing anything?
Refer to conversation on czo https://chat.zulip.org/#narrow/stream/206-zulip-terminal/topic/Handling.20read.20events/near/845434