Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix getRelationsForEvent under TypeScript strict mode #9558

Merged
merged 31 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b291130
Fix getRelationsForEvent tsc strictness
MadLittleMods Nov 8, 2022
331be20
Use shared type for GetRelationsForEvent
MadLittleMods Nov 8, 2022
639ae6f
Fix lint
MadLittleMods Nov 8, 2022
095347e
Add alternative type
MadLittleMods Nov 8, 2022
6db8927
getRelationsForEvent is not required
MadLittleMods Nov 8, 2022
1eabf6a
Relations are optional
MadLittleMods Nov 8, 2022
3060bba
Reactions are optional
MadLittleMods Nov 8, 2022
bc788c0
We expect relations in these tests
MadLittleMods Nov 8, 2022
f42971b
Add more protection if the eventID is not defined
MadLittleMods Nov 8, 2022
6aec3ef
Allow null too
MadLittleMods Nov 8, 2022
0f80d5a
Better test typing
MadLittleMods Nov 8, 2022
bab05e2
User ID is not necessary unless something is selected
MadLittleMods Nov 9, 2022
a5a61d2
It's okay to [].includes(null)
MadLittleMods Nov 9, 2022
ae6dddc
Null is as good as undefined here
MadLittleMods Nov 9, 2022
a51fb2c
Null or undefined is good here
MadLittleMods Nov 9, 2022
0cef622
We have some expectations for the tests
MadLittleMods Nov 9, 2022
6caefb0
The room and user can be undefined too
MadLittleMods Nov 9, 2022
eb30722
Protec
MadLittleMods Nov 9, 2022
7aaf107
Reactions are optional
MadLittleMods Nov 9, 2022
75582e7
Try match signatures
MadLittleMods Nov 9, 2022
382c380
Null or undefined
MadLittleMods Nov 9, 2022
07089e7
More null or undefined
MadLittleMods Nov 9, 2022
847132e
Protec
MadLittleMods Nov 9, 2022
cd98cef
Fix typo (wrong variable)
MadLittleMods Nov 9, 2022
a909456
Remove optional params
MadLittleMods Nov 9, 2022
25d0e36
Fix up last maaaaybe relevant lint
MadLittleMods Nov 10, 2022
5b76218
Merge branch 'develop' into madlittlemods/strict-getRelationsForEvent
MadLittleMods Nov 10, 2022
2467df2
Merge branch 'develop' into madlittlemods/strict-getRelationsForEvent
t3chguy Nov 11, 2022
8bf3d64
Merge branch 'develop' into madlittlemods/strict-getRelationsForEvent
MadLittleMods Nov 17, 2022
0a18bba
Merge branch 'madlittlemods/strict-getRelationsForEvent' of github.co…
MadLittleMods Nov 17, 2022
d0e7258
Merge branch 'develop' into madlittlemods/strict-getRelationsForEvent
MadLittleMods Nov 21, 2022
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
5 changes: 2 additions & 3 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import classNames from 'classnames';
import { Room } from 'matrix-js-sdk/src/models/room';
import { EventType } from 'matrix-js-sdk/src/@types/event';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Relations } from "matrix-js-sdk/src/models/relations";
import { logger } from 'matrix-js-sdk/src/logger';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon';
Expand All @@ -35,7 +34,7 @@ import SettingsStore from '../../settings/SettingsStore';
import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext";
import { Layout } from "../../settings/enums/Layout";
import { _t } from "../../languageHandler";
import EventTile, { UnwrappedEventTile, IReadReceiptProps } from "../views/rooms/EventTile";
import EventTile, { UnwrappedEventTile, GetRelationsForEvent, IReadReceiptProps } from "../views/rooms/EventTile";
import { hasText } from "../../TextForEvent";
import IRCTimelineProfileResizer from "../views/elements/IRCTimelineProfileResizer";
import DMRoomMap from "../../utils/DMRoomMap";
Expand Down Expand Up @@ -186,7 +185,7 @@ interface IProps {
// helper function to access relations for an event
onUnfillRequest?(backwards: boolean, scrollToken: string): void;

getRelationsForEvent?(eventId: string, relationType: string, eventType: string): Relations;
getRelationsForEvent?: GetRelationsForEvent;

hideThreadedMessages?: boolean;
disableGrouping?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ class TimelinePanel extends React.Component<IProps, IState> {

private getRelationsForEvent = (
eventId: string,
relationType: RelationType,
relationType: RelationType | string,
eventType: EventType | string,
) => this.props.timelineSet.relations?.getChildEventsForEvent(eventId, relationType, eventType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ interface IProps extends IPosition {
// True if the menu is being used as a right click menu
rightClick?: boolean;
// The Relations model from the JS SDK for reactions to `mxEvent`
reactions?: Relations;
reactions?: Relations | null | undefined;
// A permalink to this event or an href of an anchor element the user has clicked
link?: string;

Expand Down
8 changes: 2 additions & 6 deletions src/components/views/dialogs/EndPollDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
import React from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { Relations } from "matrix-js-sdk/src/models/relations";
import { PollEndEvent } from "matrix-events-sdk";

import { _t } from "../../../languageHandler";
Expand All @@ -26,16 +25,13 @@ import QuestionDialog from "./QuestionDialog";
import { findTopAnswer } from "../messages/MPollBody";
import Modal from "../../../Modal";
import ErrorDialog from "./ErrorDialog";
import { GetRelationsForEvent } from "../rooms/EventTile";

interface IProps extends IDialogProps {
matrixClient: MatrixClient;
event: MatrixEvent;
onFinished: (success: boolean) => void;
getRelationsForEvent?: (
eventId: string,
relationType: string,
eventType: string
) => Relations;
getRelationsForEvent?: GetRelationsForEvent;
}

export default class EndPollDialog extends React.Component<IProps> {
Expand Down
6 changes: 2 additions & 4 deletions src/components/views/elements/ReplyChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import React from 'react';
import classNames from 'classnames';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Room } from 'matrix-js-sdk/src/models/room';
import { Relations } from 'matrix-js-sdk/src/models/relations';
import { MatrixClient } from 'matrix-js-sdk/src/client';

import { _t } from '../../../languageHandler';
Expand All @@ -36,6 +35,7 @@ import AccessibleButton, { ButtonEvent } from './AccessibleButton';
import { getParentEventId, shouldDisplayReply } from '../../../utils/Reply';
import RoomContext from "../../../contexts/RoomContext";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { GetRelationsForEvent } from "../rooms/EventTile";

/**
* This number is based on the previous behavior - if we have message of height
Expand All @@ -56,9 +56,7 @@ interface IProps {
forExport?: boolean;
isQuoteExpanded?: boolean;
setQuoteExpanded: (isExpanded: boolean) => void;
getRelationsForEvent?: (
(eventId: string, relationType: string, eventType: string) => Relations
);
getRelationsForEvent?: GetRelationsForEvent;
}

interface IState {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/emojipicker/ReactionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { FocusComposerPayload } from '../../../dispatcher/payloads/FocusComposer

interface IProps {
mxEvent: MatrixEvent;
reactions?: Relations;
reactions?: Relations | null | undefined;
onFinished(): void;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/views/messages/IBodyProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ limitations under the License.

import React, { LegacyRef } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Relations } from "matrix-js-sdk/src/models/relations";

import { MediaEventHelper } from "../../../utils/MediaEventHelper";
import EditorStateTransfer from "../../../utils/EditorStateTransfer";
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
import { GetRelationsForEvent } from "../rooms/EventTile";

export interface IBodyProps {
mxEvent: MatrixEvent;
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface IBodyProps {
isSeeingThroughMessageHiddenForModeration?: boolean;

// helper function to access relations for this event
getRelationsForEvent?: (eventId: string, relationType: string, eventType: string) => Relations;
getRelationsForEvent?: GetRelationsForEvent;

ref?: React.RefObject<any> | LegacyRef<any>;
}
10 changes: 5 additions & 5 deletions src/components/views/messages/MBeaconBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ const useUniqueId = (eventId: string): string => {
// remove related beacon locations on beacon redaction
const useHandleBeaconRedaction = (
event: MatrixEvent,
getRelationsForEvent: GetRelationsForEvent,
cli: MatrixClient,
matrixClient: MatrixClient,
getRelationsForEvent?: GetRelationsForEvent,
): void => {
const onBeforeBeaconInfoRedaction = useCallback((_event: MatrixEvent, redactionEvent: MatrixEvent) => {
const relations = getRelationsForEvent ?
getRelationsForEvent(event.getId(), RelationType.Reference, M_BEACON.name) :
undefined;

relations?.getRelations()?.forEach(locationEvent => {
cli.redactEvent(
matrixClient.redactEvent(
locationEvent.getRoomId(),
locationEvent.getId(),
undefined,
redactionEvent.getContent(),
);
});
}, [event, getRelationsForEvent, cli]);
}, [event, matrixClient, getRelationsForEvent]);

useEffect(() => {
event.addListener(MatrixEventEvent.BeforeRedaction, onBeforeBeaconInfoRedaction);
Expand Down Expand Up @@ -151,7 +151,7 @@ const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelati
const markerRoomMember = isSelfLocation(mxEvent.getContent()) ? mxEvent.sender : undefined;
const isOwnBeacon = beacon?.beaconInfoOwner === matrixClient.getUserId();

useHandleBeaconRedaction(mxEvent, getRelationsForEvent, matrixClient);
useHandleBeaconRedaction(mxEvent, matrixClient, getRelationsForEvent);

const onClick = () => {
if (displayStatus !== BeaconDisplayStatus.Active) {
Expand Down
Loading