From 24cc9e1d254c3454dcbef052bef0004614d559d0 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 16 Feb 2019 23:22:42 -0300 Subject: [PATCH] channels: use Icon.icon_hash - images: handle generic_get with null icon - images: update group dms on delete icon --- litecord/blueprints/channels.py | 2 +- litecord/images.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index d620268..88f78b7 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -422,7 +422,7 @@ async def _update_group_dm(channel_id: int, j: dict): UPDATE group_dm_channels SET icon = $1 WHERE id = $2 - """, new_icon, channel_id) + """, new_icon.icon_hash, channel_id) @bp.route('/', methods=['PUT', 'PATCH']) diff --git a/litecord/images.py b/litecord/images.py index 8c1012f..854e2b9 100644 --- a/litecord/images.py +++ b/litecord/images.py @@ -274,6 +274,9 @@ class IconManager: async def generic_get(self, scope, key, icon_hash, **kwargs) -> Icon: """Get any icon.""" + if icon_hash is None: + return None + log.debug('GET {} {} {}', scope, key, icon_hash) key = str(key) @@ -406,6 +409,12 @@ class IconManager: WHERE icon = $1 """, icon.icon_hash) + await self.storage.db.execute(""" + UPDATE group_dm_channels + SET icon = NULL + WHERE icon = $1 + """, icon.icon_hash) + await self.storage.db.execute(""" DELETE FROM icons WHERE hash = $1