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:
|
else:
|
||||||
room = Rooms.query.filter(Rooms.pnut_chan == id).one_or_none()
|
room = Rooms.query.filter(Rooms.pnut_chan == id).one_or_none()
|
||||||
|
|
||||||
if room.portal:
|
if hasattr(room, 'portal'):
|
||||||
alias = "#" + app.config['MATRIX_PNUT_PREFIX']
|
if room.portal:
|
||||||
alias += str(room.pnut_chan) + ":"
|
alias = "#" + app.config['MATRIX_PNUT_PREFIX']
|
||||||
alias += app.config['MATRIX_DOMAIN']
|
alias += str(room.pnut_chan) + ":"
|
||||||
matrix_api.remove_room_alias(alias)
|
alias += app.config['MATRIX_DOMAIN']
|
||||||
|
matrix_api.remove_room_alias(alias)
|
||||||
|
|
||||||
# Kicking users needs at least moderator privs
|
# Kicking users needs at least moderator privs
|
||||||
members = matrix_api.get_room_members(room.room_id)
|
members = matrix_api.get_room_members(room.room_id)
|
||||||
reason = "Portal room has been unlinked by administrator"
|
reason = "Portal room has been unlinked by administrator"
|
||||||
for m in members['chunk']:
|
for m in members['chunk']:
|
||||||
if m['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']:
|
if m['content']['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']:
|
||||||
if room.portal:
|
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)
|
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:
|
try:
|
||||||
channel, meta = pnutpy.api.unsubscribe_channel(room.pnut_chan)
|
channel, meta = pnutpy.api.unsubscribe_channel(room.pnut_chan)
|
||||||
|
|
Loading…
Reference in a new issue