Skip to content

Added recent conversations #1566

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,4 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:

if __name__ == "__main__":
main()

10 changes: 10 additions & 0 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class KeyBinding(TypedDict):
'help_text': 'Send a message',
'key_category': 'compose_box',
},
'OPEN_RECENT_CONVERSATIONS': {
'keys': ['^'],
'help_text': 'Open recent conversations',
'key_category': 'navigation',
},
'SAVE_AS_DRAFT': {
'keys': ['meta s'],
'help_text': 'Save current message as a draft',
Expand Down Expand Up @@ -209,6 +214,11 @@ class KeyBinding(TypedDict):
'help_text': 'Toggle topics in a stream',
'key_category': 'stream_list',
},
"SEARCH_RECENT_CONVERSATIONS": {
"keys": ["ctrl+f"],
"help_text": "Search recent conversations",
"key_category": "navigation"
},
'ALL_MESSAGES': {
'keys': ['a', 'esc'],
'help_text': 'View all messages',
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/config/ui_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

TAB_WIDTH = 3
LEFT_WIDTH = 31
LEFT_WIDTH = 32
RIGHT_WIDTH = 23

# These affect popup width-scaling, dependent upon window width
Expand Down
4 changes: 3 additions & 1 deletion zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
StreamInfoView,
StreamMembersView,
UserInfoView,

)
from zulipterminal.version import ZT_VERSION

Expand Down Expand Up @@ -593,10 +594,11 @@ def copy_to_clipboard(self, text: str, text_category: str) -> None:

def _narrow_to(self, anchor: Optional[int], **narrow: Any) -> None:
already_narrowed = self.model.set_narrow(**narrow)
self.view.middle_column.set_view("messages")

if already_narrowed and anchor is None:
return

msg_id_list = self.model.get_message_ids_in_current_narrow()

# If no messages are found in the current narrow
Expand Down
56 changes: 54 additions & 2 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from concurrent.futures import Future, ThreadPoolExecutor, wait
from copy import deepcopy
from datetime import datetime
from datetime import datetime,timezone
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -116,7 +116,6 @@ def __init__(self, controller: Any) -> None:
self.recipients: FrozenSet[Any] = frozenset()
self.index = initial_index
self.last_unread_pm = None

self.user_id = -1
self.user_email = ""
self.user_full_name = ""
Expand Down Expand Up @@ -315,6 +314,7 @@ def set_narrow(
frozenset(["pm_with"]): [["pm-with", pm_with]],
frozenset(["starred"]): [["is", "starred"]],
frozenset(["mentioned"]): [["is", "mentioned"]],

}
for narrow_param, narrow in valid_narrows.items():
if narrow_param == selected_params:
Expand Down Expand Up @@ -856,6 +856,7 @@ def modernize_message_response(message: Message) -> Message:
message["topic_links"] = topic_links

return message


