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:
parent
4d1ae4eafd
commit
f82cfead46
58 changed files with 1715 additions and 781 deletions
60
src/app/hooks/useRoomPermissions.ts
Normal file
60
src/app/hooks/useRoomPermissions.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { useMemo } from 'react';
|
||||
import {
|
||||
IPowerLevels,
|
||||
PowerLevelActions,
|
||||
PowerLevelNotificationsAction,
|
||||
readPowerLevel,
|
||||
} from './usePowerLevels';
|
||||
|
||||
export type RoomPermissionsAPI = {
|
||||
event: (type: string, userId: string) => boolean;
|
||||
stateEvent: (type: string, userId: string) => boolean;
|
||||
action: (action: PowerLevelActions, userId: string) => boolean;
|
||||
notificationAction: (action: PowerLevelNotificationsAction, userId: string) => boolean;
|
||||
};
|
||||
|
||||
export const getRoomPermissionsAPI = (
|
||||
creators: Set<string>,
|
||||
powerLevels: IPowerLevels
|
||||
): RoomPermissionsAPI => {
|
||||
const api: RoomPermissionsAPI = {
|
||||
event: (type, userId) => {
|
||||
if (creators.has(userId)) return true;
|
||||
const userPower = readPowerLevel.user(powerLevels, userId);
|
||||
const requiredPL = readPowerLevel.event(powerLevels, type);
|
||||
return userPower >= requiredPL;
|
||||
},
|
||||
stateEvent: (type, userId) => {
|
||||
if (creators.has(userId)) return true;
|
||||
const userPower = readPowerLevel.user(powerLevels, userId);
|
||||
const requiredPL = readPowerLevel.state(powerLevels, type);
|
||||
return userPower >= requiredPL;
|
||||
},
|
||||
action: (action, userId) => {
|
||||
if (creators.has(userId)) return true;
|
||||
const userPower = readPowerLevel.user(powerLevels, userId);
|
||||
const requiredPL = readPowerLevel.action(powerLevels, action);
|
||||
return userPower >= requiredPL;
|
||||
},
|
||||
notificationAction: (action, userId) => {
|
||||
if (creators.has(userId)) return true;
|
||||
const userPower = readPowerLevel.user(powerLevels, userId);
|
||||
const requiredPL = readPowerLevel.notification(powerLevels, action);
|
||||
return userPower >= requiredPL;
|
||||
},
|
||||
};
|
||||
|
||||
return api;
|
||||
};
|
||||
|
||||
export const useRoomPermissions = (
|
||||
creators: Set<string>,
|
||||
powerLevels: IPowerLevels
|
||||
): RoomPermissionsAPI => {
|
||||
const api: RoomPermissionsAPI = useMemo(
|
||||
() => getRoomPermissionsAPI(creators, powerLevels),
|
||||
[creators, powerLevels]
|
||||
);
|
||||
|
||||
return api;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue