Chux0519/master (#211)

* patch td 1.6.0

* pathced for td 1.6.10

* Fix black formatting

* Fix type formatting

Co-authored-by: hexyoungs <chuxdesign@hotmail.com>
This commit is contained in:
Nameless 2021-04-19 11:03:55 +03:00 committed by GitHub
parent 1cd023afc1
commit c7b08b3efa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 17 deletions

View file

@ -81,7 +81,7 @@ FILE_PICKER_CMD = "ranger --choosefile={file_path}"
DOWNLOAD_DIR = os.path.expanduser("~/Downloads/")
if os.path.isfile(CONFIG_FILE):
config_params = runpy.run_path(CONFIG_FILE)
config_params = runpy.run_path(CONFIG_FILE) # type: ignore
for param, value in config_params.items():
if param.isupper():
globals()[param] = value

View file

@ -52,14 +52,14 @@ def bind(
return fun(*args, **kwargs)
@wraps(fun)
def _no_repeat_factor(self: "Controller", _: bool) -> Any:
def _no_repeat_factor(self: "Controller", _: bool) -> Optional[str]:
return fun(self)
for key in keys:
assert (
key not in binding
), f"Key {key} already binded to {binding[key]}"
binding[key] = fun if repeat_factor else _no_repeat_factor
binding[key] = fun if repeat_factor else _no_repeat_factor # type: ignore
return wrapper
@ -869,7 +869,7 @@ class Controller:
return
# notify
if self.model.is_me(msg["sender_user_id"]):
if self.model.is_me(msg["sender"].get("user_id")):
return
user = self.model.users.get_user(msg.sender_id)
name = f"{user['first_name']} {user['last_name']}"

View file

@ -175,7 +175,8 @@ class Model:
return False
def can_be_deleted(self, chat_id: int, msg: Dict[str, Any]) -> bool:
if chat_id == msg["sender_user_id"]:
c_id = msg["sender"].get("chat_id") or msg["sender"].get("user_id")
if chat_id == c_id:
return msg["can_be_deleted_only_for_self"]
return msg["can_be_deleted_for_all_users"]
@ -436,6 +437,12 @@ class ChatModel:
chat_id = chat["id"]
if chat_id in self.chat_ids:
return
if len(chat["positions"]) > 0:
chat["order"] = chat["positions"][0]["order"]
else:
chat["order"] = 0 # str(sys.maxsize)
if int(chat["order"]) == 0:
self.inactive_chats[chat_id] = chat
return
@ -811,10 +818,10 @@ class UserModel:
if user_id == 0:
return ""
user = self.get_user(user_id)
if user["first_name"] and user["last_name"]:
if user.get("first_name") and user.get("last_name"):
return f'{user["first_name"]} {user["last_name"]}'[:20]
if user["first_name"]:
if user.get("first_name"):
return f'{user["first_name"]}'[:20]
if user.get("username"):

View file

@ -218,7 +218,9 @@ class MsgProxy:
@property
def sender_id(self) -> int:
return self.msg["sender_user_id"]
return self.msg["sender"].get("user_id") or self.msg["sender"].get(
"chat_id"
)
@property
def forward(self) -> Optional[Dict[str, Any]]:

View file

@ -79,6 +79,7 @@ def update_new_message(controller: Controller, update: Dict[str, Any]) -> None:
controller.notify_for_message(msg.chat_id, msg)
# outdated
@update_handler("updateChatOrder")
def update_chat_order(controller: Controller, update: Dict[str, Any]) -> None:
current_chat_id = controller.model.current_chat_id
@ -89,6 +90,20 @@ def update_chat_order(controller: Controller, update: Dict[str, Any]) -> None:
controller.refresh_current_chat(current_chat_id)
@update_handler("updateChatPosition")
def update_chat_position(
controller: Controller, update: Dict[str, Any]
) -> None:
current_chat_id = controller.model.current_chat_id
chat_id = update["chat_id"]
info = {}
info["order"] = update["position"]["order"]
if "is_pinned" in update:
info["is_pinned"] = update["is_pinned"]
if controller.model.chats.update_chat(chat_id, **info):
controller.refresh_current_chat(current_chat_id)
@update_handler("updateChatTitle")
def update_chat_title(controller: Controller, update: Dict[str, Any]) -> None:
chat_id = update["chat_id"]
@ -189,12 +204,14 @@ def update_chat_last_message(
# according to documentation it can be null
log.warning("last_message is null: %s", update)
return
order = update["order"]
info = {}
info["last_message"] = last_message
if len(update["positions"]) > 0:
info["order"] = update["positions"][0]["order"]
current_chat_id = controller.model.current_chat_id
if controller.model.chats.update_chat(
chat_id, last_message=last_message, order=order
):
if controller.model.chats.update_chat(chat_id, **info):
controller.refresh_current_chat(current_chat_id)

View file

@ -240,7 +240,7 @@ class ChatView:
msg = chat.get("last_message")
if (
msg
and self.model.is_me(msg["sender_user_id"])
and self.model.is_me(msg["sender"].get("user_id"))
and msg["id"] > chat["last_read_outbox_message_id"]
and not self.model.is_me(chat["id"])
):
@ -248,7 +248,7 @@ class ChatView:
flags.append("unseen")
elif (
msg
and self.model.is_me(msg["sender_user_id"])
and self.model.is_me(msg["sender"].get("user_id"))
and msg["id"] <= chat["last_read_outbox_message_id"]
):
flags.append("seen")
@ -259,7 +259,7 @@ class ChatView:
if self.model.users.is_online(chat["id"]):
flags.append("online")
if chat["is_pinned"]:
if "is_pinned" in chat and chat["is_pinned"]:
flags.append("pinned")
if chat["notification_settings"]["mute_for"]:
@ -363,7 +363,7 @@ class MsgView:
return f"\n | photo: {web['url']}"
name = web["site_name"]
title = web["title"]
description = web["description"].replace("\n", "")
description = web["description"]["text"].replace("\n", "")
url = f"\n | {name}: {title}"
if description:
url += f"\n | {description}"
@ -584,7 +584,7 @@ def get_last_msg(
if not last_msg:
return None, "<No messages yet>"
return (
last_msg["sender_user_id"],
last_msg["sender"].get("user_id"),
parse_content(MsgProxy(last_msg), users),
)