mirror of https://github.com/vector-im/riot-web
Fix useRoomPowerLevels hook
parent
ee9e1a72cb
commit
1572a53af9
|
@ -24,6 +24,7 @@ import {RoomMember} from 'matrix-js-sdk/src/models/room-member';
|
||||||
import {User} from 'matrix-js-sdk/src/models/user';
|
import {User} from 'matrix-js-sdk/src/models/user';
|
||||||
import {Room} from 'matrix-js-sdk/src/models/room';
|
import {Room} from 'matrix-js-sdk/src/models/room';
|
||||||
import {EventTimeline} from 'matrix-js-sdk/src/models/event-timeline';
|
import {EventTimeline} from 'matrix-js-sdk/src/models/event-timeline';
|
||||||
|
import {MatrixEvent} from 'matrix-js-sdk/src/models/event';
|
||||||
|
|
||||||
import dis from '../../../dispatcher/dispatcher';
|
import dis from '../../../dispatcher/dispatcher';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
@ -496,11 +497,11 @@ const isMuted = (member: RoomMember, powerLevelContent: IPowerLevelsContent) =>
|
||||||
export const useRoomPowerLevels = (cli: MatrixClient, room: Room) => {
|
export const useRoomPowerLevels = (cli: MatrixClient, room: Room) => {
|
||||||
const [powerLevels, setPowerLevels] = useState<IPowerLevelsContent>({});
|
const [powerLevels, setPowerLevels] = useState<IPowerLevelsContent>({});
|
||||||
|
|
||||||
const update = useCallback(() => {
|
const update = useCallback((ev?: MatrixEvent) => {
|
||||||
if (!room) {
|
if (!room) return;
|
||||||
return;
|
if (ev && ev.getType() !== EventType.RoomPowerLevels) return;
|
||||||
}
|
|
||||||
const event = room.currentState.getStateEvents("m.room.power_levels", "");
|
const event = room.currentState.getStateEvents(EventType.RoomPowerLevels, "");
|
||||||
if (event) {
|
if (event) {
|
||||||
setPowerLevels(event.getContent());
|
setPowerLevels(event.getContent());
|
||||||
} else {
|
} else {
|
||||||
|
@ -511,7 +512,7 @@ export const useRoomPowerLevels = (cli: MatrixClient, room: Room) => {
|
||||||
};
|
};
|
||||||
}, [room]);
|
}, [room]);
|
||||||
|
|
||||||
useEventEmitter(cli, "RoomState.members", update);
|
useEventEmitter(cli, "RoomState.events", update);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
update();
|
update();
|
||||||
return () => {
|
return () => {
|
||||||
|
|
Loading…
Reference in New Issue