Merge branch 'feature/fga/voip_v1_start' into feature/fga/voip_dial_pad

This commit is contained in:
ganfra 2021-01-14 15:10:07 +01:00
commit 55fd983fd3
256 changed files with 2775 additions and 1258 deletions

View File

@ -5,11 +5,17 @@ Features ✨:
- Enable url previews for notices (#2562) - Enable url previews for notices (#2562)
Improvements 🙌: Improvements 🙌:
- - Add System theme option and set as default (#904, #2387)
- Warn user when he is leaving a not public room (#1460)
Bugfix 🐛: Bugfix 🐛:
- Unspecced msgType field in m.sticker (#2580)
- Wait for all room members to be known before sending a message to a e2e room (#2518)
- Url previews sometimes attached to wrong message (#2561) - Url previews sometimes attached to wrong message (#2561)
- Room Topic not displayed correctly after visiting a link (#2551)
- Hiding membership events works the exact opposite (#2603)
- Tapping drawer having more than 1 room in notifications gives "malformed link" error (#2605)
- Initial sync is not retried correctly when there is some network error. (#2632)
Translations 🗣: Translations 🗣:
- -
@ -17,7 +23,7 @@ SDK API changes ⚠️:
- -
Build 🧱: Build 🧱:
- - Remove dependency to org.greenrobot.eventbus library
Test: Test:
- -

View File

@ -40,13 +40,16 @@ import kotlin.math.abs
abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventListener { abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventListener {
lateinit var pager2: ViewPager2 protected val pager2: ViewPager2
lateinit var imageTransitionView: ImageView get() = views.attachmentPager
lateinit var transitionImageContainer: ViewGroup protected val imageTransitionView: ImageView
get() = views.transitionImageView
protected val transitionImageContainer: ViewGroup
get() = views.transitionImageContainer
var topInset = 0 private var topInset = 0
var bottomInset = 0 private var bottomInset = 0
var systemUiVisibility = true private var systemUiVisibility = true
private var overlayView: View? = null private var overlayView: View? = null
set(value) { set(value) {
@ -65,14 +68,16 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
private lateinit var gestureDetector: GestureDetectorCompat private lateinit var gestureDetector: GestureDetectorCompat
var currentPosition = 0 var currentPosition = 0
private set
private var swipeDirection: SwipeDirection? = null private var swipeDirection: SwipeDirection? = null
private fun isScaled() = attachmentsAdapter.isScaled(currentPosition) private fun isScaled() = attachmentsAdapter.isScaled(currentPosition)
private val attachmentsAdapter = AttachmentsAdapter()
private var wasScaled: Boolean = false private var wasScaled: Boolean = false
private var isSwipeToDismissAllowed: Boolean = true private var isSwipeToDismissAllowed: Boolean = true
private lateinit var attachmentsAdapter: AttachmentsAdapter
private var isOverlayWasClicked = false private var isOverlayWasClicked = false
// private val shouldDismissToBottom: Boolean // private val shouldDismissToBottom: Boolean
@ -101,10 +106,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
views = ActivityAttachmentViewerBinding.inflate(layoutInflater) views = ActivityAttachmentViewerBinding.inflate(layoutInflater)
setContentView(views.root) setContentView(views.root)
views.attachmentPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL views.attachmentPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
attachmentsAdapter = AttachmentsAdapter()
views.attachmentPager.adapter = attachmentsAdapter views.attachmentPager.adapter = attachmentsAdapter
imageTransitionView = views.transitionImageView
pager2 = views.attachmentPager
directionDetector = createSwipeDirectionDetector() directionDetector = createSwipeDirectionDetector()
gestureDetector = createGestureDetector() gestureDetector = createGestureDetector()

View File

@ -27,7 +27,6 @@ $ source env/bin/activate
Every time you want to launch these test homeservers, type: Every time you want to launch these test homeservers, type:
```shell script ```shell script
$ virtualenv -p python3 env
$ source env/bin/activate $ source env/bin/activate
(env) $ demo/start.sh --no-rate-limit (env) $ demo/start.sh --no-rate-limit
``` ```

View File

@ -167,9 +167,6 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
// Bus
implementation 'org.greenrobot:eventbus:3.1.1'
// Phone number https://github.com/google/libphonenumber // Phone number https://github.com/google/libphonenumber
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.23' implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.23'

View File

@ -20,14 +20,8 @@
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
# BMA: Not sure I can delete this one without side effect
### EVENT BUS ###
-keepattributes *Annotation* -keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
### MOSHI ### ### MOSHI ###

View File

@ -86,7 +86,7 @@ class CommonTestHelper(context: Context) {
* *
* @param session the session to sync * @param session the session to sync
*/ */
fun syncSession(session: Session) { fun syncSession(session: Session, timeout: Long = TestConstants.timeOutMillis) {
val lock = CountDownLatch(1) val lock = CountDownLatch(1)
val job = GlobalScope.launch(Dispatchers.Main) { val job = GlobalScope.launch(Dispatchers.Main) {
@ -109,7 +109,7 @@ class CommonTestHelper(context: Context) {
} }
GlobalScope.launch(Dispatchers.Main) { syncLiveData.observeForever(syncObserver) } GlobalScope.launch(Dispatchers.Main) { syncLiveData.observeForever(syncObserver) }
await(lock) await(lock, timeout)
} }
/** /**
@ -119,7 +119,7 @@ class CommonTestHelper(context: Context) {
* @param message the message to send * @param message the message to send
* @param nbOfMessages the number of time the message will be sent * @param nbOfMessages the number of time the message will be sent
*/ */
fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<TimelineEvent> { fun sendTextMessage(room: Room, message: String, nbOfMessages: Int, timeout: Long = TestConstants.timeOutMillis): List<TimelineEvent> {
val timeline = room.createTimeline(null, TimelineSettings(10)) val timeline = room.createTimeline(null, TimelineSettings(10))
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages) val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
val latch = CountDownLatch(1) val latch = CountDownLatch(1)
@ -151,7 +151,7 @@ class CommonTestHelper(context: Context) {
room.sendTextMessage(message + " #" + (i + 1)) room.sendTextMessage(message + " #" + (i + 1))
} }
// Wait 3 second more per message // Wait 3 second more per message
await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages) await(latch, timeout = timeout + 3_000L * nbOfMessages)
timeline.dispose() timeline.dispose()
// Check that all events has been created // Check that all events has been created
@ -215,14 +215,14 @@ class CommonTestHelper(context: Context) {
.getLoginFlow(hs, it) .getLoginFlow(hs, it)
} }
doSync<RegistrationResult> { doSync<RegistrationResult>(timeout = 60_000) {
matrix.authenticationService matrix.authenticationService
.getRegistrationWizard() .getRegistrationWizard()
.createAccount(userName, password, null, it) .createAccount(userName, password, null, it)
} }
// Perform dummy step // Perform dummy step
val registrationResult = doSync<RegistrationResult> { val registrationResult = doSync<RegistrationResult>(timeout = 60_000) {
matrix.authenticationService matrix.authenticationService
.getRegistrationWizard() .getRegistrationWizard()
.dummy(it) .dummy(it)
@ -231,7 +231,7 @@ class CommonTestHelper(context: Context) {
assertTrue(registrationResult is RegistrationResult.Success) assertTrue(registrationResult is RegistrationResult.Success)
val session = (registrationResult as RegistrationResult.Success).session val session = (registrationResult as RegistrationResult.Success).session
if (sessionTestParams.withInitialSync) { if (sessionTestParams.withInitialSync) {
syncSession(session) syncSession(session, 60_000)
} }
return session return session

View File

@ -18,14 +18,21 @@ package org.matrix.android.sdk.common
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
data class CryptoTestData(val firstSession: Session, data class CryptoTestData(val roomId: String,
val roomId: String, val sessions: List<Session>) {
val secondSession: Session? = null,
val thirdSession: Session? = null) { val firstSession: Session
get() = sessions.first()
val secondSession: Session?
get() = sessions.getOrNull(1)
val thirdSession: Session?
get() = sessions.getOrNull(2)
fun cleanUp(testHelper: CommonTestHelper) { fun cleanUp(testHelper: CommonTestHelper) {
testHelper.signOutAndClose(firstSession) sessions.forEach {
secondSession?.let { testHelper.signOutAndClose(it) } testHelper.signOutAndClose(it)
thirdSession?.let { testHelper.signOutAndClose(it) } }
} }
} }

View File

@ -73,7 +73,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
} }
} }
return CryptoTestData(aliceSession, roomId) return CryptoTestData(roomId, listOf(aliceSession))
} }
/** /**
@ -139,7 +139,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
// assertNotNull(roomFromBobPOV.powerLevels) // assertNotNull(roomFromBobPOV.powerLevels)
// assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId)) // assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId))
return CryptoTestData(aliceSession, aliceRoomId, bobSession) return CryptoTestData(aliceRoomId, listOf(aliceSession, bobSession))
} }
/** /**
@ -157,7 +157,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
// wait the initial sync // wait the initial sync
SystemClock.sleep(1000) SystemClock.sleep(1000)
return CryptoTestData(aliceSession, aliceRoomId, cryptoTestData.secondSession, samSession) return CryptoTestData(aliceRoomId, listOf(aliceSession, cryptoTestData.secondSession!!, samSession))
} }
/** /**
@ -381,4 +381,30 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
} }
} }
} }
fun doE2ETestWithManyMembers(numberOfMembers: Int): CryptoTestData {
val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams)
aliceSession.cryptoService().setWarnOnUnknownDevices(false)
val roomId = mTestHelper.doSync<String> {
aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, it)
}
val room = aliceSession.getRoom(roomId)!!
mTestHelper.runBlockingTest {
room.enableEncryption()
}
val sessions = mutableListOf(aliceSession)
for (index in 1 until numberOfMembers) {
val session = mTestHelper.createAccount("User_$index", defaultSessionParams)
mTestHelper.doSync<Unit>(timeout = 600_000) { room.invite(session.myUserId, null, it) }
println("TEST -> " + session.myUserId + " invited")
mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) }
println("TEST -> " + session.myUserId + " joined")
sessions.add(session)
}
return CryptoTestData(roomId, sessions)
}
} }

View File

@ -0,0 +1,92 @@
/*
* Copyright 2020 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.session.room.timeline
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.CryptoTestHelper
import java.util.concurrent.CountDownLatch
import kotlin.test.fail
@RunWith(JUnit4::class)
@FixMethodOrder(MethodSorters.JVM)
class TimelineWithManyMembersTest : InstrumentedTest {
companion object {
private const val NUMBER_OF_MEMBERS = 6
}
private val commonTestHelper = CommonTestHelper(context())
private val cryptoTestHelper = CryptoTestHelper(commonTestHelper)
/**
* Ensures when someone sends a message to a crowded room, everyone can decrypt the message.
*/
@Test
fun everyone_should_decrypt_message_in_a_crowded_room() {
val cryptoTestData = cryptoTestHelper.doE2ETestWithManyMembers(NUMBER_OF_MEMBERS)
val sessionForFirstMember = cryptoTestData.firstSession
val roomForFirstMember = sessionForFirstMember.getRoom(cryptoTestData.roomId)!!
val firstMessage = "First messages from Alice"
commonTestHelper.sendTextMessage(
roomForFirstMember,
firstMessage,
1,
600_000
)
for (index in 1 until cryptoTestData.sessions.size) {
val session = cryptoTestData.sessions[index]
val roomForCurrentMember = session.getRoom(cryptoTestData.roomId)!!
val timelineForCurrentMember = roomForCurrentMember.createTimeline(null, TimelineSettings(30))
timelineForCurrentMember.start()
session.startSync(true)
run {
val lock = CountDownLatch(1)
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
snapshot
.find { it.isEncrypted() }
?.let {
val body = it.root.getClearContent()?.toModel<MessageContent>()?.body
if (body?.startsWith(firstMessage).orFalse()) {
println("User " + session.myUserId + " decrypted as " + body)
return@createEventListener true
} else {
fail("User " + session.myUserId + " decrypted as " + body + " CryptoError: " + it.root.mCryptoError)
}
} ?: return@createEventListener false
}
timelineForCurrentMember.addListener(eventsListener)
commonTestHelper.await(lock, 600_000)
}
session.stopSync()
}
}
}

View File

@ -35,7 +35,11 @@ data class MatrixConfiguration(
* Optional proxy to connect to the matrix servers * Optional proxy to connect to the matrix servers
* You can create one using for instance Proxy(proxyType, InetSocketAddress.createUnresolved(hostname, port) * You can create one using for instance Proxy(proxyType, InetSocketAddress.createUnresolved(hostname, port)
*/ */
val proxy: Proxy? = null val proxy: Proxy? = null,
/**
* True to advertise support for call transfers to other parties on Matrix calls.
*/
val supportsCallTransfer: Boolean = false
) { ) {
/** /**

View File

@ -41,6 +41,16 @@ interface AuthenticationService {
*/ */
fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable
/**
* Get a SSO url
*/
fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String?
/**
* Get the sign in or sign up fallback URL
*/
fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String?
/** /**
* Return a LoginWizard, to login to the homeserver. The login flow has to be retrieved first. * Return a LoginWizard, to login to the homeserver. The login flow has to be retrieved first.
*/ */

View File

@ -17,6 +17,7 @@
package org.matrix.android.sdk.api.session.call package org.matrix.android.sdk.api.session.call
import org.matrix.android.sdk.api.session.room.model.call.CallCandidate import org.matrix.android.sdk.api.session.room.model.call.CallCandidate
import org.matrix.android.sdk.api.session.room.model.call.CallCapabilities
import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent
import org.matrix.android.sdk.api.session.room.model.call.SdpType import org.matrix.android.sdk.api.session.room.model.call.SdpType
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
@ -42,6 +43,8 @@ interface MxCall : MxCallDetail {
var opponentPartyId: Optional<String>? var opponentPartyId: Optional<String>?
var opponentVersion: Int var opponentVersion: Int
var capabilities: CallCapabilities?
var state: CallState var state: CallState
/** /**
@ -86,6 +89,11 @@ interface MxCall : MxCallDetail {
*/ */
fun sendLocalIceCandidateRemovals(candidates: List<CallCandidate>) fun sendLocalIceCandidateRemovals(candidates: List<CallCandidate>)
/**
* Send a m.call.replaces event to initiate call transfer.
*/
suspend fun transfer(targetUserId: String, targetRoomId: String?)
fun addListener(listener: StateListener) fun addListener(listener: StateListener)
fun removeListener(listener: StateListener) fun removeListener(listener: StateListener)

View File

@ -72,6 +72,7 @@ object EventType {
const val CALL_NEGOTIATE = "m.call.negotiate" const val CALL_NEGOTIATE = "m.call.negotiate"
const val CALL_REJECT = "m.call.reject" const val CALL_REJECT = "m.call.reject"
const val CALL_HANGUP = "m.call.hangup" const val CALL_HANGUP = "m.call.hangup"
const val CALL_REPLACES = "m.call.replaces"
// Key share events // Key share events
const val ROOM_KEY_REQUEST = "m.room_key_request" const val ROOM_KEY_REQUEST = "m.room_key_request"

View File

@ -25,7 +25,6 @@ interface PermalinkService {
companion object { companion object {
const val MATRIX_TO_URL_BASE = "https://matrix.to/#/" const val MATRIX_TO_URL_BASE = "https://matrix.to/#/"
const val MATRIX_TO_CUSTOM_SCHEME_URL_BASE = "element://"
} }
/** /**

View File

@ -39,7 +39,11 @@ data class CallAnswerContent(
/** /**
* Required. The version of the VoIP specification this messages adheres to. * Required. The version of the VoIP specification this messages adheres to.
*/ */
@Json(name = "version") override val version: String? @Json(name = "version") override val version: String?,
/**
* Capability advertisement.
*/
@Json(name = "capabilities") val capabilities: CallCapabilities? = null
): CallSignallingContent { ): CallSignallingContent {
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -0,0 +1,32 @@
/*
* Copyright 2020 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.api.session.room.model.call
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.extensions.orFalse
@JsonClass(generateAdapter = true)
data class CallCapabilities(
/**
* If set to true, states that the sender of the event supports the m.call.replaces event and therefore supports
* being transferred to another destination
*/
@Json(name = "m.call.transferee") val transferee: Boolean? = null
)
fun CallCapabilities?.supportCallTransfer() = this?.transferee.orFalse()

View File

@ -49,7 +49,11 @@ data class CallInviteContent(
/** /**
* The field should be added for all invites where the target is a specific user * The field should be added for all invites where the target is a specific user
*/ */
@Json(name = "invitee") val invitee: String? = null @Json(name = "invitee") val invitee: String? = null,
/**
* Capability advertisement.
*/
@Json(name = "capabilities") val capabilities: CallCapabilities? = null
): CallSignallingContent { ): CallSignallingContent {
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -0,0 +1,82 @@
/*
* Copyright 2020 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.api.session.room.model.call
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* This event is sent to signal the intent of a participant in a call to replace the call with another,
* such that the other participant ends up in a call with a new user.
*/
@JsonClass(generateAdapter = true)
data class CallReplacesContent(
/**
* Required. The ID of the call this event relates to.
*/
@Json(name = "call_id") override val callId: String,
/**
* Required. ID to let user identify remote echo of their own events
*/
@Json(name = "party_id") override val partyId: String? = null,
/**
* An identifier for the call replacement itself, generated by the transferor.
*/
@Json(name = "replacement_id") val replacementId: String? = null,
/**
* Optional. If specified, the transferee client waits for an invite to this room and joins it
* (possibly waiting for user confirmation) and then continues the transfer in this room.
* If absent, the transferee contacts the Matrix User ID given in the target_user field in a room of its choosing.
*/
@Json(name = "target_room") val targerRoomId: String? = null,
/**
* An object giving information about the transfer target
*/
@Json(name = "target_user") val targetUser: TargetUser? = null,
/**
* If specified, gives the call ID for the transferee's client to use when placing the replacement call.
* Mutually exclusive with await_call
*/
@Json(name = "create_call") val createCall: String? = null,
/**
* If specified, gives the call ID that the transferee's client should wait for.
* Mutually exclusive with create_call.
*/
@Json(name = "await_call") val awaitCall: String? = null,
/**
* Required. The version of the VoIP specification this messages adheres to.
*/
@Json(name = "version") override val version: String?
): CallSignallingContent {
@JsonClass(generateAdapter = true)
data class TargetUser(
/**
* Required. The matrix user ID of the transfer target
*/
@Json(name = "id") val id: String,
/**
* Optional. The display name of the transfer target.
*/
@Json(name = "display_name") val displayName: String?,
/**
* Optional. The avatar URL of the transfer target.
*/
@Json(name = "avatar_url") val avatarUrl: String?
)
}

View File

@ -27,6 +27,7 @@ data class MessageStickerContent(
/** /**
* Set in local, not from server * Set in local, not from server
*/ */
@Transient
override val msgType: String = MessageType.MSGTYPE_STICKER_LOCAL, override val msgType: String = MessageType.MSGTYPE_STICKER_LOCAL,
/** /**

View File

@ -0,0 +1,33 @@
/*
* Copyright 2020 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.api.session.room.state
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
/**
* Return true if a room can be joined by anyone (RoomJoinRules.PUBLIC)
*/
fun StateService.isPublic(): Boolean {
return getStateEvent(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition)
?.content
?.toModel<RoomJoinRulesContent>()
?.joinRules == RoomJoinRules.PUBLIC
}

View File

@ -52,6 +52,8 @@ data class TimelineEvent(
} }
} }
val roomId = root.roomId ?: ""
val metadata = HashMap<String, Any>() val metadata = HashMap<String, Any>()
/** /**

View File

@ -0,0 +1,37 @@
/*
* Copyright 2020 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.api.util
import java.net.URLEncoder
/**
* Append param and value to a Url, using "?" or "&". Value parameter will be encoded
* Return this for chaining purpose
*/
fun StringBuilder.appendParamToUrl(param: String, value: String): StringBuilder {
if (contains("?")) {
append("&")
} else {
append("?")
}
append(param)
append("=")
append(URLEncoder.encode(value, "utf-8"))
return this
}

View File

@ -14,25 +14,25 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.api.auth package org.matrix.android.sdk.internal.auth
/** /**
* Path to use when the client does not supported any or all login flows * Path to use when the client does not supported any or all login flows
* Ref: https://matrix.org/docs/spec/client_server/latest#login-fallback * Ref: https://matrix.org/docs/spec/client_server/latest#login-fallback
*/ */
const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/" internal const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/"
/** /**
* Path to use when the client does not supported any or all registration flows * Path to use when the client does not supported any or all registration flows
* Not documented * Not documented
*/ */
const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/" internal const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/"
/** /**
* Path to use when the client want to connect using SSO * Path to use when the client want to connect using SSO
* Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login * Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login
*/ */
const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect" internal const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect"
const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect" internal const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect"
const val SSO_REDIRECT_URL_PARAM = "redirectUrl" internal const val SSO_REDIRECT_URL_PARAM = "redirectUrl"

View File

@ -34,6 +34,7 @@ import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.api.util.NoOpCancellable import org.matrix.android.sdk.api.util.NoOpCancellable
import org.matrix.android.sdk.api.util.appendParamToUrl
import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse
import org.matrix.android.sdk.internal.auth.data.RiotConfig import org.matrix.android.sdk.internal.auth.data.RiotConfig
@ -99,6 +100,52 @@ internal class DefaultAuthenticationService @Inject constructor(
} }
} }
override fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String? {
val homeServerUrlBase = getHomeServerUrlBase() ?: return null
return buildString {
append(homeServerUrlBase)
if (providerId != null) {
append(MSC2858_SSO_REDIRECT_PATH)
append("/$providerId")
} else {
append(SSO_REDIRECT_PATH)
}
// Set the redirect url
appendParamToUrl(SSO_REDIRECT_URL_PARAM, redirectUrl)
deviceId?.takeIf { it.isNotBlank() }?.let {
// But https://github.com/matrix-org/synapse/issues/5755
appendParamToUrl("device_id", it)
}
}
}
override fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String? {
val homeServerUrlBase = getHomeServerUrlBase() ?: return null
return buildString {
append(homeServerUrlBase)
if (forSignIn) {
append(LOGIN_FALLBACK_PATH)
deviceId?.takeIf { it.isNotBlank() }?.let {
// But https://github.com/matrix-org/synapse/issues/5755
appendParamToUrl("device_id", it)
}
} else {
// For sign up
append(REGISTER_FALLBACK_PATH)
}
}
}
private fun getHomeServerUrlBase(): String? {
return pendingSessionData
?.homeServerConnectionConfig
?.homeServerUri
?.toString()
?.trim { it == '/' }
}
override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable { override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable {
pendingSessionData = null pendingSessionData = null

View File

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
@ -60,7 +59,6 @@ internal class CancelGossipRequestWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore @Inject lateinit var cryptoStore: IMXCryptoStore
@Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials @Inject lateinit var credentials: Credentials
override fun injectWith(injector: SessionComponent) { override fun injectWith(injector: SessionComponent) {

View File

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
@ -52,7 +51,6 @@ internal class SendGossipRequestWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore @Inject lateinit var cryptoStore: IMXCryptoStore
@Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials @Inject lateinit var credentials: Credentials
override fun injectWith(injector: SessionComponent) { override fun injectWith(injector: SessionComponent) {

View File

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
@ -54,7 +53,6 @@ internal class SendGossipWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask @Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore @Inject lateinit var cryptoStore: IMXCryptoStore
@Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials @Inject lateinit var credentials: Credentials
@Inject lateinit var messageEncrypter: MessageEncrypter @Inject lateinit var messageEncrypter: MessageEncrypter
@Inject lateinit var ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction @Inject lateinit var ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction

View File

@ -19,20 +19,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersion import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersion
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface CreateKeysBackupVersionTask : Task<CreateKeysBackupVersionBody, KeysVersion> internal interface CreateKeysBackupVersionTask : Task<CreateKeysBackupVersionBody, KeysVersion>
internal class DefaultCreateKeysBackupVersionTask @Inject constructor( internal class DefaultCreateKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : CreateKeysBackupVersionTask { ) : CreateKeysBackupVersionTask {
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion { override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.createKeysBackupVersion(params) apiCall = roomKeysApi.createKeysBackupVersion(params)
} }
} }

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> { internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
@ -30,11 +30,11 @@ internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
internal class DefaultDeleteBackupTask @Inject constructor( internal class DefaultDeleteBackupTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteBackupTask { ) : DeleteBackupTask {
override suspend fun execute(params: DeleteBackupTask.Params) { override suspend fun execute(params: DeleteBackupTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.deleteBackup(params.version) apiCall = roomKeysApi.deleteBackup(params.version)
} }
} }

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Params, Unit> { internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Params, Unit> {
@ -32,11 +32,11 @@ internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Pa
internal class DefaultDeleteRoomSessionDataTask @Inject constructor( internal class DefaultDeleteRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteRoomSessionDataTask { ) : DeleteRoomSessionDataTask {
override suspend fun execute(params: DeleteRoomSessionDataTask.Params) { override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.deleteRoomSessionData( apiCall = roomKeysApi.deleteRoomSessionData(
params.roomId, params.roomId,
params.sessionId, params.sessionId,

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.Params, Unit> { internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.Params, Unit> {
@ -31,11 +31,11 @@ internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor( internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteRoomSessionsDataTask { ) : DeleteRoomSessionsDataTask {
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) { override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.deleteRoomSessionsData( apiCall = roomKeysApi.deleteRoomSessionsData(
params.roomId, params.roomId,
params.version) params.version)

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params, Unit> { internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params, Unit> {
@ -30,11 +30,11 @@ internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params,
internal class DefaultDeleteSessionsDataTask @Inject constructor( internal class DefaultDeleteSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteSessionsDataTask { ) : DeleteSessionsDataTask {
override suspend fun execute(params: DeleteSessionsDataTask.Params) { override suspend fun execute(params: DeleteSessionsDataTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.deleteSessionsData(params.version) apiCall = roomKeysApi.deleteSessionsData(params.version)
} }
} }

View File

@ -18,20 +18,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult> internal interface GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult>
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor( internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetKeysBackupLastVersionTask { ) : GetKeysBackupLastVersionTask {
override suspend fun execute(params: Unit): KeysVersionResult { override suspend fun execute(params: Unit): KeysVersionResult {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getKeysBackupLastVersion() apiCall = roomKeysApi.getKeysBackupLastVersion()
} }
} }

View File

@ -18,20 +18,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeysBackupVersionTask : Task<String, KeysVersionResult> internal interface GetKeysBackupVersionTask : Task<String, KeysVersionResult>
internal class DefaultGetKeysBackupVersionTask @Inject constructor( internal class DefaultGetKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetKeysBackupVersionTask { ) : GetKeysBackupVersionTask {
override suspend fun execute(params: String): KeysVersionResult { override suspend fun execute(params: String): KeysVersionResult {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getKeysBackupVersion(params) apiCall = roomKeysApi.getKeysBackupVersion(params)
} }
} }

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params, KeyBackupData> { internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params, KeyBackupData> {
@ -33,11 +33,11 @@ internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params,
internal class DefaultGetRoomSessionDataTask @Inject constructor( internal class DefaultGetRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetRoomSessionDataTask { ) : GetRoomSessionDataTask {
override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData { override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getRoomSessionData( apiCall = roomKeysApi.getRoomSessionData(
params.roomId, params.roomId,
params.sessionId, params.sessionId,

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params, RoomKeysBackupData> { internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params, RoomKeysBackupData> {
@ -32,11 +32,11 @@ internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params
internal class DefaultGetRoomSessionsDataTask @Inject constructor( internal class DefaultGetRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetRoomSessionsDataTask { ) : GetRoomSessionsDataTask {
override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData { override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getRoomSessionsData( apiCall = roomKeysApi.getRoomSessionsData(
params.roomId, params.roomId,
params.version) params.version)

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBackupData> { internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBackupData> {
@ -31,11 +31,11 @@ internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBa
internal class DefaultGetSessionsDataTask @Inject constructor( internal class DefaultGetSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetSessionsDataTask { ) : GetSessionsDataTask {
override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData { override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getSessionsData(params.version) apiCall = roomKeysApi.getSessionsData(params.version)
} }
} }

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Params, BackupKeysResult> { internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Params, BackupKeysResult> {
@ -35,11 +35,11 @@ internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Para
internal class DefaultStoreRoomSessionDataTask @Inject constructor( internal class DefaultStoreRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : StoreRoomSessionDataTask { ) : StoreRoomSessionDataTask {
override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.storeRoomSessionData( apiCall = roomKeysApi.storeRoomSessionData(
params.roomId, params.roomId,
params.sessionId, params.sessionId,

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Params, BackupKeysResult> { internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Params, BackupKeysResult> {
@ -34,11 +34,11 @@ internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Pa
internal class DefaultStoreRoomSessionsDataTask @Inject constructor( internal class DefaultStoreRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : StoreRoomSessionsDataTask { ) : StoreRoomSessionsDataTask {
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.storeRoomSessionsData( apiCall = roomKeysApi.storeRoomSessionsData(
params.roomId, params.roomId,
params.version, params.version,

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, BackupKeysResult> { internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, BackupKeysResult> {
@ -33,11 +33,11 @@ internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, Ba
internal class DefaultStoreSessionsDataTask @Inject constructor( internal class DefaultStoreSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : StoreSessionsDataTask { ) : StoreSessionsDataTask {
override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.storeSessionsData( apiCall = roomKeysApi.storeSessionsData(
params.version, params.version,
params.keysBackupData) params.keysBackupData)

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTask.Params, Unit> { internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTask.Params, Unit> {
@ -32,11 +32,11 @@ internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTas
internal class DefaultUpdateKeysBackupVersionTask @Inject constructor( internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi, private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UpdateKeysBackupVersionTask { ) : UpdateKeysBackupVersionTask {
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) { override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody) apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody)
} }
} }

View File

@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.model.MXKey
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimBody import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimResponse import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -36,13 +36,13 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysFor
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor( internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : ClaimOneTimeKeysForUsersDeviceTask { ) : ClaimOneTimeKeysForUsersDeviceTask {
override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap<MXKey> { override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap<MXKey> {
val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map) val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map)
val keysClaimResponse = executeRequest<KeysClaimResponse>(eventBus) { val keysClaimResponse = executeRequest<KeysClaimResponse>(globalErrorReceiver) {
apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body) apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body)
} }
val map = MXUsersDevicesMap<MXKey>() val map = MXUsersDevicesMap<MXKey>()

View File

@ -20,9 +20,9 @@ import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> { internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
@ -33,12 +33,12 @@ internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
internal class DefaultDeleteDeviceTask @Inject constructor( internal class DefaultDeleteDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteDeviceTask { ) : DeleteDeviceTask {
override suspend fun execute(params: DeleteDeviceTask.Params) { override suspend fun execute(params: DeleteDeviceTask.Params) {
try { try {
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()) apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams())
} }
} catch (throwable: Throwable) { } catch (throwable: Throwable) {

View File

@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserPasswordTask.Params, Unit> { internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserPasswordTask.Params, Unit> {
@ -37,11 +37,11 @@ internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserP
internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor( internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
@UserId private val userId: String, @UserId private val userId: String,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteDeviceWithUserPasswordTask { ) : DeleteDeviceWithUserPasswordTask {
override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) { override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.deleteDevice(params.deviceId, apiCall = cryptoApi.deleteDevice(params.deviceId,
DeleteDeviceParams( DeleteDeviceParams(
userPasswordAuth = UserPasswordAuth( userPasswordAuth = UserPasswordAuth(

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryBody import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> { internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> {
@ -35,7 +35,7 @@ internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Para
internal class DefaultDownloadKeysForUsers @Inject constructor( internal class DefaultDownloadKeysForUsers @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DownloadKeysForUsersTask { ) : DownloadKeysForUsersTask {
override suspend fun execute(params: DownloadKeysForUsersTask.Params): KeysQueryResponse { override suspend fun execute(params: DownloadKeysForUsersTask.Params): KeysQueryResponse {
@ -46,7 +46,7 @@ internal class DefaultDownloadKeysForUsers @Inject constructor(
token = params.token?.takeIf { it.isNotEmpty() } token = params.token?.takeIf { it.isNotEmpty() }
) )
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.downloadKeysForUsers(body) apiCall = cryptoApi.downloadKeysForUsers(body)
} }
} }

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo> { internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo> {
@ -29,11 +29,11 @@ internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo
internal class DefaultGetDeviceInfoTask @Inject constructor( internal class DefaultGetDeviceInfoTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetDeviceInfoTask { ) : GetDeviceInfoTask {
override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo { override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.getDeviceInfo(params.deviceId) apiCall = cryptoApi.getDeviceInfo(params.deviceId)
} }
} }

View File

@ -18,20 +18,20 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DevicesListResponse import org.matrix.android.sdk.internal.crypto.model.rest.DevicesListResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetDevicesTask : Task<Unit, DevicesListResponse> internal interface GetDevicesTask : Task<Unit, DevicesListResponse>
internal class DefaultGetDevicesTask @Inject constructor( internal class DefaultGetDevicesTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetDevicesTask { ) : GetDevicesTask {
override suspend fun execute(params: Unit): DevicesListResponse { override suspend fun execute(params: Unit): DevicesListResponse {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.getDevices() apiCall = cryptoApi.getDevices()
} }
} }

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.KeyChangesResponse import org.matrix.android.sdk.internal.crypto.model.rest.KeyChangesResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChangesResponse> { internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChangesResponse> {
@ -34,11 +34,11 @@ internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChanges
internal class DefaultGetKeyChangesTask @Inject constructor( internal class DefaultGetKeyChangesTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetKeyChangesTask { ) : GetKeyChangesTask {
override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse { override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.getKeyChanges(params.from, params.to) apiCall = cryptoApi.getKeyChanges(params.from, params.to)
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package org.matrix.android.sdk.internal.crypto.tasks package org.matrix.android.sdk.internal.crypto.tasks
import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest 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.RoomAPI
import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.session.room.send.SendResponse
@ -33,10 +33,10 @@ internal interface RedactEventTask : Task<RedactEventTask.Params, String> {
internal class DefaultRedactEventTask @Inject constructor( internal class DefaultRedactEventTask @Inject constructor(
private val roomAPI: RoomAPI, private val roomAPI: RoomAPI,
private val eventBus: EventBus) : RedactEventTask { private val globalErrorReceiver: GlobalErrorReceiver) : RedactEventTask {
override suspend fun execute(params: RedactEventTask.Params): String { override suspend fun execute(params: RedactEventTask.Params): String {
val executeRequest = executeRequest<SendResponse>(eventBus) { val executeRequest = executeRequest<SendResponse>(globalErrorReceiver) {
apiCall = roomAPI.redactEvent( apiCall = roomAPI.redactEvent(
txId = params.txID, txId = params.txID,
roomId = params.roomId, roomId = params.roomId,

View File

@ -15,11 +15,12 @@
*/ */
package org.matrix.android.sdk.internal.crypto.tasks package org.matrix.android.sdk.internal.crypto.tasks
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.send.SendState 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.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.RoomAPI
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.session.room.send.LocalEchoRepository
import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.session.room.send.SendResponse
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
@ -35,16 +36,24 @@ internal interface SendEventTask : Task<SendEventTask.Params, String> {
internal class DefaultSendEventTask @Inject constructor( internal class DefaultSendEventTask @Inject constructor(
private val localEchoRepository: LocalEchoRepository, private val localEchoRepository: LocalEchoRepository,
private val encryptEventTask: DefaultEncryptEventTask, private val encryptEventTask: DefaultEncryptEventTask,
private val loadRoomMembersTask: LoadRoomMembersTask,
private val roomAPI: RoomAPI, private val roomAPI: RoomAPI,
private val eventBus: EventBus) : SendEventTask { private val globalErrorReceiver: GlobalErrorReceiver) : SendEventTask {
override suspend fun execute(params: SendEventTask.Params): String { override suspend fun execute(params: SendEventTask.Params): String {
try { try {
// Make sure to load all members in the room before sending the event.
params.event.roomId
?.takeIf { params.encrypt }
?.let { roomId ->
loadRoomMembersTask.execute(LoadRoomMembersTask.Params(roomId))
}
val event = handleEncryption(params) val event = handleEncryption(params)
val localId = event.eventId!! val localId = event.eventId!!
localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENDING) localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENDING)
val executeRequest = executeRequest<SendResponse>(eventBus) { val executeRequest = executeRequest<SendResponse>(globalErrorReceiver) {
apiCall = roomAPI.send( apiCall = roomAPI.send(
localId, localId,
roomId = event.roomId ?: "", roomId = event.roomId ?: "",

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.rest.SendToDeviceBody import org.matrix.android.sdk.internal.crypto.model.rest.SendToDeviceBody
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
import kotlin.random.Random import kotlin.random.Random
@ -38,7 +38,7 @@ internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
internal class DefaultSendToDeviceTask @Inject constructor( internal class DefaultSendToDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : SendToDeviceTask { ) : SendToDeviceTask {
override suspend fun execute(params: SendToDeviceTask.Params) { override suspend fun execute(params: SendToDeviceTask.Params) {
@ -46,7 +46,7 @@ internal class DefaultSendToDeviceTask @Inject constructor(
messages = params.contentMap.map messages = params.contentMap.map
) )
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.sendToDevice( apiCall = cryptoApi.sendToDevice(
params.eventType, params.eventType,
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(), params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(),

View File

@ -15,10 +15,10 @@
*/ */
package org.matrix.android.sdk.internal.crypto.tasks package org.matrix.android.sdk.internal.crypto.tasks
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.internal.crypto.CryptoSessionInfoProvider import org.matrix.android.sdk.internal.crypto.CryptoSessionInfoProvider
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest 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.RoomAPI
import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository
@ -37,7 +37,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor(
private val encryptEventTask: DefaultEncryptEventTask, private val encryptEventTask: DefaultEncryptEventTask,
private val roomAPI: RoomAPI, private val roomAPI: RoomAPI,
private val cryptoSessionInfoProvider: CryptoSessionInfoProvider, private val cryptoSessionInfoProvider: CryptoSessionInfoProvider,
private val eventBus: EventBus) : SendVerificationMessageTask { private val globalErrorReceiver: GlobalErrorReceiver) : SendVerificationMessageTask {
override suspend fun execute(params: SendVerificationMessageTask.Params): String { override suspend fun execute(params: SendVerificationMessageTask.Params): String {
val event = handleEncryption(params) val event = handleEncryption(params)
@ -45,7 +45,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor(
try { try {
localEchoRepository.updateSendState(localId, event.roomId, SendState.SENDING) localEchoRepository.updateSendState(localId, event.roomId, SendState.SENDING)
val executeRequest = executeRequest<SendResponse>(eventBus) { val executeRequest = executeRequest<SendResponse>(globalErrorReceiver) {
apiCall = roomAPI.send( apiCall = roomAPI.send(
localId, localId,
roomId = event.roomId ?: "", roomId = event.roomId ?: "",

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.UpdateDeviceInfoBody import org.matrix.android.sdk.internal.crypto.model.rest.UpdateDeviceInfoBody
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> { internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
@ -34,14 +34,14 @@ internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
internal class DefaultSetDeviceNameTask @Inject constructor( internal class DefaultSetDeviceNameTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : SetDeviceNameTask { ) : SetDeviceNameTask {
override suspend fun execute(params: SetDeviceNameTask.Params) { override suspend fun execute(params: SetDeviceNameTask.Params) {
val body = UpdateDeviceInfoBody( val body = UpdateDeviceInfoBody(
displayName = params.deviceName displayName = params.deviceName
) )
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body) apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body)
} }
} }

View File

@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeys import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeys
import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadBody import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadResponse import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -38,7 +38,7 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
internal class DefaultUploadKeysTask @Inject constructor( internal class DefaultUploadKeysTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UploadKeysTask { ) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse { override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
@ -49,7 +49,7 @@ internal class DefaultUploadKeysTask @Inject constructor(
Timber.i("## Uploading device keys -> $body") Timber.i("## Uploading device keys -> $body")
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.uploadKeys(body) apiCall = cryptoApi.uploadKeys(body)
} }
} }

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UploadSignaturesTask : Task<UploadSignaturesTask.Params, Unit> { internal interface UploadSignaturesTask : Task<UploadSignaturesTask.Params, Unit> {
@ -31,12 +31,12 @@ internal interface UploadSignaturesTask : Task<UploadSignaturesTask.Params, Unit
internal class DefaultUploadSignaturesTask @Inject constructor( internal class DefaultUploadSignaturesTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UploadSignaturesTask { ) : UploadSignaturesTask {
override suspend fun execute(params: UploadSignaturesTask.Params) { override suspend fun execute(params: UploadSignaturesTask.Params) {
try { try {
val response = executeRequest<SignatureUploadResponse>(eventBus) { val response = executeRequest<SignatureUploadResponse>(globalErrorReceiver) {
this.isRetryable = true this.isRetryable = true
this.maxRetryCount = 10 this.maxRetryCount = 10
this.apiCall = cryptoApi.uploadSignatures(params.signatures) this.apiCall = cryptoApi.uploadSignatures(params.signatures)

View File

@ -25,9 +25,9 @@ import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody
import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth
import org.matrix.android.sdk.internal.crypto.model.toRest import org.matrix.android.sdk.internal.crypto.model.toRest
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UploadSigningKeysTask : Task<UploadSigningKeysTask.Params, Unit> { internal interface UploadSigningKeysTask : Task<UploadSigningKeysTask.Params, Unit> {
@ -55,7 +55,7 @@ data class UploadSigningKeys(val failures: Map<String, Any>?) : Failure.FeatureF
internal class DefaultUploadSigningKeysTask @Inject constructor( internal class DefaultUploadSigningKeysTask @Inject constructor(
private val cryptoApi: CryptoApi, private val cryptoApi: CryptoApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UploadSigningKeysTask { ) : UploadSigningKeysTask {
override suspend fun execute(params: UploadSigningKeysTask.Params) { override suspend fun execute(params: UploadSigningKeysTask.Params) {
@ -87,7 +87,7 @@ internal class DefaultUploadSigningKeysTask @Inject constructor(
} }
private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) { private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) {
val keysQueryResponse = executeRequest<KeysQueryResponse>(eventBus) { val keysQueryResponse = executeRequest<KeysQueryResponse>(globalErrorReceiver) {
apiCall = cryptoApi.uploadSigningKeys(uploadQuery) apiCall = cryptoApi.uploadSigningKeys(uploadQuery)
} }
if (keysQueryResponse.failures?.isNotEmpty() == true) { if (keysQueryResponse.failures?.isNotEmpty() == true) {

View File

@ -21,6 +21,8 @@ import io.realm.RealmMigration
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields
import org.matrix.android.sdk.internal.database.model.RoomEntityFields
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -28,7 +30,7 @@ import javax.inject.Inject
class RealmSessionStoreMigration @Inject constructor() : RealmMigration { class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
companion object { companion object {
const val SESSION_STORE_SCHEMA_VERSION = 6L const val SESSION_STORE_SCHEMA_VERSION = 7L
} }
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
@ -40,6 +42,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
if (oldVersion <= 3) migrateTo4(realm) if (oldVersion <= 3) migrateTo4(realm)
if (oldVersion <= 4) migrateTo5(realm) if (oldVersion <= 4) migrateTo5(realm)
if (oldVersion <= 5) migrateTo6(realm) if (oldVersion <= 5) migrateTo6(realm)
if (oldVersion <= 6) migrateTo7(realm)
} }
private fun migrateTo1(realm: DynamicRealm) { private fun migrateTo1(realm: DynamicRealm) {
@ -105,4 +108,18 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
.addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java) .addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java)
.addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java) .addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java)
} }
private fun migrateTo7(realm: DynamicRealm) {
Timber.d("Step 6 -> 7")
realm.schema.get("RoomEntity")
?.addField(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, String::class.java)
?.transform { obj ->
if (obj.getBoolean("areAllMembersLoaded")) {
obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.LOADED.name)
} else {
obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.NONE.name)
}
}
?.removeField("areAllMembersLoaded")
}
} }

View File

@ -23,8 +23,7 @@ import io.realm.annotations.PrimaryKey
internal open class RoomEntity(@PrimaryKey var roomId: String = "", internal open class RoomEntity(@PrimaryKey var roomId: String = "",
var chunks: RealmList<ChunkEntity> = RealmList(), var chunks: RealmList<ChunkEntity> = RealmList(),
var sendingTimelineEvents: RealmList<TimelineEventEntity> = RealmList(), var sendingTimelineEvents: RealmList<TimelineEventEntity> = RealmList()
var areAllMembersLoaded: Boolean = false
) : RealmObject() { ) : RealmObject() {
private var membershipStr: String = Membership.NONE.name private var membershipStr: String = Membership.NONE.name
@ -36,5 +35,14 @@ internal open class RoomEntity(@PrimaryKey var roomId: String = "",
membershipStr = value.name membershipStr = value.name
} }
private var membersLoadStatusStr: String = RoomMembersLoadStatusType.NONE.name
var membersLoadStatus: RoomMembersLoadStatusType
get() {
return RoomMembersLoadStatusType.valueOf(membersLoadStatusStr)
}
set(value) {
membersLoadStatusStr = value.name
}
companion object companion object
} }

View File

@ -14,18 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package org.matrix.android.sdk.internal.eventbus package org.matrix.android.sdk.internal.database.model
import org.greenrobot.eventbus.Logger internal enum class RoomMembersLoadStatusType {
import timber.log.Timber NONE,
import java.util.logging.Level LOADING,
LOADED
class EventBusTimberLogger : Logger {
override fun log(level: Level, msg: String) {
Timber.d(msg)
}
override fun log(level: Level, msg: String, th: Throwable) {
Timber.e(th, msg)
}
} }

View File

@ -0,0 +1,54 @@
/*
* Copyright 2021 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.network
import org.matrix.android.sdk.api.failure.GlobalError
import org.matrix.android.sdk.internal.auth.SessionParamsStore
import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.session.SessionScope
import org.matrix.android.sdk.internal.task.TaskExecutor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@SessionScope
internal class GlobalErrorHandler @Inject constructor(
private val taskExecutor: TaskExecutor,
private val sessionParamsStore: SessionParamsStore,
@SessionId private val sessionId: String
) : GlobalErrorReceiver {
var listener: Listener? = null
override fun handleGlobalError(globalError: GlobalError) {
Timber.e("Global error received: $globalError")
if (globalError is GlobalError.InvalidToken && globalError.softLogout) {
// Mark the token has invalid
taskExecutor.executorScope.launch(Dispatchers.IO) {
sessionParamsStore.setTokenInvalid(sessionId)
}
}
listener?.onGlobalError(globalError)
}
internal interface Listener {
fun onGlobalError(globalError: GlobalError)
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright 2021 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.network
import org.matrix.android.sdk.api.failure.GlobalError
internal interface GlobalErrorReceiver {
fun handleGlobalError(globalError: GlobalError)
}

View File

@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.network
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.internal.network.ssl.CertUtil import org.matrix.android.sdk.internal.network.ssl.CertUtil
@ -27,10 +26,10 @@ import retrofit2.awaitResponse
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
internal suspend inline fun <DATA : Any> executeRequest(eventBus: EventBus?, internal suspend inline fun <DATA : Any> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
block: Request<DATA>.() -> Unit) = Request<DATA>(eventBus).apply(block).execute() block: Request<DATA>.() -> Unit) = Request<DATA>(globalErrorReceiver).apply(block).execute()
internal class Request<DATA : Any>(private val eventBus: EventBus?) { internal class Request<DATA : Any>(private val globalErrorReceiver: GlobalErrorReceiver?) {
var isRetryable = false var isRetryable = false
var initialDelay: Long = 100L var initialDelay: Long = 100L
@ -47,7 +46,7 @@ internal class Request<DATA : Any>(private val eventBus: EventBus?) {
response.body() response.body()
?: throw IllegalStateException("The request returned a null body") ?: throw IllegalStateException("The request returned a null body")
} else { } else {
throw response.toFailure(eventBus) throw response.toFailure(globalErrorReceiver)
} }
} catch (exception: Throwable) { } catch (exception: Throwable) {
// Log some details about the request which has failed // Log some details about the request which has failed

View File

@ -25,7 +25,6 @@ import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.MoshiProvider
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.ResponseBody import okhttp3.ResponseBody
import org.greenrobot.eventbus.EventBus
import retrofit2.Response import retrofit2.Response
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
@ -54,18 +53,18 @@ internal suspend fun okhttp3.Call.awaitResponse(): okhttp3.Response {
/** /**
* Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError * Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/ */
internal fun <T> Response<T>.toFailure(eventBus: EventBus?): Failure { internal fun <T> Response<T>.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure {
return toFailure(errorBody(), code(), eventBus) return toFailure(errorBody(), code(), globalErrorReceiver)
} }
/** /**
* Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError * Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/ */
internal fun okhttp3.Response.toFailure(eventBus: EventBus?): Failure { internal fun okhttp3.Response.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure {
return toFailure(body, code, eventBus) return toFailure(body, code, globalErrorReceiver)
} }
private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBus?): Failure { private fun toFailure(errorBody: ResponseBody?, httpCode: Int, globalErrorReceiver: GlobalErrorReceiver?): Failure {
if (errorBody == null) { if (errorBody == null) {
return Failure.Unknown(RuntimeException("errorBody should not be null")) return Failure.Unknown(RuntimeException("errorBody should not be null"))
} }
@ -79,12 +78,12 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBu
if (matrixError != null) { if (matrixError != null) {
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) { if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
// Also send this error to the bus, for a global management // Also send this error to the globalErrorReceiver, for a global management
eventBus?.post(GlobalError.ConsentNotGivenError(matrixError.consentUri)) globalErrorReceiver?.handleGlobalError(GlobalError.ConsentNotGivenError(matrixError.consentUri))
} else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */ } else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) { && matrixError.code == MatrixError.M_UNKNOWN_TOKEN) {
// Also send this error to the bus, for a global management // Also send this error to the globalErrorReceiver, for a global management
eventBus?.post(GlobalError.InvalidToken(matrixError.isSoftLogout)) globalErrorReceiver?.handleGlobalError(GlobalError.InvalidToken(matrixError.isSoftLogout))
} }
return Failure.ServerError(matrixError, httpCode) return Failure.ServerError(matrixError, httpCode)

View File

@ -19,12 +19,7 @@ package org.matrix.android.sdk.internal.session
import androidx.annotation.MainThread import androidx.annotation.MainThread
import dagger.Lazy import dagger.Lazy
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.failure.GlobalError import org.matrix.android.sdk.api.failure.GlobalError
@ -66,13 +61,12 @@ import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.network.GlobalErrorHandler
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
import org.matrix.android.sdk.internal.session.sync.job.SyncThread import org.matrix.android.sdk.internal.session.sync.job.SyncThread
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.util.createUIHandler import org.matrix.android.sdk.internal.util.createUIHandler
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -82,7 +76,7 @@ import javax.inject.Provider
internal class DefaultSession @Inject constructor( internal class DefaultSession @Inject constructor(
override val sessionParams: SessionParams, override val sessionParams: SessionParams,
private val workManagerProvider: WorkManagerProvider, private val workManagerProvider: WorkManagerProvider,
private val eventBus: EventBus, private val globalErrorHandler: GlobalErrorHandler,
@SessionId @SessionId
override val sessionId: String, override val sessionId: String,
@SessionDatabase private val realmConfiguration: RealmConfiguration, @SessionDatabase private val realmConfiguration: RealmConfiguration,
@ -118,11 +112,9 @@ internal class DefaultSession @Inject constructor(
private val accountDataService: Lazy<AccountDataService>, private val accountDataService: Lazy<AccountDataService>,
private val _sharedSecretStorageService: Lazy<SharedSecretStorageService>, private val _sharedSecretStorageService: Lazy<SharedSecretStorageService>,
private val accountService: Lazy<AccountService>, private val accountService: Lazy<AccountService>,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val defaultIdentityService: DefaultIdentityService, private val defaultIdentityService: DefaultIdentityService,
private val integrationManagerService: IntegrationManagerService, private val integrationManagerService: IntegrationManagerService,
private val thirdPartyService: ThirdPartyService, private val thirdPartyService: ThirdPartyService,
private val taskExecutor: TaskExecutor,
private val callSignalingService: Lazy<CallSignalingService>, private val callSignalingService: Lazy<CallSignalingService>,
@UnauthenticatedWithCertificate @UnauthenticatedWithCertificate
private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>, private val unauthenticatedWithCertificateOkHttpClient: Lazy<OkHttpClient>,
@ -143,7 +135,8 @@ internal class DefaultSession @Inject constructor(
ProfileService by profileService.get(), ProfileService by profileService.get(),
AccountDataService by accountDataService.get(), AccountDataService by accountDataService.get(),
AccountService by accountService.get(), AccountService by accountService.get(),
ThirdPartyService by thirdPartyService { ThirdPartyService by thirdPartyService,
GlobalErrorHandler.Listener {
override val sharedSecretStorageService: SharedSecretStorageService override val sharedSecretStorageService: SharedSecretStorageService
get() = _sharedSecretStorageService.get() get() = _sharedSecretStorageService.get()
@ -165,7 +158,7 @@ internal class DefaultSession @Inject constructor(
uiHandler.post { uiHandler.post {
lifecycleObservers.forEach { it.onStart() } lifecycleObservers.forEach { it.onStart() }
} }
eventBus.register(this) globalErrorHandler.listener = this
eventSenderProcessor.start() eventSenderProcessor.start()
} }
@ -209,7 +202,7 @@ internal class DefaultSession @Inject constructor(
} }
cryptoService.get().close() cryptoService.get().close()
isOpen = false isOpen = false
eventBus.unregister(this) globalErrorHandler.listener = null
eventSenderProcessor.interrupt() eventSenderProcessor.interrupt()
} }
@ -237,16 +230,7 @@ internal class DefaultSession @Inject constructor(
workManagerProvider.cancelAllWorks() workManagerProvider.cancelAllWorks()
} }
@Subscribe(threadMode = ThreadMode.MAIN) override fun onGlobalError(globalError: GlobalError) {
fun onGlobalError(globalError: GlobalError) {
if (globalError is GlobalError.InvalidToken
&& globalError.softLogout) {
// Mark the token has invalid
taskExecutor.executorScope.launch(Dispatchers.IO) {
sessionParamsStore.setTokenInvalid(sessionId)
}
}
sessionListeners.dispatchGlobalError(globalError) sessionListeners.dispatchGlobalError(globalError)
} }

View File

@ -26,7 +26,6 @@ import dagger.Provides
import dagger.multibindings.IntoSet import dagger.multibindings.IntoSet
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
@ -61,9 +60,10 @@ import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificateWithProgress import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificateWithProgress
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.di.UserMd5 import org.matrix.android.sdk.internal.di.UserMd5
import org.matrix.android.sdk.internal.eventbus.EventBusTimberLogger
import org.matrix.android.sdk.internal.network.DefaultNetworkConnectivityChecker import org.matrix.android.sdk.internal.network.DefaultNetworkConnectivityChecker
import org.matrix.android.sdk.internal.network.FallbackNetworkCallbackStrategy import org.matrix.android.sdk.internal.network.FallbackNetworkCallbackStrategy
import org.matrix.android.sdk.internal.network.GlobalErrorHandler
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.NetworkCallbackStrategy import org.matrix.android.sdk.internal.network.NetworkCallbackStrategy
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
import org.matrix.android.sdk.internal.network.PreferredNetworkCallbackStrategy import org.matrix.android.sdk.internal.network.PreferredNetworkCallbackStrategy
@ -256,16 +256,6 @@ internal abstract class SessionModule {
.create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString()) .create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString())
} }
@JvmStatic
@Provides
@SessionScope
fun providesEventBus(): EventBus {
return EventBus
.builder()
.logger(EventBusTimberLogger())
.build()
}
@JvmStatic @JvmStatic
@Provides @Provides
@SessionScope @SessionScope
@ -294,6 +284,9 @@ internal abstract class SessionModule {
@Binds @Binds
abstract fun bindSession(session: DefaultSession): Session abstract fun bindSession(session: DefaultSession): Session
@Binds
abstract fun bindGlobalErrorReceiver(handler: GlobalErrorHandler): GlobalErrorReceiver
@Binds @Binds
abstract fun bindNetworkConnectivityChecker(checker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker abstract fun bindNetworkConnectivityChecker(checker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.account
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface ChangePasswordTask : Task<ChangePasswordTask.Params, Unit> { internal interface ChangePasswordTask : Task<ChangePasswordTask.Params, Unit> {
@ -32,14 +32,14 @@ internal interface ChangePasswordTask : Task<ChangePasswordTask.Params, Unit> {
internal class DefaultChangePasswordTask @Inject constructor( internal class DefaultChangePasswordTask @Inject constructor(
private val accountAPI: AccountAPI, private val accountAPI: AccountAPI,
private val eventBus: EventBus, private val globalErrorReceiver: GlobalErrorReceiver,
@UserId private val userId: String @UserId private val userId: String
) : ChangePasswordTask { ) : ChangePasswordTask {
override suspend fun execute(params: ChangePasswordTask.Params) { override suspend fun execute(params: ChangePasswordTask.Params) {
val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword) val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword)
try { try {
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = accountAPI.changePassword(changePasswordParams) apiCall = accountAPI.changePassword(changePasswordParams)
} }
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
@ -49,7 +49,7 @@ internal class DefaultChangePasswordTask @Inject constructor(
/* Avoid infinite loop */ /* Avoid infinite loop */
&& changePasswordParams.auth?.session == null) { && changePasswordParams.auth?.session == null) {
// Retry with authentication // Retry with authentication
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = accountAPI.changePassword( apiCall = accountAPI.changePassword(
changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session)) changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session))
) )

View File

@ -17,11 +17,11 @@
package org.matrix.android.sdk.internal.session.account package org.matrix.android.sdk.internal.session.account
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.cleanup.CleanupSession import org.matrix.android.sdk.internal.session.cleanup.CleanupSession
import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -34,7 +34,7 @@ internal interface DeactivateAccountTask : Task<DeactivateAccountTask.Params, Un
internal class DefaultDeactivateAccountTask @Inject constructor( internal class DefaultDeactivateAccountTask @Inject constructor(
private val accountAPI: AccountAPI, private val accountAPI: AccountAPI,
private val eventBus: EventBus, private val globalErrorReceiver: GlobalErrorReceiver,
@UserId private val userId: String, @UserId private val userId: String,
private val identityDisconnectTask: IdentityDisconnectTask, private val identityDisconnectTask: IdentityDisconnectTask,
private val cleanupSession: CleanupSession private val cleanupSession: CleanupSession
@ -43,7 +43,7 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
override suspend fun execute(params: DeactivateAccountTask.Params) { override suspend fun execute(params: DeactivateAccountTask.Params) {
val deactivateAccountParams = DeactivateAccountParams.create(userId, params.password, params.eraseAllData) val deactivateAccountParams = DeactivateAccountParams.create(userId, params.password, params.eraseAllData)
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = accountAPI.deactivate(deactivateAccountParams) apiCall = accountAPI.deactivate(deactivateAccountParams)
} }

View File

@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.call.CallAnswerContent import org.matrix.android.sdk.api.session.room.model.call.CallAnswerContent
import org.matrix.android.sdk.api.session.room.model.call.CallCandidatesContent import org.matrix.android.sdk.api.session.room.model.call.CallCandidatesContent
import org.matrix.android.sdk.api.session.room.model.call.CallCapabilities
import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
import org.matrix.android.sdk.api.session.room.model.call.CallNegotiateContent import org.matrix.android.sdk.api.session.room.model.call.CallNegotiateContent
@ -185,6 +186,7 @@ internal class CallSignalingHandler @Inject constructor(private val activeCallHa
call.apply { call.apply {
opponentPartyId = Optional.from(content.partyId) opponentPartyId = Optional.from(content.partyId)
opponentVersion = content.version?.let { BigDecimal(it).intValueExact() } ?: MxCall.VOIP_PROTO_VERSION opponentVersion = content.version?.let { BigDecimal(it).intValueExact() } ?: MxCall.VOIP_PROTO_VERSION
capabilities = content.capabilities ?: CallCapabilities()
} }
callListenersDispatcher.onCallAnswerReceived(content) callListenersDispatcher.onCallAnswerReceived(content)
} }

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.session.call package org.matrix.android.sdk.internal.session.call
import org.matrix.android.sdk.api.session.call.TurnServerResponse import org.matrix.android.sdk.api.session.call.TurnServerResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class GetTurnServerTask : Task<GetTurnServerTask.Params, TurnServerResponse> { internal abstract class GetTurnServerTask : Task<GetTurnServerTask.Params, TurnServerResponse> {
@ -27,10 +27,10 @@ internal abstract class GetTurnServerTask : Task<GetTurnServerTask.Params, TurnS
} }
internal class DefaultGetTurnServerTask @Inject constructor(private val voipAPI: VoipApi, internal class DefaultGetTurnServerTask @Inject constructor(private val voipAPI: VoipApi,
private val eventBus: EventBus) : GetTurnServerTask() { private val globalErrorReceiver: GlobalErrorReceiver) : GetTurnServerTask() {
override suspend fun execute(params: Params): TurnServerResponse { override suspend fun execute(params: Params): TurnServerResponse {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = voipAPI.getTurnServer() apiCall = voipAPI.getTurnServer()
} }
} }

View File

@ -16,12 +16,15 @@
package org.matrix.android.sdk.internal.session.call package org.matrix.android.sdk.internal.session.call
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.session.call.MxCall import org.matrix.android.sdk.api.session.call.MxCall
import org.matrix.android.sdk.api.session.room.model.call.CallCapabilities
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.di.DeviceId import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.session.call.model.MxCallImpl import org.matrix.android.sdk.internal.session.call.model.MxCallImpl
import org.matrix.android.sdk.internal.session.profile.GetProfileInfoTask
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
import java.math.BigDecimal import java.math.BigDecimal
@ -32,6 +35,8 @@ internal class MxCallFactory @Inject constructor(
@DeviceId private val deviceId: String?, @DeviceId private val deviceId: String?,
private val localEchoEventFactory: LocalEchoEventFactory, private val localEchoEventFactory: LocalEchoEventFactory,
private val eventSenderProcessor: EventSenderProcessor, private val eventSenderProcessor: EventSenderProcessor,
private val matrixConfiguration: MatrixConfiguration,
private val getProfileInfoTask: GetProfileInfoTask,
@UserId private val userId: String @UserId private val userId: String
) { ) {
@ -46,10 +51,13 @@ internal class MxCallFactory @Inject constructor(
opponentUserId = opponentUserId, opponentUserId = opponentUserId,
isVideoCall = content.isVideo(), isVideoCall = content.isVideo(),
localEchoEventFactory = localEchoEventFactory, localEchoEventFactory = localEchoEventFactory,
eventSenderProcessor = eventSenderProcessor eventSenderProcessor = eventSenderProcessor,
matrixConfiguration = matrixConfiguration,
getProfileInfoTask = getProfileInfoTask
).apply { ).apply {
opponentPartyId = Optional.from(content.partyId) opponentPartyId = Optional.from(content.partyId)
opponentVersion = content.version?.let { BigDecimal(it).intValueExact() } ?: MxCall.VOIP_PROTO_VERSION opponentVersion = content.version?.let { BigDecimal(it).intValueExact() } ?: MxCall.VOIP_PROTO_VERSION
capabilities = content.capabilities ?: CallCapabilities()
} }
} }
@ -63,7 +71,9 @@ internal class MxCallFactory @Inject constructor(
opponentUserId = opponentUserId, opponentUserId = opponentUserId,
isVideoCall = isVideoCall, isVideoCall = isVideoCall,
localEchoEventFactory = localEchoEventFactory, localEchoEventFactory = localEchoEventFactory,
eventSenderProcessor = eventSenderProcessor eventSenderProcessor = eventSenderProcessor,
matrixConfiguration = matrixConfiguration,
getProfileInfoTask = getProfileInfoTask
) )
} }
} }

View File

@ -16,6 +16,7 @@
package org.matrix.android.sdk.internal.session.call.model package org.matrix.android.sdk.internal.session.call.model
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.session.call.CallState
import org.matrix.android.sdk.api.session.call.MxCall import org.matrix.android.sdk.api.session.call.MxCall
import org.matrix.android.sdk.api.session.events.model.Content import org.matrix.android.sdk.api.session.events.model.Content
@ -24,20 +25,25 @@ import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.LocalEcho import org.matrix.android.sdk.api.session.events.model.LocalEcho
import org.matrix.android.sdk.api.session.events.model.UnsignedData import org.matrix.android.sdk.api.session.events.model.UnsignedData
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.profile.ProfileService
import org.matrix.android.sdk.api.session.room.model.call.CallAnswerContent import org.matrix.android.sdk.api.session.room.model.call.CallAnswerContent
import org.matrix.android.sdk.api.session.room.model.call.CallCandidate import org.matrix.android.sdk.api.session.room.model.call.CallCandidate
import org.matrix.android.sdk.api.session.room.model.call.CallCandidatesContent import org.matrix.android.sdk.api.session.room.model.call.CallCandidatesContent
import org.matrix.android.sdk.api.session.room.model.call.CallCapabilities
import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent import org.matrix.android.sdk.api.session.room.model.call.CallHangupContent
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
import org.matrix.android.sdk.api.session.room.model.call.CallNegotiateContent import org.matrix.android.sdk.api.session.room.model.call.CallNegotiateContent
import org.matrix.android.sdk.api.session.room.model.call.CallRejectContent import org.matrix.android.sdk.api.session.room.model.call.CallRejectContent
import org.matrix.android.sdk.api.session.room.model.call.CallReplacesContent
import org.matrix.android.sdk.api.session.room.model.call.CallSelectAnswerContent import org.matrix.android.sdk.api.session.room.model.call.CallSelectAnswerContent
import org.matrix.android.sdk.api.session.room.model.call.SdpType import org.matrix.android.sdk.api.session.room.model.call.SdpType
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.session.call.DefaultCallSignalingService import org.matrix.android.sdk.internal.session.call.DefaultCallSignalingService
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor import org.matrix.android.sdk.internal.session.profile.GetProfileInfoTask
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
import timber.log.Timber import timber.log.Timber
import java.util.UUID
internal class MxCallImpl( internal class MxCallImpl(
override val callId: String, override val callId: String,
@ -48,11 +54,14 @@ internal class MxCallImpl(
override val isVideoCall: Boolean, override val isVideoCall: Boolean,
override val ourPartyId: String, override val ourPartyId: String,
private val localEchoEventFactory: LocalEchoEventFactory, private val localEchoEventFactory: LocalEchoEventFactory,
private val eventSenderProcessor: EventSenderProcessor private val eventSenderProcessor: EventSenderProcessor,
private val matrixConfiguration: MatrixConfiguration,
private val getProfileInfoTask: GetProfileInfoTask
) : MxCall { ) : MxCall {
override var opponentPartyId: Optional<String>? = null override var opponentPartyId: Optional<String>? = null
override var opponentVersion: Int = MxCall.VOIP_PROTO_VERSION override var opponentVersion: Int = MxCall.VOIP_PROTO_VERSION
override var capabilities: CallCapabilities? = null
override var state: CallState = CallState.Idle override var state: CallState = CallState.Idle
set(value) { set(value) {
@ -98,7 +107,8 @@ internal class MxCallImpl(
partyId = ourPartyId, partyId = ourPartyId,
lifetime = DefaultCallSignalingService.CALL_TIMEOUT_MS, lifetime = DefaultCallSignalingService.CALL_TIMEOUT_MS,
offer = CallInviteContent.Offer(sdp = sdpString), offer = CallInviteContent.Offer(sdp = sdpString),
version = MxCall.VOIP_PROTO_VERSION.toString() version = MxCall.VOIP_PROTO_VERSION.toString(),
capabilities = buildCapabilities()
) )
.let { createEventAndLocalEcho(type = EventType.CALL_INVITE, roomId = roomId, content = it.toContent()) } .let { createEventAndLocalEcho(type = EventType.CALL_INVITE, roomId = roomId, content = it.toContent()) }
.also { eventSenderProcessor.postEvent(it) } .also { eventSenderProcessor.postEvent(it) }
@ -158,7 +168,8 @@ internal class MxCallImpl(
callId = callId, callId = callId,
partyId = ourPartyId, partyId = ourPartyId,
answer = CallAnswerContent.Answer(sdp = sdpString), answer = CallAnswerContent.Answer(sdp = sdpString),
version = MxCall.VOIP_PROTO_VERSION.toString() version = MxCall.VOIP_PROTO_VERSION.toString(),
capabilities = buildCapabilities()
) )
.let { createEventAndLocalEcho(type = EventType.CALL_ANSWER, roomId = roomId, content = it.toContent()) } .let { createEventAndLocalEcho(type = EventType.CALL_ANSWER, roomId = roomId, content = it.toContent()) }
.also { eventSenderProcessor.postEvent(it) } .also { eventSenderProcessor.postEvent(it) }
@ -191,6 +202,31 @@ internal class MxCallImpl(
.also { eventSenderProcessor.postEvent(it) } .also { eventSenderProcessor.postEvent(it) }
} }
override suspend fun transfer(targetUserId: String, targetRoomId: String?) {
val profileInfoParams = GetProfileInfoTask.Params(targetUserId)
val profileInfo = try {
getProfileInfoTask.execute(profileInfoParams)
} catch (failure: Throwable) {
Timber.v("Fail fetching profile info of $targetUserId while transferring call")
null
}
CallReplacesContent(
callId = callId,
partyId = ourPartyId,
replacementId = UUID.randomUUID().toString(),
version = MxCall.VOIP_PROTO_VERSION.toString(),
targetUser = CallReplacesContent.TargetUser(
id = targetUserId,
displayName = profileInfo?.get(ProfileService.DISPLAY_NAME_KEY) as? String,
avatarUrl = profileInfo?.get(ProfileService.AVATAR_URL_KEY) as? String
),
targerRoomId = targetRoomId,
createCall = UUID.randomUUID().toString()
)
.let { createEventAndLocalEcho(type = EventType.CALL_REPLACES, roomId = roomId, content = it.toContent()) }
.also { eventSenderProcessor.postEvent(it) }
}
private fun createEventAndLocalEcho(localId: String = LocalEcho.createLocalEchoId(), type: String, roomId: String, content: Content): Event { private fun createEventAndLocalEcho(localId: String = LocalEcho.createLocalEchoId(), type: String, roomId: String, content: Content): Event {
return Event( return Event(
roomId = roomId, roomId = roomId,
@ -203,4 +239,12 @@ internal class MxCallImpl(
) )
.also { localEchoEventFactory.createLocalEcho(it) } .also { localEchoEventFactory.createLocalEcho(it) }
} }
private fun buildCapabilities(): CallCapabilities? {
return if (matrixConfiguration.supportsCallTransfer) {
CallCapabilities(true)
} else {
null
}
}
} }

View File

@ -30,10 +30,10 @@ import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
import okio.BufferedSink import okio.BufferedSink
import okio.source import okio.source
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.api.session.content.ContentUrlResolver
import org.matrix.android.sdk.internal.di.Authenticated import org.matrix.android.sdk.internal.di.Authenticated
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.ProgressRequestBody import org.matrix.android.sdk.internal.network.ProgressRequestBody
import org.matrix.android.sdk.internal.network.awaitResponse import org.matrix.android.sdk.internal.network.awaitResponse
import org.matrix.android.sdk.internal.network.toFailure import org.matrix.android.sdk.internal.network.toFailure
@ -45,7 +45,7 @@ import javax.inject.Inject
internal class FileUploader @Inject constructor(@Authenticated internal class FileUploader @Inject constructor(@Authenticated
private val okHttpClient: OkHttpClient, private val okHttpClient: OkHttpClient,
private val eventBus: EventBus, private val globalErrorReceiver: GlobalErrorReceiver,
private val context: Context, private val context: Context,
contentUrlResolver: ContentUrlResolver, contentUrlResolver: ContentUrlResolver,
moshi: Moshi) { moshi: Moshi) {
@ -115,7 +115,7 @@ internal class FileUploader @Inject constructor(@Authenticated
return okHttpClient.newCall(request).awaitResponse().use { response -> return okHttpClient.newCall(request).awaitResponse().use { response ->
if (!response.isSuccessful) { if (!response.isSuccessful) {
throw response.toFailure(eventBus) throw response.toFailure(globalErrorReceiver)
} else { } else {
response.body?.source()?.let { response.body?.source()?.let {
responseAdapter.fromJson(it) responseAdapter.fromJson(it)

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.filter
import org.matrix.android.sdk.api.session.sync.FilterService import org.matrix.android.sdk.api.session.sync.FilterService
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -37,7 +37,7 @@ internal class DefaultSaveFilterTask @Inject constructor(
@UserId private val userId: String, @UserId private val userId: String,
private val filterAPI: FilterApi, private val filterAPI: FilterApi,
private val filterRepository: FilterRepository, private val filterRepository: FilterRepository,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : SaveFilterTask { ) : SaveFilterTask {
override suspend fun execute(params: SaveFilterTask.Params) { override suspend fun execute(params: SaveFilterTask.Params) {
@ -59,7 +59,7 @@ internal class DefaultSaveFilterTask @Inject constructor(
} }
val updated = filterRepository.storeFilter(filterBody, roomFilter) val updated = filterRepository.storeFilter(filterBody, roomFilter)
if (updated) { if (updated) {
val filterResponse = executeRequest<FilterResponse>(eventBus) { val filterResponse = executeRequest<FilterResponse>(globalErrorReceiver) {
// TODO auto retry // TODO auto retry
apiCall = filterAPI.uploadFilter(userId, filterBody) apiCall = filterAPI.uploadFilter(userId, filterBody)
} }

View File

@ -23,13 +23,13 @@ import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity
import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.group.model.GroupRooms import org.matrix.android.sdk.internal.session.group.model.GroupRooms
import org.matrix.android.sdk.internal.session.group.model.GroupSummaryResponse import org.matrix.android.sdk.internal.session.group.model.GroupSummaryResponse
import org.matrix.android.sdk.internal.session.group.model.GroupUsers import org.matrix.android.sdk.internal.session.group.model.GroupUsers
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -43,7 +43,7 @@ internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
internal class DefaultGetGroupDataTask @Inject constructor( internal class DefaultGetGroupDataTask @Inject constructor(
private val groupAPI: GroupAPI, private val groupAPI: GroupAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetGroupDataTask { ) : GetGroupDataTask {
private data class GroupData( private data class GroupData(
@ -64,13 +64,13 @@ internal class DefaultGetGroupDataTask @Inject constructor(
} }
Timber.v("Fetch data for group with ids: ${groupIds.joinToString(";")}") Timber.v("Fetch data for group with ids: ${groupIds.joinToString(";")}")
val data = groupIds.map { groupId -> val data = groupIds.map { groupId ->
val groupSummary = executeRequest<GroupSummaryResponse>(eventBus) { val groupSummary = executeRequest<GroupSummaryResponse>(globalErrorReceiver) {
apiCall = groupAPI.getSummary(groupId) apiCall = groupAPI.getSummary(groupId)
} }
val groupRooms = executeRequest<GroupRooms>(eventBus) { val groupRooms = executeRequest<GroupRooms>(globalErrorReceiver) {
apiCall = groupAPI.getRooms(groupId) apiCall = groupAPI.getRooms(groupId)
} }
val groupUsers = executeRequest<GroupUsers>(eventBus) { val groupUsers = executeRequest<GroupUsers>(globalErrorReceiver) {
apiCall = groupAPI.getUsers(groupId) apiCall = groupAPI.getUsers(groupId)
} }
GroupData(groupId, groupSummary, groupRooms, groupUsers) GroupData(groupId, groupSummary, groupRooms, groupUsers)

View File

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.homeserver package org.matrix.android.sdk.internal.session.homeserver
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
@ -27,6 +26,7 @@ import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEnti
import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor
import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult
@ -44,7 +44,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
private val capabilitiesAPI: CapabilitiesAPI, private val capabilitiesAPI: CapabilitiesAPI,
private val mediaAPI: MediaAPI, private val mediaAPI: MediaAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val eventBus: EventBus, private val globalErrorReceiver: GlobalErrorReceiver,
private val getWellknownTask: GetWellknownTask, private val getWellknownTask: GetWellknownTask,
private val configExtractor: IntegrationManagerConfigExtractor, private val configExtractor: IntegrationManagerConfigExtractor,
private val homeServerConnectionConfig: HomeServerConnectionConfig, private val homeServerConnectionConfig: HomeServerConnectionConfig,
@ -65,13 +65,13 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
} }
val capabilities = runCatching { val capabilities = runCatching {
executeRequest<GetCapabilitiesResult>(eventBus) { executeRequest<GetCapabilitiesResult>(globalErrorReceiver) {
apiCall = capabilitiesAPI.getCapabilities() apiCall = capabilitiesAPI.getCapabilities()
} }
}.getOrNull() }.getOrNull()
val mediaConfig = runCatching { val mediaConfig = runCatching {
executeRequest<GetMediaConfigResult>(eventBus) { executeRequest<GetMediaConfigResult>(globalErrorReceiver) {
apiCall = mediaAPI.getMediaConfig() apiCall = mediaAPI.getMediaConfig()
} }
}.getOrNull() }.getOrNull()

View File

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.media package org.matrix.android.sdk.internal.session.media
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.cache.CacheStrategy import org.matrix.android.sdk.api.cache.CacheStrategy
import org.matrix.android.sdk.api.session.media.PreviewUrlData import org.matrix.android.sdk.api.session.media.PreviewUrlData
import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.JsonDict
@ -25,6 +24,7 @@ import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntity
import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.database.query.get
import org.matrix.android.sdk.internal.database.query.getOrCreate import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
@ -41,7 +41,7 @@ internal interface GetPreviewUrlTask : Task<GetPreviewUrlTask.Params, PreviewUrl
internal class DefaultGetPreviewUrlTask @Inject constructor( internal class DefaultGetPreviewUrlTask @Inject constructor(
private val mediaAPI: MediaAPI, private val mediaAPI: MediaAPI,
private val eventBus: EventBus, private val globalErrorReceiver: GlobalErrorReceiver,
@SessionDatabase private val monarchy: Monarchy @SessionDatabase private val monarchy: Monarchy
) : GetPreviewUrlTask { ) : GetPreviewUrlTask {
@ -64,7 +64,7 @@ internal class DefaultGetPreviewUrlTask @Inject constructor(
} }
private suspend fun doRequest(url: String, timestamp: Long?): PreviewUrlData { private suspend fun doRequest(url: String, timestamp: Long?): PreviewUrlData {
return executeRequest<JsonDict>(eventBus) { return executeRequest<JsonDict>(globalErrorReceiver) {
apiCall = mediaAPI.getPreviewUrlData(url, timestamp) apiCall = mediaAPI.getPreviewUrlData(url, timestamp)
} }
.toPreviewUrlData(url) .toPreviewUrlData(url)

View File

@ -16,8 +16,8 @@
package org.matrix.android.sdk.internal.session.media package org.matrix.android.sdk.internal.session.media
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -31,11 +31,11 @@ internal interface GetRawPreviewUrlTask : Task<GetRawPreviewUrlTask.Params, Json
internal class DefaultGetRawPreviewUrlTask @Inject constructor( internal class DefaultGetRawPreviewUrlTask @Inject constructor(
private val mediaAPI: MediaAPI, private val mediaAPI: MediaAPI,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetRawPreviewUrlTask { ) : GetRawPreviewUrlTask {
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict { override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = mediaAPI.getPreviewUrlData(params.url, params.timestamp) apiCall = mediaAPI.getPreviewUrlData(params.url, params.timestamp)
} }
} }

View File

@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.session.openid package org.matrix.android.sdk.internal.session.openid
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetOpenIdTokenTask : Task<Unit, RequestOpenIdTokenResponse> internal interface GetOpenIdTokenTask : Task<Unit, RequestOpenIdTokenResponse>
@ -27,10 +27,10 @@ internal interface GetOpenIdTokenTask : Task<Unit, RequestOpenIdTokenResponse>
internal class DefaultGetOpenIdTokenTask @Inject constructor( internal class DefaultGetOpenIdTokenTask @Inject constructor(
@UserId private val userId: String, @UserId private val userId: String,
private val openIdAPI: OpenIdAPI, private val openIdAPI: OpenIdAPI,
private val eventBus: EventBus) : GetOpenIdTokenTask { private val globalErrorReceiver: GlobalErrorReceiver) : GetOpenIdTokenTask {
override suspend fun execute(params: Unit): RequestOpenIdTokenResponse { override suspend fun execute(params: Unit): RequestOpenIdTokenResponse {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = openIdAPI.openIdToken(userId) apiCall = openIdAPI.openIdToken(userId)
} }
} }

View File

@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.profile
import com.google.i18n.phonenumbers.PhoneNumberUtil import com.google.i18n.phonenumbers.PhoneNumberUtil
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
@ -37,7 +37,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
private val profileAPI: ProfileAPI, private val profileAPI: ProfileAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper, private val pendingThreePidMapper: PendingThreePidMapper,
private val eventBus: EventBus) : AddThreePidTask() { private val globalErrorReceiver: GlobalErrorReceiver) : AddThreePidTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
when (params.threePid) { when (params.threePid) {
@ -50,7 +50,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
val clientSecret = UUID.randomUUID().toString() val clientSecret = UUID.randomUUID().toString()
val sendAttempt = 1 val sendAttempt = 1
val result = executeRequest<AddEmailResponse>(eventBus) { val result = executeRequest<AddEmailResponse>(globalErrorReceiver) {
val body = AddEmailBody( val body = AddEmailBody(
clientSecret = clientSecret, clientSecret = clientSecret,
email = threePid.email, email = threePid.email,
@ -84,7 +84,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
val countryCode = parsedNumber.countryCode val countryCode = parsedNumber.countryCode
val country = phoneNumberUtil.getRegionCodeForCountryCode(countryCode) val country = phoneNumberUtil.getRegionCodeForCountryCode(countryCode)
val result = executeRequest<AddMsisdnResponse>(eventBus) { val result = executeRequest<AddMsisdnResponse>(globalErrorReceiver) {
val body = AddMsisdnBody( val body = AddMsisdnBody(
clientSecret = clientSecret, clientSecret = clientSecret,
country = country, country = country,

View File

@ -19,12 +19,12 @@ package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.di.AuthenticatedIdentity import org.matrix.android.sdk.internal.di.AuthenticatedIdentity
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.network.token.AccessTokenProvider import org.matrix.android.sdk.internal.network.token.AccessTokenProvider
import org.matrix.android.sdk.internal.session.identity.data.IdentityStore import org.matrix.android.sdk.internal.session.identity.data.IdentityStore
import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class BindThreePidsTask : Task<BindThreePidsTask.Params, Unit> { internal abstract class BindThreePidsTask : Task<BindThreePidsTask.Params, Unit> {
@ -37,13 +37,13 @@ internal class DefaultBindThreePidsTask @Inject constructor(private val profileA
private val identityStore: IdentityStore, private val identityStore: IdentityStore,
@AuthenticatedIdentity @AuthenticatedIdentity
private val accessTokenProvider: AccessTokenProvider, private val accessTokenProvider: AccessTokenProvider,
private val eventBus: EventBus) : BindThreePidsTask() { private val globalErrorReceiver: GlobalErrorReceiver) : BindThreePidsTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured
val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured
val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = profileAPI.bindThreePid( apiCall = profileAPI.bindThreePid(
BindThreePidBody( BindThreePidBody(
clientSecret = identityPendingBinding.clientSecret, clientSecret = identityPendingBinding.clientSecret,

View File

@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.session.identity.toMedium import org.matrix.android.sdk.api.session.identity.toMedium
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -31,10 +31,10 @@ internal abstract class DeleteThreePidTask : Task<DeleteThreePidTask.Params, Uni
internal class DefaultDeleteThreePidTask @Inject constructor( internal class DefaultDeleteThreePidTask @Inject constructor(
private val profileAPI: ProfileAPI, private val profileAPI: ProfileAPI,
private val eventBus: EventBus) : DeleteThreePidTask() { private val globalErrorReceiver: GlobalErrorReceiver) : DeleteThreePidTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
executeRequest<DeleteThreePidResponse>(eventBus) { executeRequest<DeleteThreePidResponse>(globalErrorReceiver) {
val body = DeleteThreePidBody( val body = DeleteThreePidBody(
medium = params.threePid.toMedium(), medium = params.threePid.toMedium(),
address = params.threePid.value address = params.threePid.value

View File

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
@ -26,6 +25,7 @@ import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
@ -45,7 +45,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper, private val pendingThreePidMapper: PendingThreePidMapper,
@UserId private val userId: String, @UserId private val userId: String,
private val eventBus: EventBus) : FinalizeAddingThreePidTask() { private val globalErrorReceiver: GlobalErrorReceiver) : FinalizeAddingThreePidTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
if (params.userWantsToCancel.not()) { if (params.userWantsToCancel.not()) {
@ -58,7 +58,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
?: throw IllegalArgumentException("unknown threepid") ?: throw IllegalArgumentException("unknown threepid")
try { try {
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
val body = FinalizeAddThreePidBody( val body = FinalizeAddThreePidBody(
clientSecret = pendingThreePids.clientSecret, clientSecret = pendingThreePids.clientSecret,
sid = pendingThreePids.sid, sid = pendingThreePids.sid,

View File

@ -18,9 +18,9 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class GetProfileInfoTask : Task<GetProfileInfoTask.Params, JsonDict> { internal abstract class GetProfileInfoTask : Task<GetProfileInfoTask.Params, JsonDict> {
@ -30,10 +30,10 @@ internal abstract class GetProfileInfoTask : Task<GetProfileInfoTask.Params, Jso
} }
internal class DefaultGetProfileInfoTask @Inject constructor(private val profileAPI: ProfileAPI, internal class DefaultGetProfileInfoTask @Inject constructor(private val profileAPI: ProfileAPI,
private val eventBus: EventBus) : GetProfileInfoTask() { private val globalErrorReceiver: GlobalErrorReceiver) : GetProfileInfoTask() {
override suspend fun execute(params: Params): JsonDict { override suspend fun execute(params: Params): JsonDict {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = profileAPI.getProfile(params.userId) apiCall = profileAPI.getProfile(params.userId)
} }
} }

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.session.profile
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.internal.database.model.UserThreePidEntity import org.matrix.android.sdk.internal.database.model.UserThreePidEntity
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -30,10 +30,10 @@ internal abstract class RefreshUserThreePidsTask : Task<Unit, Unit>
internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI, internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val eventBus: EventBus) : RefreshUserThreePidsTask() { private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() {
override suspend fun execute(params: Unit) { override suspend fun execute(params: Unit) {
val accountThreePidsResponse = executeRequest<AccountThreePidsResponse>(eventBus) { val accountThreePidsResponse = executeRequest<AccountThreePidsResponse>(globalErrorReceiver) {
apiCall = profileAPI.getThreePIDs() apiCall = profileAPI.getThreePIDs()
} }

View File

@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class SetAvatarUrlTask : Task<SetAvatarUrlTask.Params, Unit> { internal abstract class SetAvatarUrlTask : Task<SetAvatarUrlTask.Params, Unit> {
@ -30,10 +30,10 @@ internal abstract class SetAvatarUrlTask : Task<SetAvatarUrlTask.Params, Unit> {
internal class DefaultSetAvatarUrlTask @Inject constructor( internal class DefaultSetAvatarUrlTask @Inject constructor(
private val profileAPI: ProfileAPI, private val profileAPI: ProfileAPI,
private val eventBus: EventBus) : SetAvatarUrlTask() { private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
val body = SetAvatarUrlBody( val body = SetAvatarUrlBody(
avatarUrl = params.newAvatarUrl avatarUrl = params.newAvatarUrl
) )

View File

@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class SetDisplayNameTask : Task<SetDisplayNameTask.Params, Unit> { internal abstract class SetDisplayNameTask : Task<SetDisplayNameTask.Params, Unit> {
@ -30,10 +30,10 @@ internal abstract class SetDisplayNameTask : Task<SetDisplayNameTask.Params, Uni
internal class DefaultSetDisplayNameTask @Inject constructor( internal class DefaultSetDisplayNameTask @Inject constructor(
private val profileAPI: ProfileAPI, private val profileAPI: ProfileAPI,
private val eventBus: EventBus) : SetDisplayNameTask() { private val globalErrorReceiver: GlobalErrorReceiver) : SetDisplayNameTask() {
override suspend fun execute(params: Params) { override suspend fun execute(params: Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
val body = SetDisplayNameBody( val body = SetDisplayNameBody(
displayName = params.newDisplayName displayName = params.newDisplayName
) )

View File

@ -19,11 +19,11 @@ package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.session.identity.toMedium import org.matrix.android.sdk.api.session.identity.toMedium
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.identity.data.IdentityStore import org.matrix.android.sdk.internal.session.identity.data.IdentityStore
import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal abstract class UnbindThreePidsTask : Task<UnbindThreePidsTask.Params, Boolean> { internal abstract class UnbindThreePidsTask : Task<UnbindThreePidsTask.Params, Boolean> {
@ -34,12 +34,12 @@ internal abstract class UnbindThreePidsTask : Task<UnbindThreePidsTask.Params, B
internal class DefaultUnbindThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI, internal class DefaultUnbindThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI,
private val identityStore: IdentityStore, private val identityStore: IdentityStore,
private val eventBus: EventBus) : UnbindThreePidsTask() { private val globalErrorReceiver: GlobalErrorReceiver) : UnbindThreePidsTask() {
override suspend fun execute(params: Params): Boolean { override suspend fun execute(params: Params): Boolean {
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol()
?: throw IdentityServiceError.NoIdentityServerConfigured ?: throw IdentityServiceError.NoIdentityServerConfigured
return executeRequest<UnbindThreePidResponse>(eventBus) { return executeRequest<UnbindThreePidResponse>(globalErrorReceiver) {
apiCall = profileAPI.unbindThreePid( apiCall = profileAPI.unbindThreePid(
UnbindThreePidBody( UnbindThreePidBody(
identityServerUrlWithoutProtocol, identityServerUrlWithoutProtocol,

View File

@ -17,13 +17,13 @@
package org.matrix.android.sdk.internal.session.profile package org.matrix.android.sdk.internal.session.profile
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.auth.registration.SuccessResult
import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -40,7 +40,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor(
@SessionDatabase @SessionDatabase
private val monarchy: Monarchy, private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper, private val pendingThreePidMapper: PendingThreePidMapper,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : ValidateSmsCodeTask { ) : ValidateSmsCodeTask {
override suspend fun execute(params: ValidateSmsCodeTask.Params) { override suspend fun execute(params: ValidateSmsCodeTask.Params) {
@ -58,7 +58,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor(
sid = pendingThreePids.sid, sid = pendingThreePids.sid,
code = params.code code = params.code
) )
val result = executeRequest<SuccessResult>(eventBus) { val result = executeRequest<SuccessResult>(globalErrorReceiver) {
apiCall = profileAPI.validateMsisdn(url, body) apiCall = profileAPI.validateMsisdn(url, body)
} }

View File

@ -19,13 +19,13 @@ import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.pushers.PusherState import org.matrix.android.sdk.api.session.pushers.PusherState
import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.mapper.toEntity
import org.matrix.android.sdk.internal.database.model.PusherEntity import org.matrix.android.sdk.internal.database.model.PusherEntity
import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
@ -45,7 +45,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
@Inject lateinit var pushersAPI: PushersAPI @Inject lateinit var pushersAPI: PushersAPI
@Inject @SessionDatabase lateinit var monarchy: Monarchy @Inject @SessionDatabase lateinit var monarchy: Monarchy
@Inject lateinit var eventBus: EventBus @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
override fun injectWith(injector: SessionComponent) { override fun injectWith(injector: SessionComponent) {
injector.inject(this) injector.inject(this)
@ -81,7 +81,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
} }
private suspend fun setPusher(pusher: JsonPusher) { private suspend fun setPusher(pusher: JsonPusher) {
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = pushersAPI.setPusher(pusher) apiCall = pushersAPI.setPusher(pusher)
} }
monarchy.awaitTransaction { realm -> monarchy.awaitTransaction { realm ->

View File

@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> { internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> {
@ -31,11 +31,11 @@ internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> {
internal class DefaultAddPushRuleTask @Inject constructor( internal class DefaultAddPushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi, private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : AddPushRuleTask { ) : AddPushRuleTask {
override suspend fun execute(params: AddPushRuleTask.Params) { override suspend fun execute(params: AddPushRuleTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule) apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
} }
} }

View File

@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.pushers package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> { internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
@ -31,11 +31,11 @@ internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
internal class DefaultGetPushRulesTask @Inject constructor( internal class DefaultGetPushRulesTask @Inject constructor(
private val pushRulesApi: PushRulesApi, private val pushRulesApi: PushRulesApi,
private val savePushRulesTask: SavePushRulesTask, private val savePushRulesTask: SavePushRulesTask,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetPushRulesTask { ) : GetPushRulesTask {
override suspend fun execute(params: GetPushRulesTask.Params) { override suspend fun execute(params: GetPushRulesTask.Params) {
val response = executeRequest<GetPushRulesResponse>(eventBus) { val response = executeRequest<GetPushRulesResponse>(globalErrorReceiver) {
apiCall = pushRulesApi.getAllRules() apiCall = pushRulesApi.getAllRules()
} }

View File

@ -20,10 +20,10 @@ import org.matrix.android.sdk.api.session.pushers.PusherState
import org.matrix.android.sdk.internal.database.mapper.toEntity import org.matrix.android.sdk.internal.database.mapper.toEntity
import org.matrix.android.sdk.internal.database.model.PusherEntity import org.matrix.android.sdk.internal.database.model.PusherEntity
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetPushersTask : Task<Unit, Unit> internal interface GetPushersTask : Task<Unit, Unit>
@ -31,11 +31,11 @@ internal interface GetPushersTask : Task<Unit, Unit>
internal class DefaultGetPushersTask @Inject constructor( internal class DefaultGetPushersTask @Inject constructor(
private val pushersAPI: PushersAPI, private val pushersAPI: PushersAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetPushersTask { ) : GetPushersTask {
override suspend fun execute(params: Unit) { override suspend fun execute(params: Unit) {
val response = executeRequest<GetPushersResponse>(eventBus) { val response = executeRequest<GetPushersResponse>(globalErrorReceiver) {
apiCall = pushersAPI.getPushers() apiCall = pushersAPI.getPushers()
} }
monarchy.awaitTransaction { realm -> monarchy.awaitTransaction { realm ->

View File

@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> { internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> {
@ -31,11 +31,11 @@ internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> {
internal class DefaultRemovePushRuleTask @Inject constructor( internal class DefaultRemovePushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi, private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : RemovePushRuleTask { ) : RemovePushRuleTask {
override suspend fun execute(params: RemovePushRuleTask.Params) { override suspend fun execute(params: RemovePushRuleTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId) apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId)
} }
} }

View File

@ -26,7 +26,7 @@ import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction import org.matrix.android.sdk.internal.util.awaitTransaction
import io.realm.Realm import io.realm.Realm
import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import javax.inject.Inject import javax.inject.Inject
internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> { internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
@ -37,7 +37,7 @@ internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
internal class DefaultRemovePusherTask @Inject constructor( internal class DefaultRemovePusherTask @Inject constructor(
private val pushersAPI: PushersAPI, private val pushersAPI: PushersAPI,
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : RemovePusherTask { ) : RemovePusherTask {
override suspend fun execute(params: RemovePusherTask.Params) { override suspend fun execute(params: RemovePusherTask.Params) {
@ -62,7 +62,7 @@ internal class DefaultRemovePusherTask @Inject constructor(
data = JsonPusherData(existing.data.url, existing.data.format), data = JsonPusherData(existing.data.url, existing.data.format),
append = false append = false
) )
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = pushersAPI.setPusher(deleteBody) apiCall = pushersAPI.setPusher(deleteBody)
} }
monarchy.awaitTransaction { monarchy.awaitTransaction {

View File

@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdatePushRuleActionsTask : Task<UpdatePushRuleActionsTask.Params, Unit> { internal interface UpdatePushRuleActionsTask : Task<UpdatePushRuleActionsTask.Params, Unit> {
@ -32,13 +32,13 @@ internal interface UpdatePushRuleActionsTask : Task<UpdatePushRuleActionsTask.Pa
internal class DefaultUpdatePushRuleActionsTask @Inject constructor( internal class DefaultUpdatePushRuleActionsTask @Inject constructor(
private val pushRulesApi: PushRulesApi, private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UpdatePushRuleActionsTask { ) : UpdatePushRuleActionsTask {
override suspend fun execute(params: UpdatePushRuleActionsTask.Params) { override suspend fun execute(params: UpdatePushRuleActionsTask.Params) {
if (params.oldPushRule.enabled != params.newPushRule.enabled) { if (params.oldPushRule.enabled != params.newPushRule.enabled) {
// First change enabled state // First change enabled state
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled) apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled)
} }
} }
@ -47,7 +47,7 @@ internal class DefaultUpdatePushRuleActionsTask @Inject constructor(
// Also ensure the actions are up to date // Also ensure the actions are up to date
val body = mapOf("actions" to params.newPushRule.actions) val body = mapOf("actions" to params.newPushRule.actions)
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body) apiCall = pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body)
} }
} }

View File

@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> { internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> {
@ -30,11 +30,11 @@ internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableSta
internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor( internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor(
private val pushRulesApi: PushRulesApi, private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : UpdatePushRuleEnableStatusTask { ) : UpdatePushRuleEnableStatusTask {
override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) { override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) {
return executeRequest(eventBus) { return executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled) apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled)
} }
} }

View File

@ -16,8 +16,8 @@
package org.matrix.android.sdk.internal.session.room.alias package org.matrix.android.sdk.internal.session.room.alias
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasAvailabilityChecker.Companion.toFullLocalAlias import org.matrix.android.sdk.internal.session.room.alias.RoomAliasAvailabilityChecker.Companion.toFullLocalAlias
@ -39,13 +39,13 @@ internal class DefaultAddRoomAliasTask @Inject constructor(
@UserId private val userId: String, @UserId private val userId: String,
private val directoryAPI: DirectoryAPI, private val directoryAPI: DirectoryAPI,
private val aliasAvailabilityChecker: RoomAliasAvailabilityChecker, private val aliasAvailabilityChecker: RoomAliasAvailabilityChecker,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : AddRoomAliasTask { ) : AddRoomAliasTask {
override suspend fun execute(params: AddRoomAliasTask.Params) { override suspend fun execute(params: AddRoomAliasTask.Params) {
aliasAvailabilityChecker.check(params.aliasLocalPart) aliasAvailabilityChecker.check(params.aliasLocalPart)
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = directoryAPI.addRoomAlias( apiCall = directoryAPI.addRoomAlias(
roomAlias = params.aliasLocalPart.toFullLocalAlias(userId), roomAlias = params.aliasLocalPart.toFullLocalAlias(userId),
body = AddRoomAliasBody( body = AddRoomAliasBody(

View File

@ -16,7 +16,7 @@
package org.matrix.android.sdk.internal.session.room.alias package org.matrix.android.sdk.internal.session.room.alias
import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
@ -30,11 +30,11 @@ internal interface DeleteRoomAliasTask : Task<DeleteRoomAliasTask.Params, Unit>
internal class DefaultDeleteRoomAliasTask @Inject constructor( internal class DefaultDeleteRoomAliasTask @Inject constructor(
private val directoryAPI: DirectoryAPI, private val directoryAPI: DirectoryAPI,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteRoomAliasTask { ) : DeleteRoomAliasTask {
override suspend fun execute(params: DeleteRoomAliasTask.Params) { override suspend fun execute(params: DeleteRoomAliasTask.Params) {
executeRequest<Unit>(eventBus) { executeRequest<Unit>(globalErrorReceiver) {
apiCall = directoryAPI.deleteRoomAlias( apiCall = directoryAPI.deleteRoomAlias(
roomAlias = params.roomAlias roomAlias = params.roomAlias
) )

View File

@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.alias
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import io.realm.Realm import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.query.findByAlias import org.matrix.android.sdk.internal.database.query.findByAlias
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
@ -39,7 +39,7 @@ internal interface GetRoomIdByAliasTask : Task<GetRoomIdByAliasTask.Params, Opti
internal class DefaultGetRoomIdByAliasTask @Inject constructor( internal class DefaultGetRoomIdByAliasTask @Inject constructor(
@SessionDatabase private val monarchy: Monarchy, @SessionDatabase private val monarchy: Monarchy,
private val directoryAPI: DirectoryAPI, private val directoryAPI: DirectoryAPI,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetRoomIdByAliasTask { ) : GetRoomIdByAliasTask {
override suspend fun execute(params: GetRoomIdByAliasTask.Params): Optional<RoomAliasDescription> { override suspend fun execute(params: GetRoomIdByAliasTask.Params): Optional<RoomAliasDescription> {
@ -52,7 +52,7 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor(
Optional.from(null) Optional.from(null)
} else { } else {
val description = tryOrNull("## Failed to get roomId from alias") { val description = tryOrNull("## Failed to get roomId from alias") {
executeRequest<RoomAliasDescription>(eventBus) { executeRequest<RoomAliasDescription>(globalErrorReceiver) {
apiCall = directoryAPI.getRoomIdByAlias(params.roomAlias) apiCall = directoryAPI.getRoomIdByAlias(params.roomAlias)
} }
} }

View File

@ -16,7 +16,7 @@
package org.matrix.android.sdk.internal.session.room.alias package org.matrix.android.sdk.internal.session.room.alias
import org.greenrobot.eventbus.EventBus import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest 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.RoomAPI
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
@ -30,12 +30,12 @@ internal interface GetRoomLocalAliasesTask : Task<GetRoomLocalAliasesTask.Params
internal class DefaultGetRoomLocalAliasesTask @Inject constructor( internal class DefaultGetRoomLocalAliasesTask @Inject constructor(
private val roomAPI: RoomAPI, private val roomAPI: RoomAPI,
private val eventBus: EventBus private val globalErrorReceiver: GlobalErrorReceiver
) : GetRoomLocalAliasesTask { ) : GetRoomLocalAliasesTask {
override suspend fun execute(params: GetRoomLocalAliasesTask.Params): List<String> { override suspend fun execute(params: GetRoomLocalAliasesTask.Params): List<String> {
// We do not check for "org.matrix.msc2432", so the API may be missing // We do not check for "org.matrix.msc2432", so the API may be missing
val response = executeRequest<GetAliasesResponse>(eventBus) { val response = executeRequest<GetAliasesResponse>(globalErrorReceiver) {
apiCall = roomAPI.getAliases(roomId = params.roomId) apiCall = roomAPI.getAliases(roomId = params.roomId)
} }

Some files were not shown because too many files have changed in this diff Show More