diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index 5986e53..dd2539a 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -185,6 +185,10 @@ async def close_channel(channel_id): WHERE id = $1 """, channel_id) + # clean its member list representation + lazy_guilds = app.dispatcher.backends['lazy_guild'] + lazy_guilds.remove_channel(channel_id) + await app.dispatcher.dispatch_guild( guild_id, 'CHANNEL_DELETE', chan) return jsonify(chan) @@ -404,6 +408,8 @@ async def update_channel(channel_id): await update_handler(channel_id, j) chan = await app.storage.get_channel(channel_id) + + await app.dispatcher.dispatch('guild', guild_id, 'CHANNEL_UPDATE', chan) return jsonify(chan) @@ -498,6 +504,7 @@ async def _search_channel(channel_id): user_id = await token_check() await channel_check(user_id, channel_id) await channel_perm_check(user_id, channel_id, 'read_messages') + j = validate(request.args, SEARCH_CHANNEL) # main message ids diff --git a/litecord/pubsub/lazy_guild.py b/litecord/pubsub/lazy_guild.py index fe4c3d0..c7bb4b1 100644 --- a/litecord/pubsub/lazy_guild.py +++ b/litecord/pubsub/lazy_guild.py @@ -1264,6 +1264,17 @@ class GuildMemberList: return await self.resync(sess_ids_resync, role_item_index) + def close(self): + """Remove data.""" + log.info('closing GML gid={} cid={}, {} subscribers', + self.guild_id, self.channel_id, len(self.state)) + + self.guild_id = None + self.channel_id = None + self.main = None + self.list = MemberList + self.state = {} + class LazyGuildDispatcher(Dispatcher): """Main class holding the member lists for lazy guilds.""" @@ -1327,6 +1338,19 @@ class LazyGuildDispatcher(Dispatcher): await handler(guild_id, *args, **kwargs) + def remove_channel(self, channel_id: int): + """Remove a channel from the manager.""" + try: + gml = self.state.pop(channel_id) + gml.close() + except KeyError: + pass + + async def chan_update(self, channel_id: int): + """Signal a channel update to a member list.""" + gml = await self.get_gml(channel_id) + await gml.chan_update() + async def _call_all_lists(self, guild_id, method_str: str, *args): lists = self.get_gml_guild(guild_id)