From a345c6c8e579d6f87c487c4eec4773ba221d3d8d Mon Sep 17 00:00:00 2001 From: valere Date: Sat, 31 Dec 2022 12:26:24 +0100 Subject: [PATCH 1/2] fix 7870 --- CHANGES.md | 2 +- changelog.d/7870.bugfix | 1 + .../room/create/CreateLocalRoomTask.kt | 19 ++++++++----------- 3 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 changelog.d/7870.bugfix diff --git a/CHANGES.md b/CHANGES.md index 5bd85efc67..41b1e336b6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -Changes in Element v.5.16 (2022-12-29) +Changes in Element v1.5.16 (2022-12-29) ====================================== Features ✨ diff --git a/changelog.d/7870.bugfix b/changelog.d/7870.bugfix new file mode 100644 index 0000000000..43070dadeb --- /dev/null +++ b/changelog.d/7870.bugfix @@ -0,0 +1 @@ +Start DM will create a deadlock is user profile was never loaded diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt index 0cda6eca99..793c2573be 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt @@ -21,7 +21,7 @@ import io.realm.Realm import io.realm.RealmConfiguration import io.realm.kotlin.createObject import kotlinx.coroutines.TimeoutCancellationException -import kotlinx.coroutines.runBlocking +import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.room.failure.CreateRoomFailure import org.matrix.android.sdk.api.session.room.model.Membership @@ -73,8 +73,9 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( override suspend fun execute(params: CreateRoomParams): String { val createRoomBody = createRoomBodyBuilder.build(params) val roomId = RoomLocalEcho.createLocalEchoId() + val eventList = createLocalRoomStateEventsTask.execute(CreateLocalRoomStateEventsTask.Params(createRoomBody)) monarchy.awaitTransaction { realm -> - createLocalRoomEntity(realm, roomId, createRoomBody) + createLocalRoomEntity(realm, roomId, eventList) createLocalRoomSummaryEntity(realm, roomId, params, createRoomBody) } @@ -96,10 +97,10 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( * Create a local room entity from the given room creation params. * This will also generate and store in database the chunk and the events related to the room params in order to retrieve and display the local room. */ - private fun createLocalRoomEntity(realm: Realm, roomId: String, createRoomBody: CreateRoomBody) { + private fun createLocalRoomEntity(realm: Realm, roomId: String, localStateEventList: List) { RoomEntity.getOrCreate(realm, roomId).apply { membership = Membership.JOIN - chunks.add(createLocalRoomChunk(realm, roomId, createRoomBody)) + chunks.add(createLocalRoomChunk(realm, roomId, localStateEventList)) membersLoadStatus = RoomMembersLoadStatusType.LOADED } } @@ -145,23 +146,19 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( * * @param realm the current instance of realm * @param roomId the id of the local room - * @param createRoomBody the room creation params + * @param localStateEventList list of local state events for that room * * @return a chunk entity */ - private fun createLocalRoomChunk(realm: Realm, roomId: String, createRoomBody: CreateRoomBody): ChunkEntity { + private fun createLocalRoomChunk(realm: Realm, roomId: String, localStateEventList: List): ChunkEntity { val chunkEntity = realm.createObject().apply { isLastBackward = true isLastForward = true } - // Can't suspend when using realm as it could jump thread - val eventList = runBlocking { - createLocalRoomStateEventsTask.execute(CreateLocalRoomStateEventsTask.Params(createRoomBody)) - } val roomMemberContentsByUser = HashMap() - for (event in eventList) { + for (event in localStateEventList) { if (event.eventId == null || event.senderId == null || event.type == null) { continue } From b6258cf02f0458bd9c0cace259d7a03c3e3e1fce Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 Jan 2023 09:51:57 +0100 Subject: [PATCH 2/2] Fix typo in changelog. --- changelog.d/7870.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/7870.bugfix b/changelog.d/7870.bugfix index 43070dadeb..9e9c421276 100644 --- a/changelog.d/7870.bugfix +++ b/changelog.d/7870.bugfix @@ -1 +1 @@ -Start DM will create a deadlock is user profile was never loaded +Start DM will create a deadlock if user profile was never loaded