Refactor update_msg method to match update_chat

This commit is contained in:
Paul Nameless 2020-06-06 18:08:05 +08:00
parent 27a89e7745
commit b84ebdb0d1
2 changed files with 4 additions and 16 deletions

View file

@ -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:

View file

@ -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: