From 6ca4ecce682bc8b808136c88e138bc041027cdc8 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sat, 22 Oct 2022 12:09:51 +0100 Subject: [PATCH] using a fallback user when we're unable to find the author fixes potential crash when failing to lookup a user by id --- .../st/matrix/sync/internal/sync/RoomEventFactory.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt index 4ad293b..2abbd45 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt @@ -1,14 +1,14 @@ package app.dapk.st.matrix.sync.internal.sync -import app.dapk.st.matrix.common.RoomId -import app.dapk.st.matrix.common.UserCredentials -import app.dapk.st.matrix.common.convertMxUrToUrl +import app.dapk.st.matrix.common.* import app.dapk.st.matrix.sync.MessageMeta import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomMembersService import app.dapk.st.matrix.sync.find import app.dapk.st.matrix.sync.internal.request.ApiTimelineEvent +private val UNKNOWN_AUTHOR = RoomMember(id = UserId("unknown"), displayName = null, avatarUrl = null) + internal class RoomEventFactory( private val roomMembersService: RoomMembersService ) { @@ -21,7 +21,7 @@ internal class RoomEventFactory( ) = RoomEvent.Message( eventId = this.id, content = content, - author = roomMembersService.find(roomId, this.senderId)!!, + author = roomMembersService.find(roomId, this.senderId) ?: UNKNOWN_AUTHOR, utcTimestamp = utcTimestamp, meta = MessageMeta.FromServer, edited = edited, @@ -36,7 +36,7 @@ internal class RoomEventFactory( ) = RoomEvent.Image( eventId = this.id, imageMeta = imageMeta, - author = roomMembersService.find(roomId, this.senderId)!!, + author = roomMembersService.find(roomId, this.senderId) ?: UNKNOWN_AUTHOR, utcTimestamp = utcTimestamp, meta = MessageMeta.FromServer, edited = edited,