Simplify event resolving logic

Although this commit introduces a race condition since an
event may only be half-resolved. A lock is thus needed,
but it depends on an event-loop to which we don't have
access in the class-level.
This commit is contained in:
Lonami Exo
2018-08-21 11:08:08 +02:00
parent 9f237cc928
commit d474458136
6 changed files with 26 additions and 31 deletions

View File

@@ -57,7 +57,7 @@ class EventBuilder(abc.ABC):
def __init__(self, chats=None, blacklist_chats=False):
self.chats = chats
self.blacklist_chats = blacklist_chats
self._self_id = None
self.resolved = False
@classmethod
@abc.abstractmethod
@@ -66,9 +66,11 @@ class EventBuilder(abc.ABC):
async def resolve(self, client):
"""Helper method to allow event builders to be resolved before usage"""
self.chats = await _into_id_set(client, self.chats)
if not EventBuilder.self_id:
EventBuilder.self_id = await client.get_peer_id('me')
if not self.resolved:
self.resolved = True
self.chats = await _into_id_set(client, self.chats)
if not EventBuilder.self_id:
EventBuilder.self_id = await client.get_peer_id('me')
def filter(self, event):
"""