Skip to content

Commit 24801a8

Browse files
committed
conversation: Add recent conversations view to zulip-terminal.
Implemented a new RecentConversationsView in ui_tools/views.py to display recent conversation data fetched via model.py. Updated core.py and ui.py to integrate this view into the main application flow. Modified cli/run.py to support initialization of conversation data, and adjusted keys.py and ui_sizes.py for navigation and layout consistency. Added button support in ui_tools/buttons.py for interacting with conversations. This enhances zulip-terminal’s interactivity by allowing users to view and navigate recent conversations, addressing requirements from issue #1565. Fixes #1565.
1 parent 1dca8e9 commit 24801a8

File tree

6 files changed

+135
-78
lines changed

6 files changed

+135
-78
lines changed

zulipterminal/cli/run.py

-1
Original file line numberDiff line numberDiff line change
@@ -696,4 +696,3 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:
696696

697697
if __name__ == "__main__":
698698
main()
699-

zulipterminal/core.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
StreamInfoView,
4848
StreamMembersView,
4949
UserInfoView,
50-
5150
)
5251
from zulipterminal.version import ZT_VERSION
5352

@@ -598,7 +597,7 @@ def _narrow_to(self, anchor: Optional[int], **narrow: Any) -> None:
598597

599598
if already_narrowed and anchor is None:
600599
return
601-
600+
602601
msg_id_list = self.model.get_message_ids_in_current_narrow()
603602

604603
# If no messages are found in the current narrow

