mirror of https://gitlab.com/litecord/litecord.git
users: add debug get mentions endpoint
This doesn't seem to work on the offical client, gives a crash. - schemas: add GET_MENTIONS
This commit is contained in:
parent
a0a1f24c1c
commit
011fc099bb
|
|
@ -5,7 +5,7 @@ from quart import Blueprint, jsonify, request, current_app as app
|
||||||
|
|
||||||
from ..auth import token_check
|
from ..auth import token_check
|
||||||
from ..errors import Forbidden, BadRequest
|
from ..errors import Forbidden, BadRequest
|
||||||
from ..schemas import validate, USER_UPDATE
|
from ..schemas import validate, USER_UPDATE, GET_MENTIONS
|
||||||
|
|
||||||
from .guilds import guild_check
|
from .guilds import guild_check
|
||||||
from .auth import check_password
|
from .auth import check_password
|
||||||
|
|
@ -370,3 +370,49 @@ async def get_profile(peer_id: int):
|
||||||
'premium_since': peer_premium,
|
'premium_since': peer_premium,
|
||||||
'mutual_guilds': mutual_res,
|
'mutual_guilds': mutual_res,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/mentions', methods=['GET'])
|
||||||
|
async def _get_mentions():
|
||||||
|
user_id = await token_check()
|
||||||
|
|
||||||
|
j = validate(dict(request.args), GET_MENTIONS)
|
||||||
|
|
||||||
|
print('args', j)
|
||||||
|
|
||||||
|
guild_query = 'AND guild_id = $2' if 'guild_id' in j else ''
|
||||||
|
role_query = "OR content LIKE '%<@&%'" if j['roles'] else ''
|
||||||
|
everyone_query = "OR content LIKE '%@everyone%'" if j['everyone'] else ''
|
||||||
|
mention_user = f'<@{user_id}>'
|
||||||
|
|
||||||
|
args = [mention_user]
|
||||||
|
|
||||||
|
if guild_query:
|
||||||
|
args.append(j['guild_id'])
|
||||||
|
|
||||||
|
rows = await app.db.fetch(f"""
|
||||||
|
SELECT id
|
||||||
|
FROM messages
|
||||||
|
WHERE (
|
||||||
|
content LIKE '%'||$1||'%'
|
||||||
|
{role_query}
|
||||||
|
{everyone_query}
|
||||||
|
{guild_query}
|
||||||
|
)
|
||||||
|
LIMIT {j["limit"]}
|
||||||
|
""", *args)
|
||||||
|
|
||||||
|
res = []
|
||||||
|
for row in rows:
|
||||||
|
message = await app.storage.get_message(row['id'])
|
||||||
|
chan = await app.storage.get_channel(int(message['channel_id']))
|
||||||
|
if not chan:
|
||||||
|
print('ignore wee woo')
|
||||||
|
continue
|
||||||
|
res.append(
|
||||||
|
message
|
||||||
|
)
|
||||||
|
|
||||||
|
print(res)
|
||||||
|
|
||||||
|
return jsonify(res)
|
||||||
|
|
|
||||||
|
|
@ -598,3 +598,11 @@ SEARCH_CHANNEL = {
|
||||||
'include_nsfw': {'coerce': bool, 'default': False},
|
'include_nsfw': {'coerce': bool, 'default': False},
|
||||||
'offset': {'coerce': int, 'default': 0}
|
'offset': {'coerce': int, 'default': 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GET_MENTIONS = {
|
||||||
|
'limit': {'coerce': int, 'default': 25},
|
||||||
|
'roles': {'coerce': bool, 'default': True},
|
||||||
|
'everyone': {'coerce': bool, 'default': True},
|
||||||
|
'guild_id': {'coerce': int, 'required': False}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue