mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 22:40:29 +03:00
get room creators as set only if room version support them
This commit is contained in:
parent
d13d9a991b
commit
88e8f73f53
1 changed files with 10 additions and 4 deletions
|
|
@ -2,12 +2,15 @@ import { 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';
|
||||
|
||||
export const getRoomCreators = (createEvent: MatrixEvent): string[] => {
|
||||
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);
|
||||
}
|
||||
|
|
@ -20,13 +23,16 @@ export const getRoomCreators = (createEvent: MatrixEvent): string[] => {
|
|||
});
|
||||
}
|
||||
|
||||
return Array.from(creators);
|
||||
return creators;
|
||||
};
|
||||
|
||||
export const useRoomCreators = (room: Room): string[] => {
|
||||
export const useRoomCreators = (room: Room): Set<string> => {
|
||||
const createEvent = useStateEvent(room, StateEvent.RoomCreate);
|
||||
|
||||
const creators = useMemo(() => (createEvent ? getRoomCreators(createEvent) : []), [createEvent]);
|
||||
const creators = useMemo(
|
||||
() => (createEvent ? getRoomCreators(createEvent) : new Set<string>()),
|
||||
[createEvent]
|
||||
);
|
||||
|
||||
return creators;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue