add bulk ack implementation

This commit is contained in:
Luna 2021-07-10 23:41:59 -03:00
parent 87b1257e06
commit 6c2c6500a6
2 changed files with 35 additions and 4 deletions

View File

@ -18,12 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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/<int:channel_id>/messages/ack", methods=["DELETE"])
async def delete_read_state(channel_id):
"""Delete the read state of a channel."""

View File

@ -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},
},
}
}