mirror of https://gitlab.com/litecord/litecord.git
make update_channel more flexible against non-guild chans
..to handle gdm edits
This commit is contained in:
parent
7a9453a129
commit
85a5cfc57a
|
|
@ -411,25 +411,39 @@ async def update_channel(channel_id):
|
|||
user_id = await token_check()
|
||||
ctype, guild_id = await channel_check(user_id, channel_id)
|
||||
|
||||
if ctype not in GUILD_CHANS:
|
||||
raise ChannelNotFound('Can not edit non-guild channels.')
|
||||
if ctype not in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE,
|
||||
ChannelType.GROUP_DM):
|
||||
raise ChannelNotFound('unable to edit unsupported chan type')
|
||||
|
||||
is_guild = ctype in GUILD_CHANS
|
||||
|
||||
if is_guild:
|
||||
await channel_perm_check(user_id, channel_id, 'manage_channels')
|
||||
j = validate(await request.get_json(), CHAN_UPDATE)
|
||||
|
||||
# TODO: categories?
|
||||
j = validate(await request.get_json(),
|
||||
CHAN_UPDATE if is_guild else GROUP_DM_UPDATE)
|
||||
|
||||
# TODO: categories
|
||||
update_handler = {
|
||||
ChannelType.GUILD_TEXT: _update_text_channel,
|
||||
ChannelType.GUILD_VOICE: _update_voice_channel,
|
||||
# ChannelType.GROUP_DM: _update_group_dm,
|
||||
}[ctype]
|
||||
|
||||
if is_guild:
|
||||
await _update_channel_common(channel_id, guild_id, j)
|
||||
|
||||
await update_handler(channel_id, j)
|
||||
|
||||
chan = await app.storage.get_channel(channel_id)
|
||||
|
||||
if is_guild:
|
||||
await app.dispatcher.dispatch(
|
||||
'guild', guild_id, 'CHANNEL_UPDATE', chan)
|
||||
else:
|
||||
await app.dispatcher.dispatch(
|
||||
'channel', channel_id, 'CHANNEL_UPDATE', chan)
|
||||
|
||||
await app.dispatcher.dispatch('guild', guild_id, 'CHANNEL_UPDATE', chan)
|
||||
return jsonify(chan)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue