remove msgs (#98)

* Delete msgs in batch
This commit is contained in:
Nameless 2020-06-30 22:50:38 +08:00 committed by GitHub
parent d560eee3b7
commit 3ceb816961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View file

@ -328,17 +328,15 @@ class MsgModel:
return result.update
return next(iter(m for m in self.msgs[chat_id] if m["id"] == msg_id))
def remove_message(self, chat_id: int, msg_id: int) -> bool:
msg_set = self.msg_ids[chat_id]
if msg_id not in msg_set:
return False
log.info(f"removing msg {msg_id=}")
def remove_messages(self, chat_id: int, msg_ids: List[int]) -> None:
log.info(f"removing msgs {msg_ids=}")
# FIXME: potential bottleneck, replace with constan time operation
self.msgs[chat_id] = [
m for m in self.msgs[chat_id] if m["id"] != msg_id
m for m in self.msgs[chat_id] if m["id"] not in msg_ids
]
msg_set.remove(msg_id)
return True
msg_set = self.msg_ids[chat_id]
for msg_id in msg_ids:
msg_set.remove(msg_id)
def update_msg_content_opened(self, chat_id: int, msg_id: int) -> None:
for message in self.msgs[chat_id]:

View file

@ -212,7 +212,7 @@ def update_message_send_succeeded(
chat_id = update["message"]["chat_id"]
msg_id = update["old_message_id"]
controller.model.msgs.add_message(chat_id, update["message"])
controller.model.msgs.remove_message(chat_id, msg_id)
controller.model.msgs.remove_messages(chat_id, [msg_id])
current_chat_id = controller.model.current_chat_id
if current_chat_id == chat_id:
@ -256,8 +256,7 @@ def update_delete_messages(
) -> None:
chat_id = update["chat_id"]
msg_ids = update["message_ids"]
for msg_id in msg_ids:
controller.model.msgs.remove_message(chat_id, msg_id)
controller.model.msgs.remove_messages(chat_id, msg_ids)
controller.render_msgs()