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

Added feature: Show user info by pressing 'i' #519

Closed
wants to merge 3 commits into from

Conversation

SGeetansh
Copy link
Collaborator

@SGeetansh SGeetansh commented Mar 4, 2020

Fixes #511
This pull request implements a feature of displaying the information of the user in focus. All the information that is visible in the web app is present.
It doesn't pass the tests right now. Please suggest any required changes.

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Mar 4, 2020
Copy link
Member

@sumanthvrao sumanthvrao left a comment

Choose a reason for hiding this comment

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

@SGeetansh Thanks for working on this. I gave a quick review of some aspects I came across.

Haven't looked into the the core show_user_info method thoroughly yet, but based on some manual testing the data which is being show looks good!

I know it's still a draft PR, but you could try splitting it into commits so reviewing becomes quicker as well. :)

requirements.txt Outdated
@@ -13,5 +13,5 @@ emoji==0.5.0
urwid_readline==0.10
beautifulsoup4==4.6.0
lxml==4.2.3

pytz==2019.3
Copy link
Member

Choose a reason for hiding this comment

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

@SGeetansh In order to upgrade a dependency / introduce a new one, requirements.txt is not the only place you need to include this. You should also introduce it in Pipfile and setup.py besides this. This is so that, running pip3 install -e .[dev] automatically updates the local environment and adds these packages.

For more details run git log --grep='requirements' and see how previous upgrades have been written.

@@ -200,6 +200,11 @@
'help_text': 'View stream description',
'key_category': 'stream_list',
}),
('USER_INFO', {
Copy link
Member

Choose a reason for hiding this comment

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

It would also benefit to have a note for this in README. (Maybe these two changes can be extracted into a separate commit)

@@ -79,14 +79,14 @@ def __init__(self, controller: Any) -> None:
self.stream_id = -1
self.recipients = frozenset() # type: FrozenSet[Any]
self.index = initial_index

Copy link
Member

Choose a reason for hiding this comment

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

Some extra spaces ;)

@@ -213,6 +215,11 @@ def _narrow_with_compose(self, button: Any) -> None:
self._view.body.focus.original_widget.set_focus('footer')
self._view.write_box.private_box_view(self)

def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key('USER_INFO', key):
self.model.controller.show_user_info(self.user_id)
Copy link
Member

Choose a reason for hiding this comment

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

alternatively, can we could just use self.controller.show_user_info here , and avoid the line on top? :)

def show_user_info(self, user_id:int) -> None:
user_id = user_id
url = 'users/' + str(user_id)
result = self.client.call_endpoint(
Copy link
Member

Choose a reason for hiding this comment

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

It's always good to check if the result was a success or not here. We do that in many places so you can have a look.

Copy link
Collaborator Author

@SGeetansh SGeetansh Mar 7, 2020

Choose a reason for hiding this comment

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

@sumanthvrao
I checked the other places. They just check if the response message was 'success' or not, with a return statement at the end of the function (return response['result'] == success). Do you want me to just write that only? Sorry, if I am wrong, but can you please elaborate on this? I didn't put a try-except here because I think it isn't required.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that's the correct way to do the validation. No need of a try-catch block.

The pytz library is used for timezone calculations. In our case
it will be used to fetch the local time of a user given his/her
local timezone. The standard time library can't be used.
@SGeetansh SGeetansh requested a review from sumanthvrao March 8, 2020 13:09
@neiljp neiljp added the PR needs review PR requires feedback to proceed label Mar 9, 2020
Copy link
Member

@sumanthvrao sumanthvrao left a comment

Choose a reason for hiding this comment

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

@SGeetansh Thanks for sticking with this 👍

I feel the commit order and structure can be changed.By this, I mean, in the first commit you introduced some changes which you edited in the third commit again. Instead you could introduce the entire change and just avoid linking it for now. The linking can be done in the follow-up commits.

An example commit order:

  1. The requirements update commit for pytz
  2. UserInfoView commit (and the keypress). Since we don't call this anywhere, tests will still pass by just introducing this commit.
  3. show_user_info in controller commit. Introduce the entire method here :)
  4. lastly, Add the keypress to UserButton which helps link the changes made in previous commits.

So you see, the earlier commits build up to the later one, but only the last one does the actual linking.

One more point was that I saw a lot of diffs wrt to white spaces. Remember to remove them while you do a rebase.

Are you planning to add tests? (Again, a commit can have the code changes and the tests in it) :)

Let me know if you have further doubts.

@@ -200,6 +200,11 @@
'help_text': 'View stream description',
'key_category': 'stream_list',
}),
('USER_INFO', {
'keys': {'i'},
Copy link
Member

Choose a reason for hiding this comment

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

You could extract the README and keys into a sepearte commit as well. As it stands, this commit has a lot of file changes.

@@ -13,5 +13,4 @@ emoji==0.5.0
urwid_readline==0.10
beautifulsoup4==4.6.0
lxml==4.2.3

zipp==1.0.0 # To support Python 3.5
zipp==1.0.0 # To support Python 3.5
Copy link
Member

Choose a reason for hiding this comment

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

Unwanted diff? :)

@@ -1,5 +1,6 @@
import threading
import time
import math
Copy link
Member

Choose a reason for hiding this comment

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

Isn't import math used in your third commit. If so, let's import it only in the commit where it is used.


show_userinfo_view = UserInfoView(self, display_data)
self.show_pop_up(show_userinfo_view, "{}".format(res_data['full_name']))
return 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.

Where do you validate whether the return value was true/false?

Copy link
Collaborator Author

@SGeetansh SGeetansh Mar 16, 2020

Choose a reason for hiding this comment

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

Can you point me to an instance where this is done? I don't know what to do. And do I really need to do that because there would always be a response since if a user already exists, it has to have his info on the server, am I right?

Copy link
Member

@sumanthvrao sumanthvrao Mar 20, 2020

Choose a reason for hiding this comment

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

@SGeetansh I meant you could do this at the beginning of this function after you make the API call. Only if the response result is a success, you can parse and store the parameters as you have done.

In case the API call fails, no errors will be thrown if you do this validation :)

@@ -850,13 +850,26 @@ def keypress(self, size: Tuple[int, int], key: str) -> str:


class UserInfoView(urwid.ListBox):
def __init__(self, controller, display_data) -> None:
def __init__(self, controller, display_data:dict) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe type-hint more?

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Apr 9, 2020
@zulipbot
Copy link
Member

Heads up @SGeetansh, 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/master branch and resolve your pull request's merge conflicts accordingly.

@neiljp
Copy link
Collaborator

neiljp commented Oct 20, 2020

@SGeetansh I hope you had a good Summer - just checking in if you planned to update this PR?

If you do plan to update this:

  • Some timezone code has been added, so the dependency commit shouldn't be necessary now
  • The popup code has been streamlined, which may well make this easier - see PopUpView and child classes
  • Just having the available information from the existing presences data would be good in a working commit, then following up with custom profile fields in a later one - the titles need sourcing from somewhere as I think the values you're using are hard-coded from chat.zulip.org?

Base automatically changed from master to main January 30, 2021 20:30
@neiljp
Copy link
Collaborator

neiljp commented Mar 20, 2022

Closing, as this was replaced via #848.

@SGeetansh Thanks for filing the issue and taking a shot here 👍

@neiljp neiljp closed this Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Enable view of user info
4 participants