add message flags updating on suppress embeds

This commit is contained in:
Luna 2019-09-01 18:03:29 -03:00
parent 63ab8ea064
commit e0d253f36f
3 changed files with 47 additions and 1 deletions

View File

@ -25,7 +25,7 @@ from quart import Blueprint, request, current_app as app, jsonify
from logbook import Logger
from litecord.auth import token_check
from litecord.enums import ChannelType, GUILD_CHANS, MessageType
from litecord.enums import ChannelType, GUILD_CHANS, MessageType, MessageFlags
from litecord.errors import ChannelNotFound, Forbidden, BadRequest
from litecord.schemas import (
validate, CHAN_UPDATE, CHAN_OVERWRITE, SEARCH_CHANNEL, GROUP_DM_UPDATE,
@ -616,6 +616,40 @@ async def _search_channel(channel_id):
return jsonify(await search_result_from_list(rows))
# NOTE that those functions stay here until some other
# route or code wants it.
async def _msg_set_flags(message_id: int, new_flags: int):
flags = await app.db.fetchval("""
SELECT flags
FROM messages
WHERE id = $1
""", message_id)
flags |= new_flags
await app.db.execute("""
UPDATE messages
SET flags = $1
WHERE id = $1
""", flags.value, message_id)
async def _msg_unset_flags(message_id: int, unset_flags: int):
flags = await app.db.fetchval("""
SELECT flags
FROM messages
WHERE id = $1
""", message_id)
flags &= ~unset_flags
await app.db.execute("""
UPDATE messages
SET flags = $1
WHERE id = $1
""", flags.value, message_id)
@bp.route('/<int:channel_id>/messages/<int:message_id>/suppress-embeds',
methods=['POST'])
async def suppress_embeds(channel_id: int, message_id: int):
@ -656,9 +690,11 @@ async def suppress_embeds(channel_id: int, message_id: int):
if suppress and url_embeds:
# delete all embeds then dispatch an update
await _msg_set_flags(message_id, MessageFlags.suppress_embeds)
await msg_update_embeds(message, [], app.storage, app.dispatcher)
elif not suppress and not url_embeds:
# spawn process_url_embed to restore the embeds, if any
await _msg_unset_flags(message_id, MessageFlags.suppress_embeds)
app.sched.spawn(
process_url_embed(
app.config, app.storage, app.dispatcher, app.session,

View File

@ -164,6 +164,15 @@ class UserFlags(Flags):
premium_early = 512
class MessageFlags(Flags):
"""Message flags."""
none = 0
crossposted = 1 << 0
is_crosspost = 1 << 1
suppresss_embeds = 1 << 2
class StatusType(EasyEnum):
"""All statuses there can be in a presence."""
ONLINE = 'online'

View File

@ -30,6 +30,7 @@ async def find_user(username, discrim, ctx) -> int:
WHERE username = $1 AND discriminator = $2
""", username, discrim)
async def set_user_staff(user_id, ctx):
"""Give a single user staff status."""
old_flags = await ctx.db.fetchval("""