fix msg event permission check (#1315)

This commit is contained in:
Ajay Bura 2023-06-28 17:27:28 +05:30 committed by GitHub
parent b6283b3469
commit f14d70ea35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View file

@ -7,7 +7,7 @@ export const Base = style({
height: toRem(450),
backgroundColor: color.Surface.Container,
color: color.Surface.OnContainer,
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
border: `${config.borderWidth.B300} solid ${color.Surface.ContainerLine}`,
borderRadius: config.radii.R400,
boxShadow: config.shadow.E200,
overflow: 'hidden',

View file

@ -47,7 +47,7 @@ export function usePowerLevels(room: Room) {
const canSendEvent = useCallback(
(eventType: string | undefined, powerLevel: number) => {
const { events, events_default: eventsDefault } = powerLevels;
if (events && eventType && typeof events[eventType] === 'string') {
if (events && eventType && typeof events[eventType] === 'number') {
return powerLevel >= events[eventType];
}
return powerLevel >= (eventsDefault ?? DefaultPowerLevels.eventsDefault);

View file

@ -2,6 +2,7 @@ import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import './RoomView.scss';
import { Text, config } from 'folds';
import { EventType } from 'matrix-js-sdk';
import EventEmitter from 'events';
@ -32,7 +33,9 @@ function RoomView({ room, roomTimeline, eventId }) {
const tombstoneEvent = useStateEvent(room, StateEvent.RoomTombstone);
const { getPowerLevel, canSendEvent } = usePowerLevels(room);
const myUserId = mx.getUserId();
const canMessage = myUserId ? canSendEvent(undefined, getPowerLevel(myUserId)) : false;
const canMessage = myUserId
? canSendEvent(EventType.RoomMessage, getPowerLevel(myUserId))
: false;
useEffect(() => {
const settingsToggle = (isVisible) => {