Use EventType at the state and account data call sites. [skip build]
This commit is contained in:
@@ -3,7 +3,7 @@ import React, { FormEventHandler, useCallback, useMemo, useState } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import Linkify from 'linkify-react';
|
||||
import classNames from 'classnames';
|
||||
import { JoinRule, MatrixError } from 'matrix-js-sdk';
|
||||
import { EventType, JoinRule, MatrixError } from 'matrix-js-sdk';
|
||||
import { Icon, Icons } from '../../../components/icons';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../../room-settings/styles.css';
|
||||
@@ -82,15 +82,16 @@ export function RoomProfileEdit({
|
||||
useCallback(
|
||||
async (roomAvatarMxc?: string | null, roomName?: string, roomTopic?: string) => {
|
||||
if (roomAvatarMxc !== undefined) {
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomAvatar as any, {
|
||||
url: roomAvatarMxc,
|
||||
// url can be null to clear the avatar, which RoomAvatarEventContent does not allow
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomAvatar, {
|
||||
url: roomAvatarMxc as any,
|
||||
});
|
||||
}
|
||||
if (roomName !== undefined) {
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomName as any, { name: roomName });
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomName, { name: roomName });
|
||||
}
|
||||
if (roomTopic !== undefined) {
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomTopic as any, { topic: roomTopic });
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomTopic, { topic: roomTopic });
|
||||
}
|
||||
},
|
||||
[mx, room.roomId],
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { EventType } from 'matrix-js-sdk';
|
||||
import { Icon, Icons } from '../../components/icons';
|
||||
import { useAllJoinedRoomsSet, useGetRoom } from '../../hooks/useGetRoom';
|
||||
import { SpaceProvider } from '../../hooks/useSpace';
|
||||
@@ -111,8 +112,7 @@ function CreateRoomModal({ state }: CreateRoomModalProps) {
|
||||
// Add as m.space.child to the space
|
||||
await mx.sendStateEvent(
|
||||
parentSpaceId,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
StateEvent.SpaceChild as any,
|
||||
EventType.SpaceChild,
|
||||
{ via: spaceViaServers },
|
||||
newRoomId,
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Box, Chip, IconButton, Line, Scroll, Spinner, Text, config } from 'fold
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { JoinRule, RestrictedAllowType, Room } from 'matrix-js-sdk';
|
||||
import { EventType, JoinRule, RestrictedAllowType, Room } from 'matrix-js-sdk';
|
||||
import { RoomJoinRulesEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { IHierarchyRoom } from 'matrix-js-sdk/lib/@types/spaces';
|
||||
import { produce } from 'immer';
|
||||
@@ -305,7 +305,7 @@ function SpaceCardLobby() {
|
||||
if (!reorder.item.parentId) return;
|
||||
await mx.sendStateEvent(
|
||||
reorder.item.parentId,
|
||||
StateEvent.SpaceChild as any,
|
||||
EventType.SpaceChild,
|
||||
{ ...reorder.item.content, order: reorder.orderKey },
|
||||
reorder.item.roomId,
|
||||
);
|
||||
@@ -330,7 +330,7 @@ function SpaceCardLobby() {
|
||||
|
||||
// remove from current space
|
||||
if (item.parentId !== containerParentId) {
|
||||
mx.sendStateEvent(item.parentId, StateEvent.SpaceChild as any, {}, item.roomId);
|
||||
mx.sendStateEvent(item.parentId, EventType.SpaceChild, {}, item.roomId);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -350,7 +350,7 @@ function SpaceCardLobby() {
|
||||
joinRuleContent.allow?.filter((allowRule) => allowRule.room_id !== item.parentId) ??
|
||||
[];
|
||||
allow.push({ type: RestrictedAllowType.RoomMembership, room_id: containerParentId });
|
||||
mx.sendStateEvent(itemRoom.roomId, StateEvent.RoomJoinRules as any, {
|
||||
mx.sendStateEvent(itemRoom.roomId, EventType.RoomJoinRules, {
|
||||
...joinRuleContent,
|
||||
allow,
|
||||
});
|
||||
@@ -392,7 +392,7 @@ function SpaceCardLobby() {
|
||||
await rateLimitedActions(reorders, async (reorder) => {
|
||||
await mx.sendStateEvent(
|
||||
containerParentId,
|
||||
StateEvent.SpaceChild as any,
|
||||
EventType.SpaceChild,
|
||||
{ ...reorder.item.content, order: reorder.orderKey },
|
||||
reorder.item.roomId,
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ import React, {
|
||||
} from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useHover, useFocusWithin } from 'react-aria';
|
||||
import { MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { EventType, MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
|
||||
import classNames from 'classnames';
|
||||
import { RoomPinnedEventsEventContent } from 'matrix-js-sdk/lib/types';
|
||||
@@ -77,7 +77,7 @@ import { getViaServers } from '../../../plugins/via-servers';
|
||||
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
||||
import { PluginButtonSlot } from '../../../features/settings/plugins/PluginButtonSlot';
|
||||
import { useRoomPinnedEvents } from '../../../hooks/useRoomPinnedEvents';
|
||||
import { MemberPowerTag, StateEvent } from '../../../../types/matrix/room';
|
||||
import { MemberPowerTag } from '../../../../types/matrix/room';
|
||||
import { PowerIcon } from '../../../components/power';
|
||||
import colorMXID from '../../../../util/colorMXID';
|
||||
import { getPowerTagIconSrc } from '../../../hooks/useMemberPowerTag';
|
||||
@@ -418,7 +418,7 @@ export const MessagePinItem = as<
|
||||
if (!isPinned && eventId) {
|
||||
pinContent.pinned.push(eventId);
|
||||
}
|
||||
mx.sendStateEvent(room.roomId, StateEvent.RoomPinnedEvents as any, pinContent);
|
||||
mx.sendStateEvent(room.roomId, EventType.RoomPinnedEvents, pinContent);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
Direction,
|
||||
EventTimeline,
|
||||
EventType,
|
||||
IContextResponse,
|
||||
MatrixClient,
|
||||
Method,
|
||||
@@ -9,7 +10,7 @@ import {
|
||||
RoomMember,
|
||||
Visibility,
|
||||
} from 'matrix-js-sdk';
|
||||
import { RoomServerAclEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { RoomMemberEventContent, RoomServerAclEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { useMemo } from 'react';
|
||||
import {
|
||||
addRoomIdToMDirect,
|
||||
@@ -363,11 +364,11 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomMember, mx.getSafeUserId());
|
||||
const content = mEvent?.getContent();
|
||||
const content = mEvent?.getContent<RoomMemberEventContent>();
|
||||
if (!content) return;
|
||||
await mx.sendStateEvent(
|
||||
room.roomId,
|
||||
StateEvent.RoomMember as any,
|
||||
EventType.RoomMember,
|
||||
{
|
||||
...content,
|
||||
displayname: nick,
|
||||
@@ -385,11 +386,11 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.getStateEvents(StateEvent.RoomMember, mx.getSafeUserId());
|
||||
const content = mEvent?.getContent();
|
||||
const content = mEvent?.getContent<RoomMemberEventContent>();
|
||||
if (!content) return;
|
||||
await mx.sendStateEvent(
|
||||
room.roomId,
|
||||
StateEvent.RoomMember as any,
|
||||
EventType.RoomMember,
|
||||
{
|
||||
...content,
|
||||
avatar_url: payload,
|
||||
@@ -529,7 +530,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
|
||||
aclContent.allow?.sort();
|
||||
aclContent.deny?.sort();
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomServerAcl as any, aclContent);
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomServerAcl, aclContent);
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { MatrixError, Room } from 'matrix-js-sdk';
|
||||
import { EventType, MatrixError, Room } from 'matrix-js-sdk';
|
||||
import { RoomCanonicalAliasEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { AsyncState, useAsyncCallback } from './useAsyncCallback';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
@@ -56,7 +56,7 @@ export const useSetMainAlias = (room: Room): ((alias: string | undefined) => Pro
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
@@ -90,7 +90,7 @@ export const usePublishUnpublishAliases = (
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
@@ -114,7 +114,7 @@ export const usePublishUnpublishAliases = (
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await mx.sendStateEvent(room.roomId, EventType.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from 'browser-encrypt-attachment';
|
||||
import {
|
||||
EventTimeline,
|
||||
EventType,
|
||||
MatrixClient,
|
||||
MatrixError,
|
||||
MatrixEvent,
|
||||
@@ -15,7 +16,6 @@ import {
|
||||
} from 'matrix-js-sdk';
|
||||
import to from 'await-to-js';
|
||||
import { IImageInfo, IThumbnailContent, IVideoInfo } from '../../types/matrix/common';
|
||||
import { AccountDataEvent } from '../../types/matrix/accountData';
|
||||
import { getStateEvent } from './room';
|
||||
import { Membership, StateEvent } from '../../types/matrix/room';
|
||||
|
||||
@@ -230,7 +230,7 @@ export const addRoomIdToMDirect = async (
|
||||
roomId: string,
|
||||
userId: string,
|
||||
): Promise<void> => {
|
||||
const mDirectsEvent = mx.getAccountData(AccountDataEvent.Direct as any);
|
||||
const mDirectsEvent = mx.getAccountData(EventType.Direct);
|
||||
let userIdToRoomIds: Record<string, string[]> = {};
|
||||
|
||||
if (typeof mDirectsEvent !== 'undefined')
|
||||
@@ -255,11 +255,11 @@ export const addRoomIdToMDirect = async (
|
||||
}
|
||||
userIdToRoomIds[userId] = roomIds;
|
||||
|
||||
await mx.setAccountData(AccountDataEvent.Direct as any, userIdToRoomIds as any);
|
||||
await mx.setAccountData(EventType.Direct, userIdToRoomIds);
|
||||
};
|
||||
|
||||
export const removeRoomIdFromMDirect = async (mx: MatrixClient, roomId: string): Promise<void> => {
|
||||
const mDirectsEvent = mx.getAccountData(AccountDataEvent.Direct as any);
|
||||
const mDirectsEvent = mx.getAccountData(EventType.Direct);
|
||||
let userIdToRoomIds: Record<string, string[]> = {};
|
||||
|
||||
if (typeof mDirectsEvent !== 'undefined')
|
||||
@@ -273,7 +273,7 @@ export const removeRoomIdFromMDirect = async (mx: MatrixClient, roomId: string):
|
||||
}
|
||||
});
|
||||
|
||||
await mx.setAccountData(AccountDataEvent.Direct as any, userIdToRoomIds as any);
|
||||
await mx.setAccountData(EventType.Direct, userIdToRoomIds);
|
||||
};
|
||||
|
||||
export const mxcUrlToHttp = (
|
||||
|
||||
Reference in New Issue
Block a user