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"]) 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