Experimental "read only" room support

This commit is contained in:
N-Pex 2023-03-16 15:23:26 +01:00 committed by n8fr8
parent f34721c930
commit 76ca3f8e70
8 changed files with 169 additions and 17 deletions

View file

@ -37,6 +37,7 @@ export default {
userDisplayName: null,
userAvatar: null,
currentRoom: null,
currentRoomIsReadOnlyForUser: false,
currentRoomBeingPurged: false,
notificationCount: 0,
};
@ -93,6 +94,7 @@ export default {
immediate: true,
handler(roomId) {
this.currentRoom = this.getRoom(roomId);
this.currentRoomIsReadOnlyForUser = this.isReadOnlyRoomForUser(roomId, this.currentUserId);
},
},
},
@ -355,6 +357,14 @@ export default {
}
}
break;
case "m.room.power_levels":
{
if (this.currentRoom && event.getRoomId() == this.currentRoom.roomId) {
this.currentRoomIsReadOnlyForUser = this.isReadOnlyRoomForUser(event.getRoomId(), this.currentUserId);
}
}
break;
}
this.updateNotificationCount();
},
@ -550,6 +560,47 @@ export default {
}
},
isReadOnlyRoom(roomId) {
if (this.matrixClient && roomId) {
const room = this.getRoom(roomId);
if (room && room.currentState) {
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
if (powerLevelEvent) {
return powerLevelEvent.getContent().events_default > 0
}
}
}
return false;
},
isReadOnlyRoomForUser(roomId, userId) {
if (this.matrixClient && roomId && userId) {
const room = this.getRoom(roomId);
if (room && room.currentState) {
return !room.currentState.maySendMessage(userId)
}
}
return false;
},
setReadOnlyRoom(roomId, readOnly) {
if (this.matrixClient && roomId) {
const room = this.getRoom(roomId);
if (room && room.currentState) {
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
if (powerLevelEvent) {
let content = powerLevelEvent.getContent();
content.events_default = readOnly ? 50 : 0;
this.matrixClient.sendStateEvent(
room.roomId,
"m.room.power_levels",
content
);
}
}
}
},
/**
* Purge the room with the given id! This means:
* - Make room invite only