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

Commit ab4fe63

Browse files
committed
Fix strict type issues
1 parent bc09cca commit ab4fe63

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/components/structures/TimelinePanel.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
979979
* Whether to send public or private receipts.
980980
*/
981981
private async determineReceiptType(client: MatrixClient): Promise<ReceiptType> {
982-
const roomId = this.props.timelineSet.room.roomId;
982+
const roomId = this.props.timelineSet.room?.roomId ?? null;
983983
const shouldSendPublicReadReceipts = SettingsStore.getValue("sendReadReceipts", roomId);
984984

985985
if (shouldSendPublicReadReceipts) {
@@ -1000,7 +1000,12 @@ class TimelinePanel extends React.Component<IProps, IState> {
10001000
/**
10011001
* Whether a fully_read marker should be send.
10021002
*/
1003-
private shouldSendRM(): boolean {
1003+
private shouldSendRM(readMarkerEventId: string | null): readMarkerEventId is string {
1004+
if (!this.state.readMarkerEventId) {
1005+
// Nothing that can be send.
1006+
return false;
1007+
}
1008+
10041009
if (this.lastRRSentEventId && this.lastRMSentEventId === this.state.readMarkerEventId) {
10051010
// Prevent sending the same receipt twice.
10061011
return false;
@@ -1082,9 +1087,10 @@ class TimelinePanel extends React.Component<IProps, IState> {
10821087
lastReadEvent,
10831088
lastReadEventIndex,
10841089
);
1085-
const shouldSendRM = this.shouldSendRM();
1090+
const readMarkerEventId = this.state.readMarkerEventId;
1091+
const shouldSendRM = this.shouldSendRM(readMarkerEventId);
10861092

1087-
debuglog(`Sending Read Markers for ${this.props.timelineSet.room.roomId}: `, {
1093+
debuglog(`Sending Read Markers for ${this.props.timelineSet.room?.roomId}: `, {
10881094
shouldSendRR,
10891095
shouldSendRM,
10901096
currentRREventId,
@@ -1101,7 +1107,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11011107
}
11021108

11031109
if (shouldSendRM) {
1104-
const readMarkerEvent = this.props.timelineSet.findEventById(this.state.readMarkerEventId);
1110+
const readMarkerEvent = this.props.timelineSet.findEventById(readMarkerEventId);
11051111

11061112
if (readMarkerEvent) {
11071113
proms.push(await this.sendReadMarker(client, readMarkerEvent));
@@ -1126,7 +1132,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11261132
this.lastRRSentEventId = undefined;
11271133

11281134
logger.error("Error sending receipt", {
1129-
room: this.props.timelineSet.room.roomId,
1135+
room: this.props.timelineSet.room?.roomId,
11301136
error: err,
11311137
});
11321138
}
@@ -1146,7 +1152,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11461152
this.lastRMSentEventId = undefined;
11471153

11481154
logger.error("Error sending fully_read", {
1149-
room: this.props.timelineSet.room.roomId,
1155+
room: this.props.timelineSet.room?.roomId,
11501156
error: err,
11511157
});
11521158
}

test/components/structures/TimelinePanel-test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ describe("TimelinePanel", () => {
144144
/>,
145145
);
146146
await flushPromises();
147-
timelinePanel = ref.current;
147+
timelinePanel = ref.current!;
148148
};
149149

150150
const setUpTimelineSet = (threadRoot?: MatrixEvent) => {
151151
let thread: Thread | undefined = undefined;
152152

153153
if (threadRoot) {
154-
thread = new Thread(threadRoot.getId(), threadRoot, {
154+
thread = new Thread(threadRoot.getId()!, threadRoot, {
155155
client: client,
156156
room,
157157
});
@@ -211,7 +211,7 @@ describe("TimelinePanel", () => {
211211

212212
it("and forgetting the read markers, should send the stored marker again", async () => {
213213
timelineSet.addLiveEvent(ev2, {});
214-
room.addEphemeralEvents([newReceipt(ev2.getId(), userId, 222, 200)]);
214+
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
215215
timelinePanel.forgetReadMarker();
216216
await flushPromises();
217217
expect(client.sendReadReceipt).toHaveBeenCalledWith(ev2, ReceiptType.FullyRead, true);

0 commit comments

Comments
 (0)