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