mirror of https://gitlab.com/litecord/litecord.git
add bulk ack implementation
This commit is contained in:
parent
87b1257e06
commit
6c2c6500a6
|
|
@ -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 quart import Blueprint, current_app as app, jsonify, request
|
||||||
from ..auth import token_check
|
from litecord.auth import token_check
|
||||||
from ..enums import ChannelType
|
from litecord.common.channels import channel_ack
|
||||||
from ..common.channels import channel_ack
|
|
||||||
from litecord.errors import GuildNotFound
|
from litecord.errors import GuildNotFound
|
||||||
from litecord.blueprints.checks import channel_check, guild_check
|
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__)
|
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"])
|
@bp.route("/channels/<int:channel_id>/messages/ack", methods=["DELETE"])
|
||||||
async def delete_read_state(channel_id):
|
async def delete_read_state(channel_id):
|
||||||
"""Delete the read state of a channel."""
|
"""Delete the read state of a channel."""
|
||||||
|
|
|
||||||
|
|
@ -619,3 +619,16 @@ BULK_DELETE = {
|
||||||
"schema": {"coerce": int},
|
"schema": {"coerce": int},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BULK_ACK = {
|
||||||
|
"read_states": {
|
||||||
|
"type": "list",
|
||||||
|
"required": True,
|
||||||
|
"minlength": 0,
|
||||||
|
"maxlength": 100,
|
||||||
|
"schema": {
|
||||||
|
"channel_id": {"coerce": int},
|
||||||
|
"message_id": {"coerce": int},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue