using a fallback user when we're unable to find the author

fixes potential crash when failing to lookup a user by id
This commit is contained in:
Adam Brown 2022-10-22 12:09:51 +01:00
parent aa609a7115
commit 6ca4ecce68
1 changed files with 5 additions and 5 deletions

View File

@ -1,14 +1,14 @@
package app.dapk.st.matrix.sync.internal.sync package app.dapk.st.matrix.sync.internal.sync
import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.common.*
import app.dapk.st.matrix.common.UserCredentials
import app.dapk.st.matrix.common.convertMxUrToUrl
import app.dapk.st.matrix.sync.MessageMeta import app.dapk.st.matrix.sync.MessageMeta
import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomMembersService import app.dapk.st.matrix.sync.RoomMembersService
import app.dapk.st.matrix.sync.find import app.dapk.st.matrix.sync.find
import app.dapk.st.matrix.sync.internal.request.ApiTimelineEvent import app.dapk.st.matrix.sync.internal.request.ApiTimelineEvent
private val UNKNOWN_AUTHOR = RoomMember(id = UserId("unknown"), displayName = null, avatarUrl = null)
internal class RoomEventFactory( internal class RoomEventFactory(
private val roomMembersService: RoomMembersService private val roomMembersService: RoomMembersService
) { ) {
@ -21,7 +21,7 @@ internal class RoomEventFactory(
) = RoomEvent.Message( ) = RoomEvent.Message(
eventId = this.id, eventId = this.id,
content = content, content = content,
author = roomMembersService.find(roomId, this.senderId)!!, author = roomMembersService.find(roomId, this.senderId) ?: UNKNOWN_AUTHOR,
utcTimestamp = utcTimestamp, utcTimestamp = utcTimestamp,
meta = MessageMeta.FromServer, meta = MessageMeta.FromServer,
edited = edited, edited = edited,
@ -36,7 +36,7 @@ internal class RoomEventFactory(
) = RoomEvent.Image( ) = RoomEvent.Image(
eventId = this.id, eventId = this.id,
imageMeta = imageMeta, imageMeta = imageMeta,
author = roomMembersService.find(roomId, this.senderId)!!, author = roomMembersService.find(roomId, this.senderId) ?: UNKNOWN_AUTHOR,
utcTimestamp = utcTimestamp, utcTimestamp = utcTimestamp,
meta = MessageMeta.FromServer, meta = MessageMeta.FromServer,
edited = edited, edited = edited,