zulipterminal/model.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections import defaultdict
99
from concurrent.futures import Future, ThreadPoolExecutor, wait
1010
from copy import deepcopy
11-
from datetime import datetime,timezone
11+
from datetime import datetime, timezone
1212
from typing import (
1313
Any,
1414
Callable,
@@ -314,7 +314,6 @@ def set_narrow(
314314
frozenset(["pm_with"]): [["pm-with", pm_with]],
315315
frozenset(["starred"]): [["is", "starred"]],
316316
frozenset(["mentioned"]): [["is", "mentioned"]],
317-
318317
}
319318
for narrow_param, narrow in valid_narrows.items():
320319
if narrow_param == selected_params:
@@ -856,7 +855,6 @@ def modernize_message_response(message: Message) -> Message:
856855
message["topic_links"] = topic_links
857856

858857
return message
859-
860858

861859
def fetch_message_history(
862860
self, message_id: int
@@ -1095,10 +1093,13 @@ def get_other_subscribers_in_stream(
10951093
if stream["name"] == stream_name
10961094
if sub != self.user_id
10971095
]
1096+
10981097
def group_recent_conversations(self) -> List[Dict[str, Any]]:
10991098
"""Return the 10 most recent stream conversations."""
11001099
# Filter for stream messages
1101-
stream_msgs = [m for m in self.index["messages"].values() if m["type"] == "stream"]
1100+
stream_msgs = [
1101+
m for m in self.index["messages"].values() if m["type"] == "stream"
1102+
]
11021103
if not stream_msgs:
11031104
return []
11041105

@@ -1114,11 +1115,13 @@ def group_recent_conversations(self) -> List[Dict[str, Any]]:
11141115
processed_conversations = []
11151116
now = datetime.now(timezone.utc)
11161117
for (stream_id, topic), msg_list in sorted(
1117-
convos.items(), key=lambda x: max(m["timestamp"] for m in x[1]), reverse=True
1118+
convos.items(),
1119+
key=lambda x: max(m["timestamp"] for m in x[1]),
1120+
reverse=True,
11181121
)[:10]:
11191122
# Map stream_id to stream name
11201123

1121-
stream_name=self.stream_name_from_id(stream_id)
1124+
stream_name = self.stream_name_from_id(stream_id)
11221125
topic_name = topic if topic else "(no topic)"
11231126

11241127
# Extract participants
@@ -1137,14 +1140,17 @@ def group_recent_conversations(self) -> List[Dict[str, Any]]:
11371140
hours = delta.seconds // 3600
11381141
time_str = f"{hours} hours ago" if hours > 0 else "just now"
11391142

1140-
processed_conversations.append({
1141-
"stream": stream_name,
1142-
"topic": topic_name,
1143-
"participants": list(participants),
1144-
"time": time_str,
1145-
})
1143+
processed_conversations.append(
1144+
{
1145+
"stream": stream_name,
1146+
"topic": topic_name,
1147+
"participants": list(participants),
1148+
"time": time_str,
1149+
}
1150+
)
1151+
1152+
return processed_conversations
11461153

1147-
return processed_conversations
11481154
def _clean_and_order_custom_profile_data(
11491155
self, custom_profile_data: Dict[str, CustomFieldValue]
11501156
) -> List[CustomProfileData]:
@@ -1467,7 +1473,8 @@ def stream_id_from_name(self, stream_name: str) -> int:
14671473
if stream["name"] == stream_name:
14681474
return stream_id
14691475
raise RuntimeError("Invalid stream name.")
1470-
def stream_name_from_id(self,stream_id:int)->str:
1476+
1477+
def stream_name_from_id(self, stream_id: int) -> str:
14711478
return self.stream_dict[stream_id]["name"]
14721479

14731480
def stream_access_type(self, stream_id: int) -> StreamAccessType:

zulipterminal/ui.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def middle_column_view(self) -> Any:
7272
self.middle_column = MiddleColumnView(
7373
self, self.model, self.write_box, self.search_box
7474
)
75-
75+
7676
return urwid.LineBox(
7777
self.middle_column,
7878
title="Messages",

zulipterminal/ui_tools/buttons.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
MENTIONED_MESSAGES_MARKER,
2525
MUTE_MARKER,
2626
STARRED_MESSAGES_MARKER,
27-
TIME_MENTION_MARKER
27+
TIME_MENTION_MARKER,
2828
)
2929
from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS, STREAM_ACCESS_TYPE
3030
from zulipterminal.helper import StreamData, hash_util_decode, process_media
@@ -130,9 +130,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
130130

131131
class HomeButton(TopButton):
132132
def __init__(self, *, controller: Any, count: int) -> None:
133-
button_text = (
134-
f"All messages [{primary_display_key_for_command('ALL_MESSAGES')}]"
135-
)
133+
button_text = f"All messages [{primary_display_key_for_command('ALL_MESSAGES')}]"
136134

137135
super().__init__(
138136
controller=controller,
@@ -146,7 +144,9 @@ def __init__(self, *, controller: Any, count: int) -> None:
146144

147145
class PMButton(TopButton):
148146
def __init__(self, *, controller: Any, count: int) -> None:
149-
button_text = f"Direct messages [{primary_display_key_for_command('ALL_PM')}]"
147+
button_text = (
148+
f"Direct messages [{primary_display_key_for_command('ALL_PM')}]"
149+
)
150150

151151
super().__init__(
152152
controller=controller,
@@ -160,9 +160,7 @@ def __init__(self, *, controller: Any, count: int) -> None:
160160

161161
class MentionedButton(TopButton):
162162
def __init__(self, *, controller: Any, count: int) -> None:
163-
button_text = (
164-
f"Mentions [{primary_display_key_for_command('ALL_MENTIONS')}]"
165-
)
163+
button_text = f"Mentions [{primary_display_key_for_command('ALL_MENTIONS')}]"
166164

167165
super().__init__(
168166
controller=controller,
@@ -172,11 +170,11 @@ def __init__(self, *, controller: Any, count: int) -> None:
172170
show_function=controller.narrow_to_all_mentions,
173171
count=count,
174172
)
175-
class TimeMentionedButton(TopButton):
173+
174+
175+
class TimeMentionedButton(TopButton):
176176
def __init__(self, *, controller: Any, count: int) -> None:
177-
button_text = (
178-
f"Recent Conversations [{primary_display_key_for_command('OPEN_RECENT_CONVERSATIONS')}]"
179-
)
177+
button_text = f"Recent Conversations [{primary_display_key_for_command('OPEN_RECENT_CONVERSATIONS')}]"
180178
super().__init__(
181179
controller=controller,
182180
prefix_markup=("title", TIME_MENTION_MARKER),

0 commit comments

Comments
 (0)