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

Commit

Permalink
Fix strict type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed May 11, 2023
1 parent bc09cca commit ab4fe63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
* Whether to send public or private receipts.
*/
private async determineReceiptType(client: MatrixClient): Promise<ReceiptType> {
const roomId = this.props.timelineSet.room.roomId;
const roomId = this.props.timelineSet.room?.roomId ?? null;
const shouldSendPublicReadReceipts = SettingsStore.getValue("sendReadReceipts", roomId);

if (shouldSendPublicReadReceipts) {
Expand All @@ -1000,7 +1000,12 @@ class TimelinePanel extends React.Component<IProps, IState> {
/**
* Whether a fully_read marker should be send.
*/
private shouldSendRM(): boolean {
private shouldSendRM(readMarkerEventId: string | null): readMarkerEventId is string {
if (!this.state.readMarkerEventId) {
// Nothing that can be send.
return false;
}

if (this.lastRRSentEventId && this.lastRMSentEventId === this.state.readMarkerEventId) {
// Prevent sending the same receipt twice.
return false;
Expand Down Expand Up @@ -1082,9 +1087,10 @@ class TimelinePanel extends React.Component<IProps, IState> {
lastReadEvent,
lastReadEventIndex,
);
const shouldSendRM = this.shouldSendRM();
const readMarkerEventId = this.state.readMarkerEventId;
const shouldSendRM = this.shouldSendRM(readMarkerEventId);

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

if (shouldSendRM) {
const readMarkerEvent = this.props.timelineSet.findEventById(this.state.readMarkerEventId);
const readMarkerEvent = this.props.timelineSet.findEventById(readMarkerEventId);

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

logger.error("Error sending receipt", {
room: this.props.timelineSet.room.roomId,
room: this.props.timelineSet.room?.roomId,
error: err,
});
}
Expand All @@ -1146,7 +1152,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
this.lastRMSentEventId = undefined;

logger.error("Error sending fully_read", {
room: this.props.timelineSet.room.roomId,
room: this.props.timelineSet.room?.roomId,
error: err,
});
}
Expand Down
6 changes: 3 additions & 3 deletions test/components/structures/TimelinePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ describe("TimelinePanel", () => {
/>,
);
await flushPromises();
timelinePanel = ref.current;
timelinePanel = ref.current!;
};

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

if (threadRoot) {
thread = new Thread(threadRoot.getId(), threadRoot, {
thread = new Thread(threadRoot.getId()!, threadRoot, {
client: client,
room,
});
Expand Down Expand Up @@ -211,7 +211,7 @@ describe("TimelinePanel", () => {

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

0 comments on commit ab4fe63

Please sign in to comment.