make update_channel more flexible against non-guild chans

..to handle gdm edits
This commit is contained in:
Luna 2019-02-16 22:59:20 -03:00
parent 7a9453a129
commit 85a5cfc57a
1 changed files with 21 additions and 7 deletions

View File

@ -411,25 +411,39 @@ async def update_channel(channel_id):
user_id = await token_check() user_id = await token_check()
ctype, guild_id = await channel_check(user_id, channel_id) ctype, guild_id = await channel_check(user_id, channel_id)
if ctype not in GUILD_CHANS: if ctype not in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE,
raise ChannelNotFound('Can not edit non-guild channels.') 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') 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 = { update_handler = {
ChannelType.GUILD_TEXT: _update_text_channel, ChannelType.GUILD_TEXT: _update_text_channel,
ChannelType.GUILD_VOICE: _update_voice_channel, ChannelType.GUILD_VOICE: _update_voice_channel,
# ChannelType.GROUP_DM: _update_group_dm,
}[ctype] }[ctype]
if is_guild:
await _update_channel_common(channel_id, guild_id, j) await _update_channel_common(channel_id, guild_id, j)
await update_handler(channel_id, j) await update_handler(channel_id, j)
chan = await app.storage.get_channel(channel_id) 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) return jsonify(chan)