diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index 5cdf9e0..7a649ce 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -141,7 +141,7 @@ async def close_channel(channel_id): ctype = ChannelType(chan_type) if ctype in GUILD_CHANS: - guild_id = await channel_check(user_id, channel_id) + _, guild_id = await channel_check(user_id, channel_id) chan = await app.storage.get_channel(channel_id) # the selected function will take care of checking @@ -256,7 +256,7 @@ async def get_single_message(channel_id, message_id): @bp.route('//messages', methods=['POST']) async def create_message(channel_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) j = validate(await request.get_json(), MESSAGE_CREATE) message_id = get_snowflake() @@ -304,7 +304,7 @@ async def create_message(channel_id): @bp.route('//messages/', methods=['PATCH']) async def edit_message(channel_id, message_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) author_id = await app.db.fetchval(""" SELECT author_id FROM messages @@ -339,7 +339,7 @@ async def edit_message(channel_id, message_id): @bp.route('//messages/', methods=['DELETE']) async def delete_message(channel_id, message_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) author_id = await app.db.fetchval(""" SELECT author_id FROM messages @@ -392,7 +392,7 @@ async def get_pins(channel_id): @bp.route('//pins/', methods=['PUT']) async def add_pin(channel_id, message_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) # TODO: check MANAGE_MESSAGES permission @@ -422,7 +422,7 @@ async def add_pin(channel_id, message_id): @bp.route('//pins/', methods=['DELETE']) async def delete_pin(channel_id, message_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) # TODO: check MANAGE_MESSAGES permission @@ -453,7 +453,7 @@ async def delete_pin(channel_id, message_id): @bp.route('//typing', methods=['POST']) async def trigger_typing(channel_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) # TODO: dispatch_channel await app.dispatcher.dispatch_guild(guild_id, 'TYPING_START', { @@ -508,7 +508,10 @@ async def channel_ack(user_id, guild_id, channel_id, message_id: int = None): @bp.route('//messages//ack', methods=['POST']) async def ack_channel(channel_id, message_id): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + ctype, guild_id = await channel_check(user_id, channel_id) + + if ctype == ChannelType.DM: + guild_id = None await channel_ack(user_id, guild_id, channel_id, message_id) @@ -518,3 +521,16 @@ async def ack_channel(channel_id, message_id): # so we never use it. 'token': None }) + + +@bp.route('//messages/ack', methods=['DELETE']) +async def delete_read_state(channel_id): + user_id = await token_check() + await channel_check(user_id, channel_id) + + await app.db.execute(""" + DELETE FROM user_read_state + WHERE user_id = $1 AND channel_id = $2 + """, user_id, channel_id) + + return '', 204 diff --git a/litecord/blueprints/checks.py b/litecord/blueprints/checks.py index ebd0700..2639c72 100644 --- a/litecord/blueprints/checks.py +++ b/litecord/blueprints/checks.py @@ -34,7 +34,7 @@ async def channel_check(user_id, channel_id): """, channel_id) await guild_check(user_id, guild_id) - return guild_id + return ctype, guild_id if ctype == ChannelType.DM: parties = await app.db.fetchrow(""" @@ -47,4 +47,4 @@ async def channel_check(user_id, channel_id): # get the id of the other party parties.remove(user_id) - return parties[0] + return ctype, parties[0] diff --git a/litecord/blueprints/guilds.py b/litecord/blueprints/guilds.py index 3de2927..86b627c 100644 --- a/litecord/blueprints/guilds.py +++ b/litecord/blueprints/guilds.py @@ -6,7 +6,7 @@ from ..enums import ChannelType from ..errors import Forbidden, GuildNotFound, BadRequest from ..schemas import validate, GUILD_UPDATE from .channels import channel_ack -from .checks import guild_check, channel_check +from .checks import guild_check bp = Blueprint('guilds', __name__) diff --git a/litecord/blueprints/invites.py b/litecord/blueprints/invites.py index bb2308b..011da6a 100644 --- a/litecord/blueprints/invites.py +++ b/litecord/blueprints/invites.py @@ -21,7 +21,7 @@ async def create_invite(channel_id): user_id = await token_check() j = validate(await request.get_json(), INVITE) - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) # TODO: check CREATE_INSTANT_INVITE permission @@ -125,7 +125,7 @@ async def get_guild_invites(guild_id: int): @bp.route('/channels//invites', methods=['GET']) async def get_channel_invites(channel_id: int): user_id = await token_check() - guild_id = await channel_check(user_id, channel_id) + _ctype, guild_id = await channel_check(user_id, channel_id) inv_codes = await app.db.fetch(""" SELECT code