fix: test for callback existance before running it

This commit is contained in:
əlemi 2024-01-29 17:46:32 +01:00
parent f570579fb4
commit 7183358f48
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -58,11 +58,9 @@ class AppService:
self.logger.warn("unhandled event of type %s, ignoring", event["type"])
continue
self.logger.debug("dispatching event %s for %s", event.type)
if event.type not in self._callbacks:
self._callbacks[event.type] = {}
asyncio.get_event_loop().create_task(
self._callbacks[event.type][event.room_id](event)
)
callback = self._callbacks.get(event.type, {}).get(event.room_id, None)
if callback is not None:
asyncio.get_event_loop().create_task(callback(event))
return web.Response()
@ -72,6 +70,8 @@ class AppService:
key = EventType[event]
else:
key = event
if event.type not in self._callbacks:
self._callbacks[event.type] = {}
self._callbacks[key][room] = func
return func
return wrapper