Show reply markup

This commit is contained in:
lightme16 2020-10-10 16:30:21 +03:00
parent 3ab0779c61
commit 40d56d4baa
5 changed files with 58 additions and 15 deletions

View file

@ -424,7 +424,8 @@ class Controller:
self.tg.send_video(file_path, chat_id, width, height, duration)
def send_file(
self, send_file_fun: Callable[[str, int], AsyncResult],
self,
send_file_fun: Callable[[str, int], AsyncResult],
) -> None:
_input = self.view.status.get_input()
if _input is None:
@ -548,7 +549,10 @@ class Controller:
def _get_user_ids(self, is_multiple: bool = False) -> List[int]:
users = self.model.users.get_users()
_, cols = self.view.stdscr.getmaxyx()
limit = min(int(cols / 2), max(len(user.name) for user in users),)
limit = min(
int(cols / 2),
max(len(user.name) for user in users),
)
users_out = "\n".join(
f"{user.id}\t{user.name:<{limit}} | {user.status}"
for user in sorted(users, key=lambda user: user.order)

View file

@ -203,6 +203,10 @@ class MsgProxy:
def reply_msg_id(self) -> Optional[int]:
return self.msg.get("reply_to_message_id")
@property
def reply_markup(self) -> Optional[Dict[str, Any]]:
return self.msg.get("reply_markup")
@property
def chat_id(self) -> int:
return self.msg["chat_id"]

View file

@ -294,35 +294,50 @@ class Tdlib(Telegram):
}
return self._send_data(data)
def get_basic_group(self, basic_group_id: int,) -> AsyncResult:
def get_basic_group(
self,
basic_group_id: int,
) -> AsyncResult:
data = {
"@type": "getBasicGroup",
"basic_group_id": basic_group_id,
}
return self._send_data(data)
def get_basic_group_full_info(self, basic_group_id: int,) -> AsyncResult:
def get_basic_group_full_info(
self,
basic_group_id: int,
) -> AsyncResult:
data = {
"@type": "getBasicGroupFullInfo",
"basic_group_id": basic_group_id,
}
return self._send_data(data)
def get_supergroup(self, supergroup_id: int,) -> AsyncResult:
def get_supergroup(
self,
supergroup_id: int,
) -> AsyncResult:
data = {
"@type": "getSupergroup",
"supergroup_id": supergroup_id,
}
return self._send_data(data)
def get_supergroup_full_info(self, supergroup_id: int,) -> AsyncResult:
def get_supergroup_full_info(
self,
supergroup_id: int,
) -> AsyncResult:
data = {
"@type": "getSupergroupFullInfo",
"supergroup_id": supergroup_id,
}
return self._send_data(data)
def get_secret_chat(self, secret_chat_id: int,) -> AsyncResult:
def get_secret_chat(
self,
secret_chat_id: int,
) -> AsyncResult:
data = {
"@type": "getSecretChat",
"secret_chat_id": secret_chat_id,

View file

@ -102,7 +102,16 @@ def parse_size(size: str) -> int:
def humanize_size(
num: int,
suffix: str = "B",
suffixes: Tuple[str, ...] = ("", "K", "M", "G", "T", "P", "E", "Z",),
suffixes: Tuple[str, ...] = (
"",
"K",
"M",
"G",
"T",
"P",
"E",
"Z",
),
) -> str:
magnitude = int(math.floor(math.log(num, 1024)))
val = num / math.pow(1024, magnitude)

View file

@ -280,7 +280,11 @@ class ChatView:
class MsgView:
def __init__(self, stdscr: window, model: Model,) -> None:
def __init__(
self,
stdscr: window,
model: Model,
) -> None:
self.model = model
self.stdscr = stdscr
self.h = 0
@ -353,7 +357,8 @@ class MsgView:
msg = f"{reply_line}\n{msg}"
return msg
def _format_url(self, msg_proxy: MsgProxy) -> str:
@staticmethod
def _format_url(msg_proxy: MsgProxy) -> str:
if not msg_proxy.is_text or "web_page" not in msg_proxy.msg["content"]:
return ""
web = msg_proxy.msg["content"]["web_page"]
@ -365,9 +370,7 @@ class MsgView:
url += f"\n | {description}"
return url
def _format_msg(
self, msg_proxy: MsgProxy, user_id_item: int, width_limit: int
) -> str:
def _format_msg(self, msg_proxy: MsgProxy, width_limit: int) -> str:
msg = self._parse_msg(msg_proxy)
if caption := msg_proxy.caption:
msg += "\n" + caption.replace("\n", " ")
@ -376,6 +379,14 @@ class MsgView:
msg = self._format_reply_msg(
msg_proxy.chat_id, msg, reply_to, width_limit
)
if reply_markup := msg_proxy.reply_markup:
for row in reply_markup.get("rows", []):
msg += "\n"
for item in row:
if text := item.get("text"):
msg += f"| {text} "
msg += "|"
return msg
def _collect_msgs_to_draw(
@ -409,12 +420,12 @@ class MsgView:
flags = self._get_flags(msg_proxy)
if user_id and flags:
# if not channel add space between name and flags
flags = " " + flags
flags = f" {flags}"
label_elements = f" {dt} ", user_id, flags
label_len = sum(string_len_dwc(e) for e in label_elements)
msg = self._format_msg(
msg_proxy, user_id_item, width_limit=self.w - label_len - 1
msg_proxy, width_limit=self.w - label_len - 1
)
elements = *label_elements, f" {msg}"
needed_lines = 0