def fetch_message_history(
self, message_id: int
Expand Down Expand Up @@ -1094,7 +1095,56 @@ def get_other_subscribers_in_stream(
if stream["name"] == stream_name
if sub != self.user_id
]
def group_recent_conversations(self) -> List[Dict[str, Any]]:
"""Return the 10 most recent stream conversations."""
# Filter for stream messages
stream_msgs = [m for m in self.index["messages"].values() if m["type"] == "stream"]
if not stream_msgs:
return []

# Sort messages by timestamp (most recent first)
stream_msgs.sort(key=lambda x: x["timestamp"], reverse=True)

# Group messages by stream and topic
convos = defaultdict(list)
for msg in stream_msgs[:50]: # Limit to 50 recent messages
convos[(msg["stream_id"], msg["subject"])].append(msg)

# Process conversations into the desired format
processed_conversations = []
now = datetime.now(timezone.utc)
for (stream_id, topic), msg_list in sorted(
convos.items(), key=lambda x: max(m["timestamp"] for m in x[1]), reverse=True
)[:10]:
# Map stream_id to stream name

stream_name=self.stream_name_from_id(stream_id)
topic_name = topic if topic else "(no topic)"

# Extract participants
participants = set()
for msg in msg_list:
participants.add(msg["sender_full_name"])

# Format timestamp (using the most recent message in the conversation)
most_recent_msg = max(msg_list, key=lambda x: x["timestamp"])
timestamp = most_recent_msg["timestamp"]
conv_time = datetime.fromtimestamp(timestamp, tz=timezone.utc)
delta = now - conv_time
if delta.days > 0:
time_str = f"{delta.days} days ago"
else:
hours = delta.seconds // 3600
time_str = f"{hours} hours ago" if hours > 0 else "just now"

processed_conversations.append({
"stream": stream_name,
"topic": topic_name,
"participants": list(participants),
"time": time_str,
})

return processed_conversations
def _clean_and_order_custom_profile_data(
self, custom_profile_data: Dict[str, CustomFieldValue]
) -> List[CustomProfileData]:
Expand Down Expand Up @@ -1417,6 +1467,8 @@ def stream_id_from_name(self, stream_name: str) -> int:
if stream["name"] == stream_name:
return stream_id
raise RuntimeError("Invalid stream name.")
def stream_name_from_id(self,stream_id:int)->str:
return self.stream_dict[stream_id]["name"]

def stream_access_type(self, stream_id: int) -> StreamAccessType:
if stream_id not in self.stream_dict:
Expand Down
3 changes: 3 additions & 0 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def middle_column_view(self) -> Any:
self.middle_column = MiddleColumnView(
self, self.model, self.write_box, self.search_box
)

return urwid.LineBox(
self.middle_column,
title="Messages",
Expand Down Expand Up @@ -273,6 +274,8 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
self.pm_button.activate(key)
elif is_command_key("ALL_STARRED", key):
self.starred_button.activate(key)
elif is_command_key("OPEN_RECENT_CONVERSATIONS", key):
self.time_button.activate(key)
elif is_command_key("ALL_MENTIONS", key):
self.mentioned_button.activate(key)
elif is_command_key("SEARCH_PEOPLE", key):
Expand Down
25 changes: 21 additions & 4 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MENTIONED_MESSAGES_MARKER,
MUTE_MARKER,
STARRED_MESSAGES_MARKER,
TIME_MENTION_MARKER
)
from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS, STREAM_ACCESS_TYPE
from zulipterminal.helper import StreamData, hash_util_decode, process_media
Expand Down Expand Up @@ -130,7 +131,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
class HomeButton(TopButton):
def __init__(self, *, controller: Any, count: int) -> None:
button_text = (
f"All messages [{primary_display_key_for_command('ALL_MESSAGES')}]"
f"All messages [{primary_display_key_for_command('ALL_MESSAGES')}]"
)

super().__init__(
Expand All @@ -145,7 +146,7 @@ def __init__(self, *, controller: Any, count: int) -> None:

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

super().__init__(
controller=controller,
Expand All @@ -160,7 +161,7 @@ def __init__(self, *, controller: Any, count: int) -> None:
class MentionedButton(TopButton):
def __init__(self, *, controller: Any, count: int) -> None:
button_text = (
f"Mentions [{primary_display_key_for_command('ALL_MENTIONS')}]"
f"Mentions [{primary_display_key_for_command('ALL_MENTIONS')}]"
)

super().__init__(
Expand All @@ -171,12 +172,28 @@ def __init__(self, *, controller: Any, count: int) -> None:
show_function=controller.narrow_to_all_mentions,
count=count,
)
class TimeMentionedButton(TopButton):
def __init__(self, *, controller: Any, count: int) -> None:
button_text = (
f"Recent Conversations [{primary_display_key_for_command('OPEN_RECENT_CONVERSATIONS')}]"
)
super().__init__(
controller=controller,
prefix_markup=("title", TIME_MENTION_MARKER),
label_markup=(None, button_text),
suffix_markup=("unread_count", f" ({count})" if count > 0 else ""),
show_function=self.show_recent_conversations,
count=count,
)

def show_recent_conversations(self) -> None:
self.controller.view.middle_column.set_view("recent")


class StarredButton(TopButton):
def __init__(self, *, controller: Any, count: int) -> None:
button_text = (
f"Starred messages [{primary_display_key_for_command('ALL_STARRED')}]"
f"Starred messages [{primary_display_key_for_command('ALL_STARRED')}]"
)

super().__init__(
Expand Down
Loading
Loading