Skip to content

Commit 409ea50

Browse files
committed
Revert "BugFix: Comparing users based on user_id than user_name."
This reverts commit cdec135.
1 parent cdec135 commit 409ea50

File tree

9 files changed

+26
-45
lines changed

9 files changed

+26
-45
lines changed

tests/ui/test_ui_tools.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,6 @@ def test_main_view(self, mocker, message, last_message):
19831983
[
19841984
{
19851985
"id": 4,
1986-
"sender_id": 4,
19871986
"type": "stream",
19881987
"display_recipient": "Verona",
19891988
"stream_id": 5,
@@ -2022,7 +2021,6 @@ def test_main_view_renders_slash_me(self, mocker, message, content, is_me_messag
20222021
[
20232022
{
20242023
"id": 4,
2025-
"sender_id": 4,
20262024
"type": "stream",
20272025
"display_recipient": "Verona",
20282026
"stream_id": 5,
@@ -2198,7 +2196,6 @@ def test_msg_generates_search_and_header_bar(
21982196
[
21992197
{
22002198
"id": 4,
2201-
"sender_id": 4,
22022199
"type": "stream",
22032200
"display_recipient": "Verona",
22042201
"stream_id": 5,
@@ -2224,11 +2221,11 @@ def test_msg_generates_search_and_header_bar(
22242221
"expected_header, to_vary_in_last_message",
22252222
[
22262223
(
2227-
[STATUS_INACTIVE, "alice(4)", " ", "DAYDATETIME"],
2224+
[STATUS_INACTIVE, "alice", " ", "DAYDATETIME"],
22282225
{"sender_full_name": "bob"},
22292226
),
22302227
([" ", " ", " ", "DAYDATETIME"], {"timestamp": 1532103779}),
2231-
([STATUS_INACTIVE, "alice(4)", " ", "DAYDATETIME"], {"timestamp": 0}),
2228+
([STATUS_INACTIVE, "alice", " ", "DAYDATETIME"], {"timestamp": 0}),
22322229
],
22332230
ids=[
22342231
"show_author_as_authors_different",

zulipterminal/config/themes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'header' : 'bold',
3030
'general_narrow' : 'standout',
3131
'general_bar' : '',
32-
'msg_sender' : '',
32+
'name' : '',
3333
'unread' : 'strikethrough',
3434
'user_active' : 'bold',
3535
'user_idle' : '',

zulipterminal/model.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import json
66
import time
7-
from collections import Counter, OrderedDict, defaultdict
7+
from collections import OrderedDict, defaultdict
88
from concurrent.futures import Future, ThreadPoolExecutor, wait
99
from copy import deepcopy
1010
from datetime import datetime
@@ -1018,7 +1018,6 @@ def get_all_users(self) -> List[Dict[str, Any]]:
10181018
# and a user-id to email mapping
10191019
self.user_dict: Dict[str, Dict[str, Any]] = dict()
10201020
self.user_id_email_dict: Dict[int, str] = dict()
1021-
self.user_name_dict_count: Dict[str, int] = dict()
10221021
for user in self.initial_data["realm_users"]:
10231022
if self.user_id == user["user_id"]:
10241023
self._all_users_by_id[self.user_id] = user
@@ -1131,9 +1130,7 @@ def get_all_users(self) -> List[Dict[str, Any]]:
11311130
user_list.insert(0, current_user)
11321131
self.user_dict[current_user["email"]] = current_user
11331132
self.user_id_email_dict[self.user_id] = current_user["email"]
1134-
self.user_name_dict_count = Counter(
1135-
user["full_name"] for user in user_list
1136-
) # Counting number of users having same name
1133+
11371134
return user_list
11381135

11391136
def user_name_from_id(self, user_id: int) -> str:
@@ -1147,12 +1144,6 @@ def user_name_from_id(self, user_id: int) -> str:
11471144

11481145
return self.user_dict[user_email]["full_name"]
11491146

1150-
def user_name_count_compare(self, user_name: str) -> int:
1151-
"""
1152-
Returns if the count of the users with the same name is more than 1.
1153-
"""
1154-
return True if self.user_name_dict_count.get(user_name, -1) > 1 else False
1155-
11561147
def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
11571148
def make_reduced_stream_data(stream: Subscription) -> StreamData:
11581149
# stream_id has been changed to id.

zulipterminal/themes/gruvbox_dark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'header' : (Color.NEUTRAL_BLUE, Color.BRIGHT_BLUE),
2525
'general_narrow' : (Color.DARK0_HARD, Color.BRIGHT_BLUE),
2626
'general_bar' : (Color.LIGHT2, Color.DARK0_HARD),
27-
'msg_sender' : (Color.NEUTRAL_YELLOW__BOLD, Color.DARK0_HARD),
27+
'name' : (Color.NEUTRAL_YELLOW__BOLD, Color.DARK0_HARD),
2828
'unread' : (Color.NEUTRAL_PURPLE, Color.DARK0_HARD),
2929
'user_active' : (Color.BRIGHT_GREEN, Color.DARK0_HARD),
3030
'user_idle' : (Color.NEUTRAL_YELLOW, Color.DARK0_HARD),

zulipterminal/themes/gruvbox_light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'header' : (Color.NEUTRAL_BLUE, Color.FADED_BLUE),
2424
'general_narrow' : (Color.LIGHT0_HARD, Color.FADED_BLUE),
2525
'general_bar' : (Color.DARK2, Color.LIGHT0_HARD),
26-
'msg_sender' : (Color.NEUTRAL_YELLOW, Color.LIGHT0_HARD),
26+
'name' : (Color.NEUTRAL_YELLOW, Color.LIGHT0_HARD),
2727
'unread' : (Color.NEUTRAL_PURPLE, Color.LIGHT0_HARD),
2828
'user_active' : (Color.FADED_GREEN, Color.LIGHT0_HARD),
2929
'user_idle' : (Color.NEUTRAL_YELLOW, Color.LIGHT0_HARD),

zulipterminal/themes/zt_blue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'header' : (Color.BLACK, Color.DARK_BLUE),
1919
'general_narrow' : (Color.WHITE, Color.DARK_BLUE),
2020
'general_bar' : (Color.DARK_BLUE, Color.LIGHT_BLUE),
21-
'msg_sender' : (Color.DARK_RED, Color.LIGHT_BLUE),
21+
'name' : (Color.DARK_RED, Color.LIGHT_BLUE),
2222
'unread' : (Color.LIGHT_GRAY, Color.LIGHT_BLUE),
2323
'user_active' : (Color.LIGHT_GREEN__BOLD, Color.LIGHT_BLUE),
2424
'user_idle' : (Color.DARK_GRAY, Color.LIGHT_BLUE),

zulipterminal/themes/zt_dark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'header' : (Color.DARK_CYAN, Color.DARK_BLUE),
1919
'general_narrow' : (Color.WHITE, Color.DARK_BLUE),
2020
'general_bar' : (Color.WHITE, Color.BLACK),
21-
'msg_sender' : (Color.YELLOW__BOLD, Color.BLACK),
21+
'name' : (Color.YELLOW__BOLD, Color.BLACK),
2222
'unread' : (Color.DARK_BLUE, Color.BLACK),
2323
'user_active' : (Color.LIGHT_GREEN, Color.BLACK),
2424
'user_idle' : (Color.YELLOW, Color.BLACK),

zulipterminal/themes/zt_light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'header' : (Color.WHITE, Color.DARK_BLUE),
1919
'general_narrow' : (Color.WHITE, Color.DARK_BLUE),
2020
'general_bar' : (Color.DARK_BLUE, Color.WHITE),
21-
'msg_sender' : (Color.DARK_GREEN, Color.WHITE),
21+
'name' : (Color.DARK_GREEN, Color.WHITE),
2222
'unread' : (Color.DARK_GRAY, Color.LIGHT_GRAY),
2323
'user_active' : (Color.DARK_GREEN, Color.WHITE),
2424
'user_idle' : (Color.DARK_BLUE, Color.WHITE),

zulipterminal/ui_tools/boxes.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(self, view: Any) -> None:
7676
super().__init__(self.main_view(True))
7777
self.model = view.model
7878
self.view = view
79+
7980
# Used to indicate user's compose status, "closed" by default
8081
self.compose_box_status: Literal[
8182
"open_with_private", "open_with_stream", "closed"
@@ -574,9 +575,7 @@ def autocomplete_mentions(
574575
return combined_typeahead, combined_names
575576

576577
def autocomplete_users(
577-
self,
578-
text: str,
579-
prefix_string: str,
578+
self, text: str, prefix_string: str
580579
) -> Tuple[List[str], List[str]]:
581580
users_list = self.view.users
582581
matching_users = [
@@ -1531,7 +1530,9 @@ def main_view(self) -> List[Any]:
15311530
"author": (
15321531
msg["sender_full_name"] if "sender_full_name" in msg else None
15331532
),
1534-
"author_id": (msg["sender_id"] if "sender_id" in msg else None),
1533+
"author_id":(
1534+
msg["sender_id"] if "sender_id" in msg else None
1535+
),
15351536
"time": (
15361537
self.model.formatted_local_time(
15371538
msg["timestamp"], show_seconds=False
@@ -1549,8 +1550,7 @@ def main_view(self) -> List[Any]:
15491550
}
15501551
different = { # How this message differs from the previous one
15511552
"recipients": recipient_header is not None,
1552-
"author": message["this"]["author"] != message["last"]["author"],
1553-
"author_id": message["this"]["author_id"] != message["last"]["author_id"],
1553+
"author": message["this"]["author_id"] != message["last"]["author_id"],
15541554
"24h": (
15551555
message["last"]["datetime"] is not None
15561556
and ((message["this"]["datetime"] - message["last"]["datetime"]).days)
@@ -1566,19 +1566,12 @@ def main_view(self) -> List[Any]:
15661566
any_differences = any(different.values())
15671567

15681568
if any_differences: # Construct content_header, if needed
1569-
TextType = Dict[str, List[urwid_MarkupTuple]]
1570-
text_keys = ("author", "star", "time", "status", "author_id")
1571-
text: TextType = {key: [(None, " ")] for key in text_keys}
1572-
if any(
1573-
different[key] for key in ("recipients", "author", "24h", "author_id")
1574-
):
1575-
if self.model.user_name_count_compare(message["this"]["author"]):
1576-
text["author"] = [
1577-
("msg_sender", message["this"]["author"]),
1578-
("msg_mention", "(" + str(message["this"]["author_id"]) + ")"),
1579-
]
1580-
else:
1581-
text["author"] = [("msg_sender", message["this"]["author"])]
1569+
TextType = Dict[str, urwid_MarkupTuple]
1570+
text_keys = ("author", "star", "time", "status")
1571+
text: TextType = {key: (None, " ") for key in text_keys}
1572+
1573+
if any(different[key] for key in ("recipients", "author", "24h")):
1574+
text["author"] = ("name", message["this"]["author"])
15821575

15831576
# TODO: Refactor to use user ids for look up instead of emails.
15841577
email = self.message.get("sender_email", "")
@@ -1589,17 +1582,17 @@ def main_view(self) -> List[Any]:
15891582

15901583
# The default text['status'] value is (None, ' ')
15911584
if status in STATE_ICON:
1592-
text["status"] = [(f"user_{status}", STATE_ICON[status])]
1585+
text["status"] = (f"user_{status}", STATE_ICON[status])
15931586

15941587
if message["this"]["is_starred"]:
1595-
text["star"] = [("starred", "*")]
1588+
text["star"] = ("starred", "*")
15961589
if any(different[key] for key in ("recipients", "author", "timestamp")):
15971590
this_year = date.today().year
15981591
msg_year = message["this"]["datetime"].year
15991592
if this_year != msg_year:
1600-
text["time"] = [("time", f"{msg_year} - {message['this']['time']}")]
1593+
text["time"] = ("time", f"{msg_year} - {message['this']['time']}")
16011594
else:
1602-
text["time"] = [("time", message["this"]["time"])]
1595+
text["time"] = ("time", message["this"]["time"])
16031596

16041597
content_header = urwid.Columns(
16051598
[

0 commit comments

Comments
 (0)