Experimental "read only" room support
This commit is contained in:
parent
f34721c930
commit
76ca3f8e70
8 changed files with 169 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue