listen for RoomState.members instead of RoomState.events

as the powerlevel on the member is not yet updated at the time
RoomState.events is emitted.

Also listen on the client for this event as the currentState
object can change when the timeline is reset.
This commit is contained in:
Bruno Windels 2019-11-15 12:10:56 +01:00
parent 6db162a3a7
commit bd853b3102

View File

@ -365,10 +365,13 @@ const _isMuted = (member, powerLevelContent) => {
return member.powerLevel < levelToSend;
};
const useRoomPowerLevels = (room) => {
const useRoomPowerLevels = (cli, room) => {
const [powerLevels, setPowerLevels] = useState({});
const update = useCallback(() => {
if (!room) {
return;
}
const event = room.currentState.getStateEvents("m.room.power_levels", "");
if (event) {
setPowerLevels(event.getContent());
@ -380,7 +383,7 @@ const useRoomPowerLevels = (room) => {
};
}, [room]);
useEventEmitter(room.currentState, "RoomState.events", update);
useEventEmitter(cli, "RoomState.members", update);
useEffect(() => {
update();
return () => {
@ -819,7 +822,7 @@ function useRoomPermissions(cli, room, user) {
modifyLevelMax,
});
}, [cli, user, room]);
useEventEmitter(cli, "RoomState.events", updateRoomPermissions);
useEventEmitter(cli, "RoomState.members", updateRoomPermissions);
useEffect(() => {
updateRoomPermissions();
return () => {