Support room version 12 (#2399)
* WIP - support room version 12 * add room creators hook * revert changes from powerlevels * improve use room creators hook * add hook to get dm users * add options to add creators in create room/space * add member item component in member drawer * remove unused import * extract member drawer header component * get room creators as set only if room version support them * add room permissions hook * support room v12 creators power * make predecessor event id optional * add info about founders in permissions * allow to create infinite powers to room creators * allow everyone with permission to create infinite power * handle additional creators in room upgrade * add option to follow space tombstone
This commit is contained in:
49
src/app/hooks/useRoomCreators.ts
Normal file
49
src/app/hooks/useRoomCreators.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { MatrixClient, MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { IRoomCreateContent, StateEvent } from '../../types/matrix/room';
|
||||
import { creatorsSupported } from '../utils/matrix';
|
||||
import { getStateEvent } from '../utils/room';
|
||||
|
||||
export const getRoomCreators = (createEvent: MatrixEvent): Set<string> => {
|
||||
const createContent = createEvent.getContent<IRoomCreateContent>();
|
||||
|
||||
const creators: Set<string> = new Set();
|
||||
|
||||
if (!creatorsSupported(createContent.room_version)) return creators;
|
||||
|
||||
if (createEvent.event.sender) {
|
||||
creators.add(createEvent.event.sender);
|
||||
}
|
||||
|
||||
if ('additional_creators' in createContent && Array.isArray(createContent.additional_creators)) {
|
||||
createContent.additional_creators.forEach((creator) => {
|
||||
if (typeof creator === 'string') {
|
||||
creators.add(creator);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return creators;
|
||||
};
|
||||
|
||||
export const useRoomCreators = (room: Room): Set<string> => {
|
||||
const createEvent = useStateEvent(room, StateEvent.RoomCreate);
|
||||
|
||||
const creators = useMemo(
|
||||
() => (createEvent ? getRoomCreators(createEvent) : new Set<string>()),
|
||||
[createEvent]
|
||||
);
|
||||
|
||||
return creators;
|
||||
};
|
||||
|
||||
export const getRoomCreatorsForRoomId = (mx: MatrixClient, roomId: string): Set<string> => {
|
||||
const room = mx.getRoom(roomId);
|
||||
if (!room) return new Set();
|
||||
|
||||
const createEvent = getStateEvent(room, StateEvent.RoomCreate);
|
||||
if (!createEvent) return new Set();
|
||||
|
||||
return getRoomCreators(createEvent);
|
||||
};
|
||||
Reference in New Issue
Block a user