fix: test for callback existance before running it
This commit is contained in:
parent
f570579fb4
commit
7183358f48
1 changed files with 5 additions and 5 deletions
|
@ -58,11 +58,9 @@ class AppService:
|
||||||
self.logger.warn("unhandled event of type %s, ignoring", event["type"])
|
self.logger.warn("unhandled event of type %s, ignoring", event["type"])
|
||||||
continue
|
continue
|
||||||
self.logger.debug("dispatching event %s for %s", event.type)
|
self.logger.debug("dispatching event %s for %s", event.type)
|
||||||
if event.type not in self._callbacks:
|
callback = self._callbacks.get(event.type, {}).get(event.room_id, None)
|
||||||
self._callbacks[event.type] = {}
|
if callback is not None:
|
||||||
asyncio.get_event_loop().create_task(
|
asyncio.get_event_loop().create_task(callback(event))
|
||||||
self._callbacks[event.type][event.room_id](event)
|
|
||||||
)
|
|
||||||
|
|
||||||
return web.Response()
|
return web.Response()
|
||||||
|
|
||||||
|
@ -72,6 +70,8 @@ class AppService:
|
||||||
key = EventType[event]
|
key = EventType[event]
|
||||||
else:
|
else:
|
||||||
key = event
|
key = event
|
||||||
|
if event.type not in self._callbacks:
|
||||||
|
self._callbacks[event.type] = {}
|
||||||
self._callbacks[key][room] = func
|
self._callbacks[key][room] = func
|
||||||
return func
|
return func
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
Loading…
Reference in a new issue