Skip to content

Commit

Permalink
Clearly indicate that lastReply on a Thread can return falsy (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Jun 14, 2022
1 parent b9ca3ce commit a1ab0d4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Optional } from "matrix-events-sdk";

import { MatrixClient, MatrixEventEvent, RelationType, RoomEvent } from "../matrix";
import { TypedReEmitter } from "../ReEmitter";
import { IRelationsRequestOpts } from "../@types/requests";
Expand Down Expand Up @@ -328,15 +330,16 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
}

/**
* Return last reply to the thread
* Return last reply to the thread, if known.
*/
public lastReply(matches: (ev: MatrixEvent) => boolean = () => true): MatrixEvent {
public lastReply(matches: (ev: MatrixEvent) => boolean = () => true): Optional<MatrixEvent> {
for (let i = this.events.length - 1; i >= 0; i--) {
const event = this.events[i];
if (matches(event)) {
return event;
}
}
return null;
}

public get roomId(): string {
Expand All @@ -353,9 +356,9 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
}

/**
* A getter for the last event added to the thread
* A getter for the last event added to the thread, if known.
*/
public get replyToEvent(): MatrixEvent {
public get replyToEvent(): Optional<MatrixEvent> {
return this.lastEvent ?? this.lastReply();
}

Expand Down

0 comments on commit a1ab0d4

Please sign in to comment.