properly handle unlinking rooms, issue #47
This commit is contained in:
parent
327d8fad8c
commit
264dee0176
1 changed files with 15 additions and 14 deletions
|
@ -409,22 +409,23 @@ def cmd_admin_unlink(id):
|
|||
else:
|
||||
room = Rooms.query.filter(Rooms.pnut_chan == id).one_or_none()
|
||||
|
||||
if room.portal:
|
||||
alias = "#" + app.config['MATRIX_PNUT_PREFIX']
|
||||
alias += str(room.pnut_chan) + ":"
|
||||
alias += app.config['MATRIX_DOMAIN']
|
||||
matrix_api.remove_room_alias(alias)
|
||||
if hasattr(room, 'portal'):
|
||||
if room.portal:
|
||||
alias = "#" + app.config['MATRIX_PNUT_PREFIX']
|
||||
alias += str(room.pnut_chan) + ":"
|
||||
alias += app.config['MATRIX_DOMAIN']
|
||||
matrix_api.remove_room_alias(alias)
|
||||
|
||||
# Kicking users needs at least moderator privs
|
||||
members = matrix_api.get_room_members(room.room_id)
|
||||
reason = "Portal room has been unlinked by administrator"
|
||||
for m in members['chunk']:
|
||||
if m['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']:
|
||||
if room.portal:
|
||||
matrix_api.kick_user(room.room_id, m['sender'], reason=reason)
|
||||
else:
|
||||
if m['sender'].startswith("@" + app.config['MATRIX_PNUT_PREFIX']):
|
||||
# Kicking users needs at least moderator privs
|
||||
members = matrix_api.get_room_members(room.room_id)
|
||||
reason = "Portal room has been unlinked by administrator"
|
||||
for m in members['chunk']:
|
||||
if m['content']['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']:
|
||||
if room.portal:
|
||||
matrix_api.kick_user(room.room_id, m['sender'], reason=reason)
|
||||
else:
|
||||
if m['sender'].startswith("@" + app.config['MATRIX_PNUT_PREFIX']):
|
||||
matrix_api.kick_user(room.room_id, m['sender'], reason=reason)
|
||||
|
||||
try:
|
||||
channel, meta = pnutpy.api.unsubscribe_channel(room.pnut_chan)
|
||||
|
|
Loading…
Reference in a new issue