Support stopping propagation of events (#622)

This commit is contained in:
Joscha Götzer
2018-02-27 11:30:42 +01:00
committed by Lonami
parent 29f10f2771
commit 0b662f3b04
3 changed files with 59 additions and 1 deletions

View File

@@ -1885,7 +1885,15 @@ class TelegramClient(TelegramBareClient):
event = builder.build(update)
if event:
event._client = self
callback(event)
try:
callback(event)
except events.StopPropagation:
__log__.debug(
"Event handler '{}' stopped chain of "
"propagation for event {}."
.format(callback.__name__, type(event).__name__)
)
break
def add_event_handler(self, callback, event=None):
"""