Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/components/create-room/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const createSpacePowerLevelsOverride = () => ({
});

export const createRoomEncryptionState = () => ({
type: 'm.room.encryption',
type: EventType.RoomEncryption,
state_key: '',
content: {
algorithm: 'm.megolm.v1.aes-sha2',
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/event-history/EventHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { usePowerLevelsContext } from '$hooks/usePowerLevels';

import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
import * as css from './EventHistory.css';
import { EventType } from '$types/matrix-sdk';
import { EventType, RelationType } from '$types/matrix-sdk';

type EventHistoryProps = {
room: Room;
Expand Down Expand Up @@ -104,7 +104,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
const formattedBody =
content?.['m.new_content']?.formatted_body ?? content?.formatted_body ?? '';
const { 'm.relates_to': relation } = startThread
? { 'm.relates_to': { rel_type: 'm.thread', event_id: replyId } }
? { 'm.relates_to': { rel_type: RelationType.Thread, event_id: replyId } }
: replyEvt.getWireContent();
const senderId = replyEvt.getSender();
if (senderId) {
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/message/PollEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'matrix-js-sdk';
import * as css from './PollEvent.css';
import { useCallback, useEffect, useState } from 'react';
import { MsgType, RelationType } from '$types/matrix-sdk';
import { PollResponsesViewer } from '$features/room/poll-modals';
import { ModalOverlay } from '$components/modal-overlay/ModalOverlay';
import { useMatrixEvent } from '$hooks/useMatrixEvent';
Expand Down Expand Up @@ -188,7 +189,7 @@ export function PollEvent({ content, mEvent, mx, room }: PollEventProps) {

let newContent: PollResponse = {
'm.relates_to': {
rel_type: 'm.reference',
rel_type: RelationType.Reference,
event_id: eventId,
},
[M_POLL_RESPONSE.name]: {
Expand Down Expand Up @@ -220,13 +221,13 @@ export function PollEvent({ content, mEvent, mx, room }: PollEventProps) {

const endContent = {
'm.relates_to': {
rel_type: 'm.reference',
rel_type: RelationType.Reference,
event_id: eventId,
},
'org.matrix.msc3381.poll.end': {},
[M_TEXT.name]: endText,
body: endText,
msgtype: 'm.text',
msgtype: MsgType.Text,
};
mx.sendEvent(
roomId,
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/message/modals/MessageForward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MenuItem, Text, as } from 'folds';
import { ArrowRight, menuIcon } from '$components/icons/phosphor';
import { useSetAtom } from 'jotai';
import type { MatrixEvent, Room } from '$types/matrix-sdk';
import { MsgType } from '$types/matrix-sdk';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
import { useMessageTargetRooms } from '$hooks/useMessageTargetRooms';
Expand Down Expand Up @@ -129,7 +130,7 @@ export function MessageForwardInternal({

const eventType = mEvent.getType() as SendEventType;
const originalContent = mEvent.getContent();
const isTextMessage = originalContent.msgtype === 'm.text';
const isTextMessage = originalContent.msgtype === MsgType.Text;

const originalBody = typeof originalContent.body === 'string' ? originalContent.body : '';
const originalFormattedBody =
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/message/modals/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function OptionMenu({
const store = useStore();
const mx = useMatrixClient();
const isThreadedMessage = isThreadRelationEvent(mEvent, mEvent.threadRootId);
const isStickerMessage = mEvent.getType() === 'm.stidoecker';
const isStickerMessage = mEvent.getType() === (EventType.Sticker as string);
const evtId = mEvent.getId()!;
const evtTimeline = room.getTimelineForEvent(evtId);
const edits =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ export function DeveloperTools({ requestBack, requestClose }: DeveloperToolsProp
const latestTimelineEventId = latestTimelineEvent?.getId() ?? null;
const latestMessageEvent = [...liveEvents].toReversed().find((event) => {
const type = event.getType();
return type === 'm.room.message' || type === 'm.room.encrypted' || type === 'm.sticker';
return (
type === (EventType.RoomMessage as string) ||
type === (EventType.RoomMessageEncrypted as string) ||
type === (EventType.Sticker as string)
);
});
const latestMessageEventId = latestMessageEvent?.getId() ?? null;
const latestNotificationEvent = [...liveEvents]
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/room/RoomTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ export function RoomTimeline({
.find(
(e) =>
e.mEvent.getSender() === myUserId &&
e.mEvent.getType() === 'm.room.message' &&
e.mEvent.getType() === (EventType.RoomMessage as string) &&
!e.mEvent.isRedacted()
);
if (found?.mEvent.getId()) actions.handleEdit(found.mEvent.getId());
Expand Down
3 changes: 2 additions & 1 deletion src/app/features/room/location-modal/LocationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { LatLngLiteral } from 'leaflet';
import L from 'leaflet';
import { getReplyContent } from '../RoomInput';
import type { RoomMessageEventContent } from '$types/matrix-sdk';
import { MsgType } from '$types/matrix-sdk';
import { settingsAtom } from '$state/settings';
import { useSetting } from '$state/hooks/settings';
import classNames from 'classnames';
Expand Down Expand Up @@ -238,7 +239,7 @@ export function LocationDialog({
const mlat = pinPosition.lat.toFixed(6);
const mlon = pinPosition.lng.toFixed(6);
const content: IContent = {
msgtype: 'm.location',
msgtype: MsgType.Location,
geo_uri: `geo:${mlat},${mlon};u=0`,
body: `https://www.openstreetmap.org/?mlat=${mlat}&mlon=${mlon}#map=16/${mlat}/${mlon}"`,
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/room/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'react';
import { useHover, useFocusWithin } from 'react-aria';
import type { MatrixEvent, Room, Relations } from '$types/matrix-sdk';
import { EventStatus, MatrixEventEvent, RoomEvent } from '$types/matrix-sdk';
import { EventStatus, MatrixEventEvent, MsgType, RoomEvent } from '$types/matrix-sdk';
import classNames from 'classnames';
import { useSetAtom } from 'jotai';
import {
Expand Down Expand Up @@ -393,7 +393,7 @@ function MessageInternal(

const isGif = useMemo(() => {
const content = mEvent.getContent();
if (content.msgtype !== 'm.image') return false;
if (content.msgtype !== MsgType.Image) return false;
return checkIfGif(content?.info?.url ?? '', content?.info?.mimetype, content?.body);
}, [mEvent]);

Expand Down
3 changes: 2 additions & 1 deletion src/app/features/room/poll-modals/PollDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
M_POLL_START,
M_TEXT,
} from 'matrix-js-sdk';
import { MsgType } from '$types/matrix-sdk';
import { isKeyHotkey } from 'is-hotkey';
import * as css from './PollDialog.css';
import type { IReplyDraft } from '$state/room/roomInputDrafts';
Expand Down Expand Up @@ -113,7 +114,7 @@ export function PollDialog({ onCancel, mx, room, replyDraft, clearReplyDraft }:
question: {
[M_TEXT.name]: title.current,
body: title.current,
msgtype: 'm.text',
msgtype: MsgType.Text,
},
kind: isDisclosed ? M_POLL_KIND_DISCLOSED.name : M_POLL_KIND_UNDISCLOSED.name,
max_selections: maxSelections,
Expand Down
5 changes: 3 additions & 2 deletions src/app/features/room/schedule-send/ScheduledMessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
X,
} from '$components/icons/phosphor';
import type { Room } from '$types/matrix-sdk';
import { MatrixEvent } from '$types/matrix-sdk';
import { EventType, MatrixEvent } from '$types/matrix-sdk';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { useMatrixClient } from '$hooks/useMatrixClient';
import {
Expand Down Expand Up @@ -157,7 +157,8 @@ export function ScheduledMessagesList({ room, onEditMessage }: ScheduledMessages
const roomEvents = data?.delayed_events.filter(
(event) =>
event.room_id === room.roomId &&
(event.type === 'm.room.message' || event.type === 'm.room.encrypted')
(event.type === (EventType.RoomMessage as string) ||
event.type === (EventType.RoomMessageEncrypted as string))
);

const invalidateEvents = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/settings/notifications/AllMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getAllMessageDefaultRule = (
conditions.push({
kind: ConditionKind.EventMatch,
key: 'type',
pattern: encrypted ? 'm.room.encrypted' : 'm.room.message',
pattern: encrypted ? EventType.RoomMessageEncrypted : EventType.RoomMessage,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async function decryptPreviewFromPayload(
const crypto = mx.getCrypto();
if (!crypto || !pushData.content) return undefined;
const mEvent = new MatrixEvent({
type: 'm.room.encrypted',
type: EventType.RoomMessageEncrypted,
content: pushData.content,
room_id: roomId,
event_id: eventId,
Expand Down
3 changes: 2 additions & 1 deletion src/app/hooks/commands/fun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RoomMessageEventContent } from '$types/matrix-sdk';
import { MsgType } from '$types/matrix-sdk';
import type { CommandContext, CommandRecord } from './types';
import { Command } from './types';

Expand Down Expand Up @@ -102,7 +103,7 @@ export const createFunCommands = (ctx: CommandContext): Partial<CommandRecord> =
exe: async (payload) => {
const target = payload.trim();
await mx.sendMessage(room.roomId, {
msgtype: 'm.emote',
msgtype: MsgType.Emote,
'm.mentions': {
user_ids: target ? [target] : [],
},
Expand Down
6 changes: 3 additions & 3 deletions src/app/hooks/commands/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RoomMessageEventContent } from '$types/matrix-sdk';
import { MatrixError } from '$types/matrix-sdk';
import { MatrixError, MsgType } from '$types/matrix-sdk';
import { sendFeedback } from '$utils/sendFeedbackToUser';
import { CustomStateEvent } from '$types/matrix/room';
import { ErrorCode } from '../../cs-errorcode';
Expand Down Expand Up @@ -140,7 +140,7 @@ export const createMiscCommands = (ctx: CommandContext): Partial<CommandRecord>

if (mlat && mlon)
await mx.sendMessage(room.roomId, {
msgtype: 'm.location',
msgtype: MsgType.Location,
geo_uri: `geo:${mlat},${mlon};u=0`,
body: `https://www.openstreetmap.org/?mlat=${mlat}&mlon=${mlon}#map=16/${mlat}/${mlon}"`,
} as RoomMessageEventContent);
Expand Down Expand Up @@ -176,7 +176,7 @@ export const createMiscCommands = (ctx: CommandContext): Partial<CommandRecord>
return;
}
mx.sendMessage(room.roomId, {
msgtype: 'm.location',
msgtype: MsgType.Location,
geo_uri: `geo:${mlat},${mlon}${malt ? `,${malt}` : ''};u=0`,
body: `https://www.openstreetmap.org/?mlat=${mlat}&mlon=${mlon}#map=16/${mlat}/${mlon}"`,
} as unknown as RoomMessageEventContent);
Expand Down
31 changes: 18 additions & 13 deletions src/app/hooks/timeline/useProcessedTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,32 @@ export function getProcessedRowIndexForRawTimelineIndex(
return bestRowIndex >= 0 ? { rowIndex: bestRowIndex, focusRawIndex: bestRawIndex } : undefined;
}

// Decrypted room-message events are re-typed to this app-internal value; there is no SDK constant for it.
const ROOM_MESSAGE_DECRYPTED = 'm.room.message.encrypted';

const MESSAGE_EVENT_TYPES = new Set([
'm.room.message',
'm.room.message.encrypted',
'm.sticker',
'm.room.encrypted',
EventType.RoomMessage,
ROOM_MESSAGE_DECRYPTED,
EventType.Sticker,
EventType.RoomMessageEncrypted,
]);

export const STANDARD_RENDERED_EVENT_TYPES = new Set([
'm.room.message',
'm.room.message.encrypted',
'm.sticker',
EventType.RoomMessage,
ROOM_MESSAGE_DECRYPTED,
EventType.Sticker,
M_POLL_START.name,
'm.room.member',
'm.room.name',
'm.room.topic',
'm.room.avatar',
'org.matrix.msc3401.call.member',
EventType.RoomMember,
EventType.RoomName,
EventType.RoomTopic,
EventType.RoomAvatar,
EventType.GroupCallMemberPrefix,
]);

const normalizeMessageType = (t: string): string =>
t === 'm.room.encrypted' || t === 'm.room.message.encrypted' ? 'm.room.message' : t;
t === (EventType.RoomMessageEncrypted as string) || t === ROOM_MESSAGE_DECRYPTED
? EventType.RoomMessage
: t;

const isMessageRow = (mEvent: MatrixEvent): boolean =>
MESSAGE_EVENT_TYPES.has(mEvent.getType()) && !isEditEvent(mEvent);
Expand Down
6 changes: 3 additions & 3 deletions src/app/hooks/timeline/useTimelineActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MouseEventHandler } from 'react';
import { useCallback } from 'react';
import type { MatrixClient, Room, MatrixEvent } from '$types/matrix-sdk';
import type { UserProfile } from '$hooks/useUserProfile';
import { EventStatus } from '$types/matrix-sdk';
import { EventStatus, RelationType } from '$types/matrix-sdk';
import type { Editor } from 'slate';
import { ReactEditor } from 'slate-react';

Expand Down Expand Up @@ -154,7 +154,7 @@ export function useTimelineActions({
userId: mx.getUserId() ?? '',
eventId: threadRootId,
body: '',
relation: { rel_type: 'm.thread', event_id: threadRootId },
relation: { rel_type: RelationType.Thread, event_id: threadRootId },
}
: undefined
);
Expand All @@ -165,7 +165,7 @@ export function useTimelineActions({
const { body, formattedBody } = extractReplyDraftBody(replyEvt, timelineSet);

const { 'm.relates_to': relation } = startThread
? { 'm.relates_to': { rel_type: 'm.thread', event_id: draftEventId } }
? { 'm.relates_to': { rel_type: RelationType.Thread, event_id: draftEventId } }
: replyEvt.getWireContent();

const senderId = replyEvt.getSender();
Expand Down
7 changes: 4 additions & 3 deletions src/app/hooks/timeline/useTimelineRendererContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import type { Room } from '$types/matrix-sdk';
import { EventType } from '$types/matrix-sdk';
import type { HTMLReactParserOptions } from 'html-react-parser';
import type { Opts as LinkifyOpts } from 'linkifyjs';
import {
Expand Down Expand Up @@ -109,9 +110,9 @@ export function useTimelineRendererContext(room: Room): TimelineRendererContextV
const creators = useRoomCreators(room);
const permissions = useRoomPermissions(creators, powerLevels);
const canRedact = permissions.action('redact', mx.getSafeUserId());
const canDeleteOwn = permissions.event('m.room.redaction', mx.getSafeUserId());
const canSendReaction = permissions.event('m.reaction', mx.getSafeUserId());
const canPinEvent = permissions.stateEvent('m.room.pinned_events', mx.getSafeUserId());
const canDeleteOwn = permissions.event(EventType.RoomRedaction, mx.getSafeUserId());
const canSendReaction = permissions.event(EventType.Reaction, mx.getSafeUserId());
const canPinEvent = permissions.stateEvent(EventType.RoomPinnedEvents, mx.getSafeUserId());
const isReadOnly = !permissions.message(room.hasEncryptionStateEvent(), mx.getSafeUserId());
const getMemberPowerTag = useGetMemberPowerTag(room, creators, powerLevels);
const parseMemberEvent = useMemberEventParser();
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/client/BackgroundNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export function BackgroundNotifications() {
if (!eventId) return;

const eventType = mEvent.getType();
const isEncryptedType = eventType === 'm.room.encrypted';
const isEncryptedType = eventType === (EventType.RoomMessageEncrypted as string);

// For encrypted events that haven't been decrypted yet, wait for decryption
// before processing the notification. The SDK's Timeline re-emission after
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/client/client-non-ui/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export function MessageNotifications() {
// For encrypted events that haven't been decrypted yet, wait for decryption
// before processing the notification. The SDK's Timeline re-emission after
// decryption comes with data.liveEvent=false which would wrongly block it.
if (mEvent.getType() === 'm.room.encrypted' && mEvent.isEncrypted()) {
if (mEvent.getType() === (EventType.RoomMessageEncrypted as string) && mEvent.isEncrypted()) {
if (eventId) {
// Mark this event to skip focus check when decrypted, so we use the focus
// state from when the encrypted event originally arrived, not when it decrypts.
Expand Down
12 changes: 9 additions & 3 deletions src/app/plugins/call/CallEmbed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { MatrixClient, MatrixEvent, Room } from '$types/matrix-sdk';
import { ClientEvent, KnownMembership, MatrixEventEvent, RoomStateEvent } from '$types/matrix-sdk';
import {
ClientEvent,
EventType,
KnownMembership,
MatrixEventEvent,
RoomStateEvent,
} from '$types/matrix-sdk';
import { invoke } from '@tauri-apps/api/core';
import type { IRoomEvent, IWidget, WidgetDriver } from 'matrix-widget-api';
import {
Expand Down Expand Up @@ -333,11 +339,11 @@ export class CallEmbed {
});

// Sliding sync may not have delivered m.room.member yet.
if (!this.room.currentState.getStateEvents('m.room.member', myUserId)) {
if (!this.room.currentState.getStateEvents(EventType.RoomMember, myUserId)) {
const membership = this.room.getMyMembership();
if (membership) {
const memberRaw = {
type: 'm.room.member',
type: EventType.RoomMember,
state_key: myUserId,
room_id: this.roomId,
sender: myUserId,
Expand Down
5 changes: 3 additions & 2 deletions src/app/utils/messageReaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MatrixReactionEvent } from '$types/matrix/common';
import type { MatrixClient, Room } from 'matrix-js-sdk';
import type { MatrixClient, Room } from '$types/matrix-sdk';
import { RelationType } from '$types/matrix-sdk';
import { ImageUsage } from '$plugins/custom-emoji';
import { getImagePackReferencesForMxcWrappedInMap } from './msc4459helper';
import { MATRIX_UNSTABLE_IMAGE_SOURCE_PACK_PROPERTY_NAME } from '$unstable/prefixes';
Expand All @@ -14,7 +15,7 @@ export const getReactionContent = (
'm.relates_to': {
event_id: eventId,
key,
rel_type: 'm.annotation',
rel_type: RelationType.Annotation,
},
shortcode,
'com.beeper.reaction.shortcode': shortcode,
Expand Down
Loading
Loading