mirror of https://gitlab.com/litecord/litecord.git
blueprints.channels: call try_dm_state on dm pre dispatch
This commit is contained in:
parent
8e3b5d79ab
commit
692f9ef245
|
|
@ -10,6 +10,7 @@ from ..errors import Forbidden, ChannelNotFound, MessageNotFound
|
||||||
from ..schemas import validate, MESSAGE_CREATE
|
from ..schemas import validate, MESSAGE_CREATE
|
||||||
|
|
||||||
from .checks import channel_check, guild_check
|
from .checks import channel_check, guild_check
|
||||||
|
from .users import try_dm_state
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
bp = Blueprint('channels', __name__)
|
bp = Blueprint('channels', __name__)
|
||||||
|
|
@ -258,7 +259,7 @@ async def get_single_message(channel_id, message_id):
|
||||||
|
|
||||||
|
|
||||||
async def _dm_pre_dispatch(channel_id, peer_id):
|
async def _dm_pre_dispatch(channel_id, peer_id):
|
||||||
"""Doo some checks pre-MESSAGE_CREATE so we
|
"""Do some checks pre-MESSAGE_CREATE so we
|
||||||
make sure the receiving party will handle everything."""
|
make sure the receiving party will handle everything."""
|
||||||
|
|
||||||
# check the other party's dm_channel_state
|
# check the other party's dm_channel_state
|
||||||
|
|
@ -285,10 +286,7 @@ async def _dm_pre_dispatch(channel_id, peer_id):
|
||||||
|
|
||||||
# insert it on dm_channel_state so the client
|
# insert it on dm_channel_state so the client
|
||||||
# is subscribed on the future
|
# is subscribed on the future
|
||||||
await app.db.execute("""
|
await try_dm_state(peer_id, channel_id)
|
||||||
INSERT INTO dm_channel_state(user_id, dm_id)
|
|
||||||
VALUES ($1, $2)
|
|
||||||
""", peer_id, channel_id)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<int:channel_id>/messages', methods=['POST'])
|
@bp.route('/<int:channel_id>/messages', methods=['POST'])
|
||||||
|
|
|
||||||
|
|
@ -289,6 +289,8 @@ async def try_dm_state(user_id, dm_id):
|
||||||
|
|
||||||
|
|
||||||
async def create_dm(user_id, recipient_id):
|
async def create_dm(user_id, recipient_id):
|
||||||
|
"""Create a new dm with a user,
|
||||||
|
or get the existing DM id if it already exists."""
|
||||||
dm_id = get_snowflake()
|
dm_id = get_snowflake()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -302,6 +304,12 @@ async def create_dm(user_id, recipient_id):
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
""", dm_id, user_id, recipient_id)
|
""", dm_id, user_id, recipient_id)
|
||||||
|
|
||||||
|
# the dm state is something we use
|
||||||
|
# to give the currently "open dms"
|
||||||
|
# on the client.
|
||||||
|
|
||||||
|
# we don't open a dm for the peer/recipient
|
||||||
|
# until the user sends a message.
|
||||||
await try_dm_state(user_id, dm_id)
|
await try_dm_state(user_id, dm_id)
|
||||||
|
|
||||||
except UniqueViolationError:
|
except UniqueViolationError:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue