Skip to content

Commit a1ab0d4

Browse files
authored
Clearly indicate that lastReply on a Thread can return falsy (#2462)
1 parent b9ca3ce commit a1ab0d4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/models/thread.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import { Optional } from "matrix-events-sdk";
18+
1719
import { MatrixClient, MatrixEventEvent, RelationType, RoomEvent } from "../matrix";
1820
import { TypedReEmitter } from "../ReEmitter";
1921
import { IRelationsRequestOpts } from "../@types/requests";
@@ -328,15 +330,16 @@ export class Thread extends TypedEventEmitter<EmittedEvents, EventHandlerMap> {
328330
}
329331

330332
/**
331-
* Return last reply to the thread
333+
* Return last reply to the thread, if known.
332334
*/
333-
public lastReply(matches: (ev: MatrixEvent) => boolean = () => true): MatrixEvent {
335+
public lastReply(matches: (ev: MatrixEvent) => boolean = () => true): Optional<MatrixEvent> {
334336
for (let i = this.events.length - 1; i >= 0; i--) {
335337
const event = this.events[i];
336338
if (matches(event)) {
337339
return event;
338340
}
339341
}
342+
return null;
340343
}
341344

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

355358
/**
356-
* A getter for the last event added to the thread
359+
* A getter for the last event added to the thread, if known.
357360
*/
358-
public get replyToEvent(): MatrixEvent {
361+
public get replyToEvent(): Optional<MatrixEvent> {
359362
return this.lastEvent ?? this.lastReply();
360363
}
361364

0 commit comments

Comments
 (0)