mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 10:38:23 +00:00
Refactor update_msg method to match update_chat
This commit is contained in:
parent
27a89e7745
commit
b84ebdb0d1
2 changed files with 4 additions and 16 deletions
12
tg/models.py
12
tg/models.py
|
@ -283,14 +283,6 @@ class MsgModel:
|
|||
msg_set.remove(msg_id)
|
||||
return True
|
||||
|
||||
def update_msg_content(
|
||||
self, chat_id: int, msg_id: int, message_content: Dict[str, Any]
|
||||
) -> bool:
|
||||
log.info(f"updating {msg_id=} {message_content=}")
|
||||
return self.update_msg_fields(
|
||||
chat_id, msg_id, fields=dict(content=message_content)
|
||||
)
|
||||
|
||||
def update_msg_content_opened(self, chat_id: int, msg_id: int):
|
||||
for message in self.msgs[chat_id]:
|
||||
if message["id"] != msg_id:
|
||||
|
@ -305,9 +297,7 @@ class MsgModel:
|
|||
# https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1update_message_content_opened.html
|
||||
return
|
||||
|
||||
def update_msg_fields(
|
||||
self, chat_id: int, msg_id: int, fields: Dict[str, Any]
|
||||
):
|
||||
def update_msg(self, chat_id: int, msg_id: int, **fields: Dict[str, Any]):
|
||||
msg = None
|
||||
for message in self.msgs[chat_id]:
|
||||
if message["id"] == msg_id:
|
||||
|
|
|
@ -41,8 +41,8 @@ def update_handler(update_type):
|
|||
def update_message_content(controller: Controller, update: Dict[str, Any]):
|
||||
chat_id = update["chat_id"]
|
||||
message_id = update["message_id"]
|
||||
controller.model.msgs.update_msg_content(
|
||||
chat_id, message_id, update["new_content"]
|
||||
controller.model.msgs.update_msg(
|
||||
chat_id, message_id, content=update["new_content"]
|
||||
)
|
||||
|
||||
current_chat_id = controller.model.current_chat_id
|
||||
|
@ -55,9 +55,7 @@ def update_message_edited(controller: Controller, update: Dict[str, Any]):
|
|||
chat_id = update["chat_id"]
|
||||
message_id = update["message_id"]
|
||||
edit_date = update["edit_date"]
|
||||
controller.model.msgs.update_msg_fields(
|
||||
chat_id, message_id, fields=dict(edit_date=edit_date)
|
||||
)
|
||||
controller.model.msgs.update_msg(chat_id, message_id, edit_date=edit_date)
|
||||
|
||||
current_chat_id = controller.model.current_chat_id
|
||||
if current_chat_id == chat_id:
|
||||
|
|
Loading…
Add table
Reference in a new issue