mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-09-21 11:18:50 +03:00
Fix edits in custom.Conversation
This commit is contained in:
parent
216805d62d
commit
06da651f27
|
@ -196,13 +196,16 @@ class Conversation(ChatGetter):
|
||||||
target_date = self._edit_dates.get(target_id, 0)
|
target_date = self._edit_dates.get(target_id, 0)
|
||||||
earliest_edit = min(
|
earliest_edit = min(
|
||||||
(x for x in self._incoming
|
(x for x in self._incoming
|
||||||
if x.id > target_id and x.date.timestamp() > target_date),
|
if x.edit_date
|
||||||
key=lambda x: x.date,
|
and x.id > target_id
|
||||||
|
and x.edit_date.timestamp() > target_date
|
||||||
|
),
|
||||||
|
key=lambda x: x.edit_date.timestamp(),
|
||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
|
|
||||||
if earliest_edit and earliest_edit.date.timestamp() > target_date:
|
if earliest_edit and earliest_edit.edit_date.timestamp() > target_date:
|
||||||
self._edit_dates[target_id] = earliest_edit.timestamp()
|
self._edit_dates[target_id] = earliest_edit.edit_date.timestamp()
|
||||||
return earliest_edit
|
return earliest_edit
|
||||||
|
|
||||||
# Otherwise the next incoming response will be the one to use
|
# Otherwise the next incoming response will be the one to use
|
||||||
|
@ -293,6 +296,7 @@ class Conversation(ChatGetter):
|
||||||
fut.set_result(built[ev_type])
|
fut.set_result(built[ev_type])
|
||||||
|
|
||||||
def _on_new_message(self, response):
|
def _on_new_message(self, response):
|
||||||
|
response = response.message
|
||||||
if response.chat_id != self.chat_id or response.out:
|
if response.chat_id != self.chat_id or response.out:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -319,24 +323,20 @@ class Conversation(ChatGetter):
|
||||||
for msg_id in found:
|
for msg_id in found:
|
||||||
self._pending_replies.pop(msg_id).set_result(response)
|
self._pending_replies.pop(msg_id).set_result(response)
|
||||||
|
|
||||||
# TODO Edits are different since they work by date not indices
|
|
||||||
# That is, we need to scan all incoming messages and detect if
|
|
||||||
# the last used edit date is different from the one we knew.
|
|
||||||
def _on_edit(self, message):
|
def _on_edit(self, message):
|
||||||
|
message = message.message
|
||||||
if message.chat_id != self.chat_id or message.out:
|
if message.chat_id != self.chat_id or message.out:
|
||||||
return
|
return
|
||||||
|
|
||||||
found = []
|
found = []
|
||||||
for msg_id, pending in self._pending_edits.items():
|
for msg_id, pending in self._pending_edits.items():
|
||||||
if msg_id == message.id:
|
if msg_id < message.id:
|
||||||
found.append(msg_id)
|
found.append(msg_id)
|
||||||
self._edit_dates[msg_id] = message.date.timestamp()
|
self._edit_dates[msg_id] = message.edit_date.timestamp()
|
||||||
|
|
||||||
for msg_id in found:
|
for msg_id in found:
|
||||||
self._pending_edits.pop(msg_id).set_result(message)
|
self._pending_edits.pop(msg_id).set_result(message)
|
||||||
|
|
||||||
# TODO Support custom events in a comfortable way
|
|
||||||
|
|
||||||
def _on_read(self, event):
|
def _on_read(self, event):
|
||||||
if event.chat_id != self.chat_id or event.inbox:
|
if event.chat_id != self.chat_id or event.inbox:
|
||||||
return
|
return
|
||||||
|
@ -378,7 +378,7 @@ class Conversation(ChatGetter):
|
||||||
for pending in itertools.chain(
|
for pending in itertools.chain(
|
||||||
self._pending_responses.values(),
|
self._pending_responses.values(),
|
||||||
self._pending_replies.values(),
|
self._pending_replies.values(),
|
||||||
self._pending_edits):
|
self._pending_edits.values()):
|
||||||
if exception:
|
if exception:
|
||||||
pending.set_exception(exception)
|
pending.set_exception(exception)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user