From 6c2c6500a61f71d9acd563a4f2e190c492ae26b7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 10 Jul 2021 23:41:59 -0300 Subject: [PATCH] add bulk ack implementation --- litecord/blueprints/read_states.py | 26 ++++++++++++++++++++++---- litecord/schemas.py | 13 +++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/litecord/blueprints/read_states.py b/litecord/blueprints/read_states.py index 5df255a..5c216e7 100644 --- a/litecord/blueprints/read_states.py +++ b/litecord/blueprints/read_states.py @@ -18,12 +18,13 @@ along with this program. If not, see . """ -from quart import Blueprint, current_app as app, jsonify -from ..auth import token_check -from ..enums import ChannelType -from ..common.channels import channel_ack +from quart import Blueprint, current_app as app, jsonify, request +from litecord.auth import token_check +from litecord.common.channels import channel_ack from litecord.errors import GuildNotFound from litecord.blueprints.checks import channel_check, guild_check +from litecord.schemas import validate, BULK_ACK +from litecord.enums import ChannelType, GUILD_CHANS bp = Blueprint("read_states", __name__) @@ -50,6 +51,23 @@ async def ack_channel(channel_id, message_id): ) +@bp.route("/read-states/ack-bulk", methods=["POST"]) +async def bulk_ack(): + """Acknowledge multiple channels in a row""" + user_id = await token_check() + j = validate(await request.get_json(), BULK_ACK) + for ack_request in j: + channel_id, message_id = ack_request["channel_id"], ack_request["message_id"] + ctype, guild_id = await channel_check(user_id, channel_id) + if ctype not in GUILD_CHANS: + guild_id = None + + await channel_ack(user_id, channel_id, guild_id, message_id) + + # TODO: validate if this is the correct response + return "", 204 + + @bp.route("/channels//messages/ack", methods=["DELETE"]) async def delete_read_state(channel_id): """Delete the read state of a channel.""" diff --git a/litecord/schemas.py b/litecord/schemas.py index 3ba1f4c..0f28a0a 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -619,3 +619,16 @@ BULK_DELETE = { "schema": {"coerce": int}, } } + +BULK_ACK = { + "read_states": { + "type": "list", + "required": True, + "minlength": 0, + "maxlength": 100, + "schema": { + "channel_id": {"coerce": int}, + "message_id": {"coerce": int}, + }, + } +}