Skip to content

Commit 00db9c0

Browse files
committed
Fixes #511: Press 'i' to show user info
1 parent 2ec1f0a commit 00db9c0

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

zulipterminal/core.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
2+
import pytz
23
import signal
34
import sys
45
import time
6+
from datetime import datetime
57
from functools import partial
68
from platform import platform
79
from typing import Any, List, Optional
@@ -120,9 +122,64 @@ def show_stream_info(self, color: str, name: str, desc: str) -> None:
120122
show_stream_view = StreamInfoView(self, color, name, desc)
121123
self.show_pop_up(show_stream_view, "# {}".format(name))
122124

123-
def show_user_info(self, user_id:int) -> None:
124-
show_userinfo_view = UserInfoView(self, user_id)
125-
self.show_pop_up(show_userinfo_view, "{}".format(user_id))
125+
def show_user_info(self, user_id:int) -> None:
126+
url = 'users/' + str(user_id)
127+
response = self.client.call_endpoint(
128+
url=url,
129+
method='GET',
130+
request={'include_custom_profile_fields': True}
131+
)
132+
133+
index = {
134+
'17': 'Github username',
135+
'18': 'Twitter',
136+
'3': 'Country',
137+
'5': 'Zulip expertise',
138+
'7': 'About me',
139+
'13': {
140+
'0': 'emacs',
141+
'1': 'vim',
142+
'2': 'vscode',
143+
'3': 'sublime',
144+
'4': 'atom',
145+
'5': 'Other',
146+
},
147+
'16': 'Favourite date',
148+
}
149+
150+
display_data = {}
151+
res_data = response['members'][0]
152+
153+
for key, value in res_data['profile_data'].items():
154+
if key == '13':
155+
display_data['Favourite editor'] = index['13'][str(res_data['profile_data']['13']['value'])]
156+
else: display_data[str(index[key])] = value['value']
157+
158+
display_data['Email'] = res_data['email']
159+
display_data['Date joined'] = res_data['date_joined'][:10]
160+
display_data['Timezone'] = res_data['timezone']
161+
162+
try:
163+
display_data['Local time'] = datetime.now(pytz.timezone(str(res_data['timezone']))).strftime("%H:%M")
164+
except:
165+
display_data['Local time'] = "Unknown timezone"
166+
167+
presence = self.client.get_user_presence(str(res_data['email']))
168+
if presence['presence']['aggregated']['status'] == 'active':
169+
display_data['Last active'] = "Currently online"
170+
else:
171+
display_data['Last active'] = str(datetime.fromtimestamp(presence['presence']['aggregated']['timestamp']))
172+
173+
if res_data['is_admin']:
174+
display_data['Role'] = "Admin"
175+
elif res_data['is_guest']:
176+
display_data['Role'] = "Guest"
177+
else:
178+
display_data['Role'] = "Member"
179+
180+
show_userinfo_view = UserInfoView(self, display_data)
181+
self.show_pop_up(show_userinfo_view, "{}".format(res_data['full_name']))
182+
return response['result'] == 'success'
126183

127184
def search_messages(self, text: str) -> None:
128185
# Search for a text in messages

zulipterminal/ui_tools/views.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,26 @@ def keypress(self, size: Tuple[int, int], key: str) -> str:
850850

851851

852852
class UserInfoView(urwid.ListBox):
853-
def __init__(self, controller, display_data) -> None:
853+
def __init__(self, controller, display_data:dict) -> None:
854854
self.controller = controller
855-
log = [urwid.Text(str(display_data), align = 'center')]
856-
self.width = 20
857-
self.height = 20
855+
self.data = display_data
858856

859-
super().__init__(log)
857+
if 'Zulip expertise' in self.data:
858+
self.height = len(self.data) + math.floor(len(self.data['Zulip expertise'])/45)
859+
#Zulip expertise is the only column that can be of multiple lines
860+
else: self.height = len(self.data)
861+
self.width = 70
862+
863+
self.log = urwid.SimpleListWalker(
864+
[urwid.AttrWrap(
865+
urwid.Columns([
866+
urwid.Text(field),
867+
(45, urwid.Text(data))
868+
], dividechars=2),
869+
None if index % 2 else 'bar')
870+
for index, (field, data) in enumerate(self.data.items())])
871+
872+
super().__init__(self.log)
860873

861874
def keypress(self, size: Tuple[int, int], key: str) -> str:
862875
if (is_command_key('GO_BACK', key) or

0 commit comments

Comments
 (0)