-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create the DM when sending an event #6127
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
72896f1
Create the DM when sending an event
b14e3c6
Start DM - Fix first message not encrypted
69917eb
Start DM - Handle third party invites
c96343f
Persists CreateRoomParams into LocalRoomSummaryEntity
5df71c6
Update CreateRoomParams from the potential FeaturePreset before persi…
7216f6b
Fix local events generation following the specification
dee8484
Create local room state events in dedicated task
e22ce0d
Set stateKey as empty by default
882065f
Add unit tests for CreateLocalRoomStateEventsTask
3905e56
Add unit tests for CreateRoomFromLocalRoomTask
725537d
Remove safe call
cbf9dbf
Verify tombstone event
128ff0d
Extract condition to reduce code complexity
5d1124a
Update doc
110caba
Remove useless apply in CreateLocalRoomStateEventsTask
2be2a05
Change visibility of LocalRoomThirdPartyInviteContent to internal
90d688c
Remove useless explicit field type
eab4ebc
Remove roomCreatorUserId and use current userId by default
cac4df7
Improve createRoomThreePidEvents for clarity
ee7c059
Fix copyright
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create DM room only on first message - Create the DM and navigate to the new room after sending an event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,16 @@ | |
package org.matrix.android.sdk.api.session.room.model.create | ||
|
||
import android.net.Uri | ||
import com.squareup.moshi.JsonClass | ||
import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM | ||
import org.matrix.android.sdk.api.session.identity.ThreePid | ||
import org.matrix.android.sdk.api.session.room.model.GuestAccess | ||
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent | ||
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility | ||
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility | ||
import org.matrix.android.sdk.internal.di.MoshiProvider | ||
|
||
@JsonClass(generateAdapter = true) | ||
open class CreateRoomParams { | ||
/** | ||
* A public visibility indicates that the room will be shown in the published room list. | ||
|
@@ -61,12 +64,12 @@ open class CreateRoomParams { | |
* A list of user IDs to invite to the room. | ||
* This will tell the server to invite everyone in the list to the newly created room. | ||
*/ | ||
val invitedUserIds = mutableListOf<String>() | ||
var invitedUserIds = mutableListOf<String>() | ||
|
||
/** | ||
* A list of objects representing third party IDs to invite into the room. | ||
*/ | ||
val invite3pids = mutableListOf<ThreePid>() | ||
var invite3pids = mutableListOf<ThreePid>() | ||
|
||
/** | ||
* Initial Guest Access. | ||
|
@@ -99,14 +102,14 @@ open class CreateRoomParams { | |
* The server will clobber the following keys: creator. | ||
* Future versions of the specification may allow the server to clobber other keys. | ||
*/ | ||
val creationContent = mutableMapOf<String, Any>() | ||
var creationContent = mutableMapOf<String, Any>() | ||
|
||
/** | ||
* A list of state events to set in the new room. This allows the user to override the default state events | ||
* set in the new room. The expected format of the state events are an object with type, state_key and content keys set. | ||
* Takes precedence over events set by preset, but gets overridden by name and topic keys. | ||
*/ | ||
val initialStates = mutableListOf<CreateRoomStateEvent>() | ||
var initialStates = mutableListOf<CreateRoomStateEvent>() | ||
|
||
/** | ||
* Set to true to disable federation of this room. | ||
|
@@ -151,7 +154,7 @@ open class CreateRoomParams { | |
* Supported value: MXCRYPTO_ALGORITHM_MEGOLM. | ||
*/ | ||
var algorithm: String? = null | ||
private set | ||
internal set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to change the visibility for JSON conversion |
||
|
||
var historyVisibility: RoomHistoryVisibility? = null | ||
|
||
|
@@ -161,10 +164,18 @@ open class CreateRoomParams { | |
|
||
var roomVersion: String? = null | ||
|
||
var featurePreset: RoomFeaturePreset? = null | ||
@Transient var featurePreset: RoomFeaturePreset? = null | ||
|
||
companion object { | ||
private const val CREATION_CONTENT_KEY_M_FEDERATE = "m.federate" | ||
private const val CREATION_CONTENT_KEY_ROOM_TYPE = "type" | ||
internal const val CREATION_CONTENT_KEY_M_FEDERATE = "m.federate" | ||
internal const val CREATION_CONTENT_KEY_ROOM_TYPE = "type" | ||
|
||
fun fromJson(json: String?): CreateRoomParams? { | ||
return json?.let { MoshiProvider.providesMoshi().adapter(CreateRoomParams::class.java).fromJson(it) } | ||
} | ||
} | ||
} | ||
|
||
internal fun CreateRoomParams.toJSONString(): String { | ||
return MoshiProvider.providesMoshi().adapter(CreateRoomParams::class.java).toJson(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,12 @@ | |
package org.matrix.android.sdk.internal.crypto.tasks | ||
|
||
import org.matrix.android.sdk.api.session.events.model.Event | ||
import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho | ||
import org.matrix.android.sdk.api.session.room.send.SendState | ||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver | ||
import org.matrix.android.sdk.internal.network.executeRequest | ||
import org.matrix.android.sdk.internal.session.room.RoomAPI | ||
import org.matrix.android.sdk.internal.session.room.create.CreateRoomFromLocalRoomTask | ||
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask | ||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository | ||
import org.matrix.android.sdk.internal.task.Task | ||
|
@@ -37,12 +39,17 @@ internal class DefaultSendEventTask @Inject constructor( | |
private val localEchoRepository: LocalEchoRepository, | ||
private val encryptEventTask: EncryptEventTask, | ||
private val loadRoomMembersTask: LoadRoomMembersTask, | ||
private val createRoomFromLocalRoomTask: CreateRoomFromLocalRoomTask, | ||
private val roomAPI: RoomAPI, | ||
private val globalErrorReceiver: GlobalErrorReceiver | ||
) : SendEventTask { | ||
|
||
override suspend fun execute(params: SendEventTask.Params): String { | ||
try { | ||
if (params.event.isLocalRoomEvent) { | ||
return createRoomAndSendEvent(params) | ||
} | ||
|
||
// Make sure to load all members in the room before sending the event. | ||
params.event.roomId | ||
?.takeIf { params.encrypt } | ||
|
@@ -78,6 +85,12 @@ internal class DefaultSendEventTask @Inject constructor( | |
} | ||
} | ||
|
||
private suspend fun createRoomAndSendEvent(params: SendEventTask.Params): String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could add a unit test for the case of local room id? |
||
val roomId = createRoomFromLocalRoomTask.execute(CreateRoomFromLocalRoomTask.Params(params.event.roomId.orEmpty())) | ||
Timber.d("State event: convert local room (${params.event.roomId}) to existing room ($roomId) before sending the event.") | ||
return execute(params.copy(event = params.event.copy(roomId = roomId))) | ||
} | ||
|
||
@Throws | ||
private suspend fun handleEncryption(params: SendEventTask.Params): Event { | ||
if (params.encrypt && !params.event.isEncrypted()) { | ||
|
@@ -91,4 +104,7 @@ internal class DefaultSendEventTask @Inject constructor( | |
} | ||
return params.event | ||
} | ||
|
||
private val Event.isLocalRoomEvent | ||
get() = RoomLocalEcho.isLocalEchoId(roomId.orEmpty()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...d/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo036.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.database.migration | ||
|
||
import io.realm.DynamicRealm | ||
import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntityFields | ||
import org.matrix.android.sdk.internal.util.database.RealmMigrator | ||
|
||
internal class MigrateSessionTo036(realm: DynamicRealm) : RealmMigrator(realm, 36) { | ||
|
||
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.create("LocalRoomSummaryEntity") | ||
.addField(LocalRoomSummaryEntityFields.ROOM_ID, String::class.java) | ||
.addPrimaryKey(LocalRoomSummaryEntityFields.ROOM_ID) | ||
.setRequired(LocalRoomSummaryEntityFields.ROOM_ID, true) | ||
.addField(LocalRoomSummaryEntityFields.CREATE_ROOM_PARAMS_STR, String::class.java) | ||
.addRealmObjectField(LocalRoomSummaryEntityFields.ROOM_SUMMARY_ENTITY.`$`, realm.schema.get("RoomSummaryEntity")!!) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...id/src/main/java/org/matrix/android/sdk/internal/database/model/LocalRoomSummaryEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.database.model | ||
|
||
import io.realm.RealmObject | ||
import io.realm.annotations.PrimaryKey | ||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams | ||
import org.matrix.android.sdk.api.session.room.model.create.toJSONString | ||
|
||
internal open class LocalRoomSummaryEntity( | ||
@PrimaryKey var roomId: String = "", | ||
var roomSummaryEntity: RoomSummaryEntity? = null, | ||
private var createRoomParamsStr: String? = null | ||
) : RealmObject() { | ||
|
||
var createRoomParams: CreateRoomParams? | ||
get() { | ||
return CreateRoomParams.fromJson(createRoomParamsStr) | ||
} | ||
set(value) { | ||
createRoomParamsStr = value?.toJSONString() | ||
} | ||
|
||
companion object | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...main/java/org/matrix/android/sdk/internal/database/query/LocalRoomSummaryEntityQueries.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.database.query | ||
|
||
import io.realm.Realm | ||
import io.realm.RealmQuery | ||
import io.realm.kotlin.where | ||
import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntity | ||
import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntityFields | ||
|
||
internal fun LocalRoomSummaryEntity.Companion.where(realm: Realm, roomId: String? = null): RealmQuery<LocalRoomSummaryEntity> { | ||
val query = realm.where<LocalRoomSummaryEntity>() | ||
if (roomId != null) { | ||
query.equalTo(LocalRoomSummaryEntityFields.ROOM_ID, roomId) | ||
} | ||
return query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be internal, as well as
LocalRoomThirdPartyInviteContent
(and maybe move this class to the internal package?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2be2a05