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 chat and chat type to message info form and fixed sender value #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 56 additions & 2 deletions telegramtui/src/MessageInfoForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,57 @@
from telegramtui.src.config import get_config


def generate_user_name(user):
"$firstname $lastname (@$username) (id $id)"
out = str(user.first_name)
if user.last_name:
out += " {}".format(user.last_name)
if user.username:
out += " (@{})".format(user.username)
out += " (id {})".format(user.id)
return out


def generate_chat_name(user):
"$title (@$username) (id $id)"
out = "{}".format(user.title)
if hasattr(user, "username") and user.username:
out += " (@{})".format(user.username)
out += " (id {})".format(user.id)
return out


def _generate_sender(message_info):
# Sender is missing in channels
# channel + group is supergroup
if message_info.is_channel and not message_info.is_group:
if message_info.post_author is not None:
return message_info.post_author
return "None"
return generate_user_name(message_info.sender)


def _generate_chat(message_info):
# Chat object is a user in private chats
if message_info.is_private:
return generate_user_name(message_info.chat)
return generate_chat_name(message_info.chat)


def _generate_chat_type(message_info):
# channel + group is supergroup
if message_info.is_channel:
if message_info.is_group:
return "Super Group"
return "Channel"
if message_info.is_private:
if message_info.sender.bot:
return "Private Chat (Bot)"
return "Private Chat"
if message_info.is_group:
return "Group Chat"


class MessageInfoForm(npyscreen.ActionForm):

def create(self):
Expand All @@ -24,6 +75,8 @@ def create(self):
self.mess_id = self.add(npyscreen.TitleText, name="Message id:", editable=False)
self.date = self.add(npyscreen.TitleText, name="Date: ", editable=False)
self.sender = self.add(npyscreen.TitleText, name="Sender: ", editable=False)
self.chat = self.add(npyscreen.TitleText, name="Chat: ", editable=False)
self.chat_type = self.add(npyscreen.TitleText, name="Chat Type:", editable=False)
self.forward = self.add(npyscreen.TitleText, name="Fwd from: ", editable=False)
self.attachment = self.add(npyscreen.TitleText, name="Attachment:", editable=False)
self.text = self.add(npyscreen.TitleMultiLine, name="Text: ", max_height=5, scroll_exit=True)
Expand All @@ -37,8 +90,9 @@ def update(self):

message_info = client.get_message_by_id(current_user, current_id)
prepared_text = self.prepare_message(message_info.message)

self.sender.value = current_user_name + " (id " + str(client.dialogs[current_user].entity.id) + ")"
self.sender.value = _generate_sender(message_info)
self.chat.value = _generate_chat(message_info)
self.chat_type.value = _generate_chat_type(message_info)
self.mess_id.value = current_id
self.date.value = str(messages[-current_message - 1].date + (timedelta(self.timezone) // 24))
self.attachment.value = self.prepare_media(message_info)
Expand Down