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

Commit

Permalink
Fix issues around up arrow event edit shortcut (#9645)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Nov 29, 2022
1 parent 09282d9 commit d341c56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { logger } from "matrix-js-sdk/src/logger";
import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
import { EventType } from 'matrix-js-sdk/src/@types/event';
import { RoomState, RoomStateEvent } from 'matrix-js-sdk/src/models/room-state';
import { EventTimelineSet } from "matrix-js-sdk/src/models/event-timeline-set";
import { CallState, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { throttle } from "lodash";
import { MatrixError } from 'matrix-js-sdk/src/http-api';
Expand Down Expand Up @@ -1211,10 +1210,14 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
});
};

private onRoomTimelineReset = (room: Room, timelineSet: EventTimelineSet) => {
if (!room || room.roomId !== this.state.room?.roomId) return;
logger.log(`Live timeline of ${room.roomId} was reset`);
this.setState({ liveTimeline: timelineSet.getLiveTimeline() });
private onRoomTimelineReset = (room?: Room): void => {
if (room &&
room.roomId === this.state.room?.roomId &&
room.getLiveTimeline() !== this.state.liveTimeline
) {
logger.log(`Live timeline of ${room.roomId} was reset`);
this.setState({ liveTimeline: room.getLiveTimeline() });
}
};

private getRoomTombstone(room = this.state.room) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/EventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export function findEditableEvent({
events: MatrixEvent[];
isForward: boolean;
fromEventId?: string;
}): MatrixEvent {
}): MatrixEvent | undefined {
if (!events.length) return;
const maxIdx = events.length - 1;
const inc = isForward ? 1 : -1;
const beginIdx = isForward ? 0 : maxIdx;
Expand Down
10 changes: 10 additions & 0 deletions test/utils/EventUtils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
canEditContent,
canEditOwnEvent,
fetchInitialEvent,
findEditableEvent,
isContentActionable,
isLocationEvent,
isVoiceMessage,
Expand Down Expand Up @@ -430,4 +431,13 @@ describe('EventUtils', () => {
expect(room.getThread(THREAD_ROOT)).toBeInstanceOf(Thread);
});
});

describe("findEditableEvent", () => {
it("should not explode when given empty events array", () => {
expect(findEditableEvent({
events: [],
isForward: true,
})).toBeUndefined();
});
});
});

0 comments on commit d341c56

Please sign in to comment.