Merge branch 'develop' into feature/bma/displayname_fallback
This commit is contained in:
commit
8b15008eba
@ -15,6 +15,7 @@ Improvements 🙌:
|
|||||||
- Be more robust when parsing some enums
|
- Be more robust when parsing some enums
|
||||||
- Improve timeline filtering (dissociate membership and profile events, display hidden events when highlighted, fix hidden item/read receipts behavior)
|
- Improve timeline filtering (dissociate membership and profile events, display hidden events when highlighted, fix hidden item/read receipts behavior)
|
||||||
- Add better support for empty room name fallback (#3106)
|
- Add better support for empty room name fallback (#3106)
|
||||||
|
- Room list improvements (paging)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Fix bad theme change for the MainActivity
|
- Fix bad theme change for the MainActivity
|
||||||
@ -37,6 +38,7 @@ Test:
|
|||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
- Add version details on the login screen, in debug or developer mode
|
- Add version details on the login screen, in debug or developer mode
|
||||||
|
- Migrate Retrofit interface to coroutine calls
|
||||||
|
|
||||||
Changes in Element 1.1.3 (2021-03-18)
|
Changes in Element 1.1.3 (2021-03-18)
|
||||||
===================================================
|
===================================================
|
||||||
|
@ -16,7 +16,7 @@ buildscript {
|
|||||||
classpath 'com.google.gms:google-services:4.3.5'
|
classpath 'com.google.gms:google-services:4.3.5'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1'
|
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1'
|
||||||
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2'
|
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.3'
|
||||||
classpath "com.likethesalad.android:string-reference:1.2.1"
|
classpath "com.likethesalad.android:string-reference:1.2.1"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
@ -108,7 +108,7 @@ static def gitRevisionDate() {
|
|||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
def arrow_version = "0.8.2"
|
def arrow_version = "0.8.2"
|
||||||
def moshi_version = '1.11.0'
|
def moshi_version = '1.12.0'
|
||||||
def lifecycle_version = '2.2.0'
|
def lifecycle_version = '2.2.0'
|
||||||
def arch_version = '2.1.0'
|
def arch_version = '2.1.0'
|
||||||
def markwon_version = '3.1.0'
|
def markwon_version = '3.1.0'
|
||||||
@ -166,7 +166,7 @@ dependencies {
|
|||||||
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
||||||
|
|
||||||
// Phone number https://github.com/google/libphonenumber
|
// Phone number https://github.com/google/libphonenumber
|
||||||
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.20'
|
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.21'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.robolectric:robolectric:4.5.1'
|
testImplementation 'org.robolectric:robolectric:4.5.1'
|
||||||
|
@ -37,6 +37,18 @@ fun Throwable.shouldBeRetried(): Boolean {
|
|||||||
|| (this is Failure.ServerError && error.code == MatrixError.M_LIMIT_EXCEEDED)
|
|| (this is Failure.ServerError && error.code == MatrixError.M_LIMIT_EXCEEDED)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the retry delay in case of rate limit exceeded error, adding 100 ms, of defaultValue otherwise
|
||||||
|
*/
|
||||||
|
fun Throwable.getRetryDelay(defaultValue: Long): Long {
|
||||||
|
return (this as? Failure.ServerError)
|
||||||
|
?.error
|
||||||
|
?.takeIf { it.code == MatrixError.M_LIMIT_EXCEEDED }
|
||||||
|
?.retryAfterMillis
|
||||||
|
?.plus(100L)
|
||||||
|
?: defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
fun Throwable.isInvalidPassword(): Boolean {
|
fun Throwable.isInvalidPassword(): Boolean {
|
||||||
return this is Failure.ServerError
|
return this is Failure.ServerError
|
||||||
&& error.code == MatrixError.M_FORBIDDEN
|
&& error.code == MatrixError.M_FORBIDDEN
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 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.api.query
|
||||||
|
|
||||||
|
enum class RoomCategoryFilter {
|
||||||
|
ONLY_DM,
|
||||||
|
ONLY_ROOMS,
|
||||||
|
ONLY_WITH_NOTIFICATIONS,
|
||||||
|
ALL
|
||||||
|
}
|
@ -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.api.query
|
||||||
|
|
||||||
|
data class RoomTagQueryFilter(
|
||||||
|
val isFavorite: Boolean?,
|
||||||
|
val isLowPriority: Boolean?,
|
||||||
|
val isServerNotice: Boolean?
|
||||||
|
)
|
@ -17,6 +17,7 @@
|
|||||||
package org.matrix.android.sdk.api.session.room
|
package org.matrix.android.sdk.api.session.room
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.paging.PagedList
|
||||||
import org.matrix.android.sdk.api.MatrixCallback
|
import org.matrix.android.sdk.api.MatrixCallback
|
||||||
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.members.ChangeMembershipState
|
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
||||||
@ -24,6 +25,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
|||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
||||||
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
||||||
|
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
|
||||||
import org.matrix.android.sdk.api.util.Cancelable
|
import org.matrix.android.sdk.api.util.Cancelable
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription
|
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription
|
||||||
@ -178,4 +180,29 @@ interface RoomService {
|
|||||||
* This call will try to gather some information on this room, but it could fail and get nothing more
|
* This call will try to gather some information on this room, but it could fail and get nothing more
|
||||||
*/
|
*/
|
||||||
fun peekRoom(roomIdOrAlias: String, callback: MatrixCallback<PeekResult>)
|
fun peekRoom(roomIdOrAlias: String, callback: MatrixCallback<PeekResult>)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Doc
|
||||||
|
*/
|
||||||
|
fun getPagedRoomSummariesLive(queryParams: RoomSummaryQueryParams,
|
||||||
|
pagedListConfig: PagedList.Config = defaultPagedListConfig): LiveData<PagedList<RoomSummary>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Doc
|
||||||
|
*/
|
||||||
|
fun getFilteredPagedRoomSummariesLive(queryParams: RoomSummaryQueryParams,
|
||||||
|
pagedListConfig: PagedList.Config = defaultPagedListConfig): UpdatableFilterLivePageResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Doc
|
||||||
|
*/
|
||||||
|
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount
|
||||||
|
|
||||||
|
private val defaultPagedListConfig
|
||||||
|
get() = PagedList.Config.Builder()
|
||||||
|
.setPageSize(10)
|
||||||
|
.setInitialLoadSizeHint(20)
|
||||||
|
.setEnablePlaceholders(false)
|
||||||
|
.setPrefetchDistance(10)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
package org.matrix.android.sdk.api.session.room
|
package org.matrix.android.sdk.api.session.room
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
|
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||||
|
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
|
|
||||||
fun roomSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): RoomSummaryQueryParams {
|
fun roomSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): RoomSummaryQueryParams {
|
||||||
@ -31,7 +33,9 @@ data class RoomSummaryQueryParams(
|
|||||||
val roomId: QueryStringValue,
|
val roomId: QueryStringValue,
|
||||||
val displayName: QueryStringValue,
|
val displayName: QueryStringValue,
|
||||||
val canonicalAlias: QueryStringValue,
|
val canonicalAlias: QueryStringValue,
|
||||||
val memberships: List<Membership>
|
val memberships: List<Membership>,
|
||||||
|
val roomCategoryFilter: RoomCategoryFilter?,
|
||||||
|
val roomTagQueryFilter: RoomTagQueryFilter?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
class Builder {
|
class Builder {
|
||||||
@ -40,12 +44,16 @@ data class RoomSummaryQueryParams(
|
|||||||
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
|
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
|
||||||
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
|
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
|
||||||
var memberships: List<Membership> = Membership.all()
|
var memberships: List<Membership> = Membership.all()
|
||||||
|
var roomCategoryFilter: RoomCategoryFilter? = RoomCategoryFilter.ALL
|
||||||
|
var roomTagQueryFilter: RoomTagQueryFilter? = null
|
||||||
|
|
||||||
fun build() = RoomSummaryQueryParams(
|
fun build() = RoomSummaryQueryParams(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
canonicalAlias = canonicalAlias,
|
canonicalAlias = canonicalAlias,
|
||||||
memberships = memberships
|
memberships = memberships,
|
||||||
|
roomCategoryFilter = roomCategoryFilter,
|
||||||
|
roomTagQueryFilter = roomTagQueryFilter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 New Vector Ltd
|
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@ -14,12 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.app.features.home
|
package org.matrix.android.sdk.api.session.room
|
||||||
|
|
||||||
import im.vector.app.core.utils.BehaviorDataSource
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.paging.PagedList
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
interface UpdatableFilterLivePageResult {
|
||||||
class HomeRoomListDataSource @Inject constructor() : BehaviorDataSource<List<RoomSummary>>()
|
val livePagedList: LiveData<PagedList<RoomSummary>>
|
||||||
|
|
||||||
|
fun updateQuery(queryParams: RoomSummaryQueryParams)
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.session.room.summary
|
||||||
|
|
||||||
|
data class RoomAggregateNotificationCount(
|
||||||
|
val notificationCount: Int,
|
||||||
|
val highlightCount: Int
|
||||||
|
) {
|
||||||
|
val totalCount = notificationCount + highlightCount
|
||||||
|
val isHighlight = highlightCount > 0
|
||||||
|
}
|
@ -29,7 +29,6 @@ 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.auth.version.Versions
|
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Headers
|
import retrofit2.http.Headers
|
||||||
@ -45,26 +44,26 @@ internal interface AuthAPI {
|
|||||||
* Get a Riot config file, using the name including the domain
|
* Get a Riot config file, using the name including the domain
|
||||||
*/
|
*/
|
||||||
@GET("config.{domain}.json")
|
@GET("config.{domain}.json")
|
||||||
fun getRiotConfigDomain(@Path("domain") domain: String): Call<RiotConfig>
|
suspend fun getRiotConfigDomain(@Path("domain") domain: String): RiotConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Riot config file
|
* Get a Riot config file
|
||||||
*/
|
*/
|
||||||
@GET("config.json")
|
@GET("config.json")
|
||||||
fun getRiotConfig(): Call<RiotConfig>
|
suspend fun getRiotConfig(): RiotConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version information of the homeserver
|
* Get the version information of the homeserver
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
||||||
fun versions(): Call<Versions>
|
suspend fun versions(): Versions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register to the homeserver, or get error 401 with a RegistrationFlowResponse object if registration is incomplete
|
* Register to the homeserver, or get error 401 with a RegistrationFlowResponse object if registration is incomplete
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#account-registration-and-management
|
* Ref: https://matrix.org/docs/spec/client_server/latest#account-registration-and-management
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register")
|
||||||
fun register(@Body registrationParams: RegistrationParams): Call<Credentials>
|
suspend fun register(@Body registrationParams: RegistrationParams): Credentials
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add 3Pid during registration
|
* Add 3Pid during registration
|
||||||
@ -72,22 +71,22 @@ internal interface AuthAPI {
|
|||||||
* https://github.com/matrix-org/matrix-doc/pull/2290
|
* https://github.com/matrix-org/matrix-doc/pull/2290
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register/{threePid}/requestToken")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register/{threePid}/requestToken")
|
||||||
fun add3Pid(@Path("threePid") threePid: String,
|
suspend fun add3Pid(@Path("threePid") threePid: String,
|
||||||
@Body params: AddThreePidRegistrationParams): Call<AddThreePidRegistrationResponse>
|
@Body params: AddThreePidRegistrationParams): AddThreePidRegistrationResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate 3pid
|
* Validate 3pid
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
fun validate3Pid(@Url url: String,
|
suspend fun validate3Pid(@Url url: String,
|
||||||
@Body params: ValidationCodeBody): Call<SuccessResult>
|
@Body params: ValidationCodeBody): SuccessResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the supported login flow
|
* Get the supported login flow
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login
|
* Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
||||||
fun getLoginFlows(): Call<LoginFlowResponse>
|
suspend fun getLoginFlows(): LoginFlowResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass params to the server for the current login phase.
|
* Pass params to the server for the current login phase.
|
||||||
@ -97,22 +96,22 @@ internal interface AuthAPI {
|
|||||||
*/
|
*/
|
||||||
@Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000")
|
@Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000")
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
||||||
fun login(@Body loginParams: PasswordLoginParams): Call<Credentials>
|
suspend fun login(@Body loginParams: PasswordLoginParams): Credentials
|
||||||
|
|
||||||
// Unfortunately we cannot use interface for @Body parameter, so I duplicate the method for the type TokenLoginParams
|
// Unfortunately we cannot use interface for @Body parameter, so I duplicate the method for the type TokenLoginParams
|
||||||
@Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000")
|
@Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000")
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login")
|
||||||
fun login(@Body loginParams: TokenLoginParams): Call<Credentials>
|
suspend fun login(@Body loginParams: TokenLoginParams): Credentials
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the homeserver to reset the password associated with the provided email.
|
* Ask the homeserver to reset the password associated with the provided email.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password/email/requestToken")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password/email/requestToken")
|
||||||
fun resetPassword(@Body params: AddThreePidRegistrationParams): Call<AddThreePidRegistrationResponse>
|
suspend fun resetPassword(@Body params: AddThreePidRegistrationParams): AddThreePidRegistrationResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the homeserver to reset the password with the provided new password once the email is validated.
|
* Ask the homeserver to reset the password with the provided new password once the email is validated.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password")
|
||||||
fun resetPasswordMailConfirmed(@Body params: ResetPasswordMailConfirmed): Call<Unit>
|
suspend fun resetPasswordMailConfirmed(@Body params: ResetPasswordMailConfirmed)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ 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.appendParamToUrl
|
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.RiotConfig
|
import org.matrix.android.sdk.internal.auth.data.RiotConfig
|
||||||
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
||||||
import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard
|
import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard
|
||||||
@ -172,8 +171,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
// First check the homeserver version
|
// First check the homeserver version
|
||||||
return runCatching {
|
return runCatching {
|
||||||
executeRequest<Versions>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.versions()
|
authAPI.versions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { versions ->
|
.map { versions ->
|
||||||
@ -204,8 +203,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
// Ok, try to get the config.domain.json file of a RiotWeb client
|
// Ok, try to get the config.domain.json file of a RiotWeb client
|
||||||
return runCatching {
|
return runCatching {
|
||||||
executeRequest<RiotConfig>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.getRiotConfigDomain(domain)
|
authAPI.getRiotConfigDomain(domain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { riotConfig ->
|
.map { riotConfig ->
|
||||||
@ -232,8 +231,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
// Ok, try to get the config.json file of a RiotWeb client
|
// Ok, try to get the config.json file of a RiotWeb client
|
||||||
return runCatching {
|
return runCatching {
|
||||||
executeRequest<RiotConfig>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.getRiotConfig()
|
authAPI.getRiotConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { riotConfig ->
|
.map { riotConfig ->
|
||||||
@ -265,8 +264,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
||||||
|
|
||||||
val versions = executeRequest<Versions>(null) {
|
val versions = executeRequest(null) {
|
||||||
apiCall = newAuthAPI.versions()
|
newAuthAPI.versions()
|
||||||
}
|
}
|
||||||
|
|
||||||
return getLoginFlowResult(newAuthAPI, versions, defaultHomeServerUrl)
|
return getLoginFlowResult(newAuthAPI, versions, defaultHomeServerUrl)
|
||||||
@ -293,8 +292,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
||||||
|
|
||||||
val versions = executeRequest<Versions>(null) {
|
val versions = executeRequest(null) {
|
||||||
apiCall = newAuthAPI.versions()
|
newAuthAPI.versions()
|
||||||
}
|
}
|
||||||
|
|
||||||
getLoginFlowResult(newAuthAPI, versions, wellknownResult.homeServerUrl)
|
getLoginFlowResult(newAuthAPI, versions, wellknownResult.homeServerUrl)
|
||||||
@ -305,8 +304,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun getLoginFlowResult(authAPI: AuthAPI, versions: Versions, homeServerUrl: String): LoginFlowResult {
|
private suspend fun getLoginFlowResult(authAPI: AuthAPI, versions: Versions, homeServerUrl: String): LoginFlowResult {
|
||||||
// Get the login flow
|
// Get the login flow
|
||||||
val loginFlowResponse = executeRequest<LoginFlowResponse>(null) {
|
val loginFlowResponse = executeRequest(null) {
|
||||||
apiCall = authAPI.getLoginFlows()
|
authAPI.getLoginFlows()
|
||||||
}
|
}
|
||||||
return LoginFlowResult.Success(
|
return LoginFlowResult.Success(
|
||||||
loginFlowResponse.flows.orEmpty().mapNotNull { it.type },
|
loginFlowResponse.flows.orEmpty().mapNotNull { it.type },
|
||||||
|
@ -20,7 +20,6 @@ import dagger.Lazy
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse
|
|
||||||
import org.matrix.android.sdk.internal.di.Unauthenticated
|
import org.matrix.android.sdk.internal.di.Unauthenticated
|
||||||
import org.matrix.android.sdk.internal.network.RetrofitFactory
|
import org.matrix.android.sdk.internal.network.RetrofitFactory
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
@ -49,8 +48,8 @@ internal class DefaultIsValidClientServerApiTask @Inject constructor(
|
|||||||
.create(AuthAPI::class.java)
|
.create(AuthAPI::class.java)
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
executeRequest<LoginFlowResponse>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.getLoginFlows()
|
authAPI.getLoginFlows()
|
||||||
}
|
}
|
||||||
// We get a response, so the API is valid
|
// We get a response, so the API is valid
|
||||||
true
|
true
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.auth.login
|
package org.matrix.android.sdk.internal.auth.login
|
||||||
|
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
|
||||||
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
import org.matrix.android.sdk.api.auth.login.LoginWizard
|
||||||
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
|
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
@ -29,7 +28,6 @@ import org.matrix.android.sdk.internal.auth.data.ThreePidMedium
|
|||||||
import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
|
import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
|
||||||
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
||||||
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
|
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
|
||||||
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationResponse
|
|
||||||
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
|
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
|
|
||||||
@ -49,8 +47,8 @@ internal class DefaultLoginWizard(
|
|||||||
} else {
|
} else {
|
||||||
PasswordLoginParams.userIdentifier(login, password, deviceName)
|
PasswordLoginParams.userIdentifier(login, password, deviceName)
|
||||||
}
|
}
|
||||||
val credentials = executeRequest<Credentials>(null) {
|
val credentials = executeRequest(null) {
|
||||||
apiCall = authAPI.login(loginParams)
|
authAPI.login(loginParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
||||||
@ -63,8 +61,8 @@ internal class DefaultLoginWizard(
|
|||||||
val loginParams = TokenLoginParams(
|
val loginParams = TokenLoginParams(
|
||||||
token = loginToken
|
token = loginToken
|
||||||
)
|
)
|
||||||
val credentials = executeRequest<Credentials>(null) {
|
val credentials = executeRequest(null) {
|
||||||
apiCall = authAPI.login(loginParams)
|
authAPI.login(loginParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
||||||
@ -80,8 +78,8 @@ internal class DefaultLoginWizard(
|
|||||||
pendingSessionData = pendingSessionData.copy(sendAttempt = pendingSessionData.sendAttempt + 1)
|
pendingSessionData = pendingSessionData.copy(sendAttempt = pendingSessionData.sendAttempt + 1)
|
||||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
|
|
||||||
val result = executeRequest<AddThreePidRegistrationResponse>(null) {
|
val result = executeRequest(null) {
|
||||||
apiCall = authAPI.resetPassword(AddThreePidRegistrationParams.from(param))
|
authAPI.resetPassword(AddThreePidRegistrationParams.from(param))
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(newPassword, result))
|
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(newPassword, result))
|
||||||
@ -98,8 +96,8 @@ internal class DefaultLoginWizard(
|
|||||||
safeResetPasswordData.newPassword
|
safeResetPasswordData.newPassword
|
||||||
)
|
)
|
||||||
|
|
||||||
executeRequest<Unit>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.resetPasswordMailConfirmed(param)
|
authAPI.resetPasswordMailConfirmed(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set to null?
|
// Set to null?
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.auth.login
|
package org.matrix.android.sdk.internal.auth.login
|
||||||
|
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
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
|
||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
@ -59,19 +58,16 @@ internal class DefaultDirectLoginTask @Inject constructor(
|
|||||||
val loginParams = PasswordLoginParams.userIdentifier(params.userId, params.password, params.deviceName)
|
val loginParams = PasswordLoginParams.userIdentifier(params.userId, params.password, params.deviceName)
|
||||||
|
|
||||||
val credentials = try {
|
val credentials = try {
|
||||||
executeRequest<Credentials>(null) {
|
executeRequest(null) {
|
||||||
apiCall = authAPI.login(loginParams)
|
authAPI.login(loginParams)
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
when (throwable) {
|
throw when (throwable) {
|
||||||
is UnrecognizedCertificateException -> {
|
is UnrecognizedCertificateException -> Failure.UnrecognizedCertificateFailure(
|
||||||
throw Failure.UnrecognizedCertificateFailure(
|
homeServerUrl,
|
||||||
homeServerUrl,
|
throwable.fingerprint
|
||||||
throwable.fingerprint
|
)
|
||||||
)
|
else -> throwable
|
||||||
}
|
|
||||||
else ->
|
|
||||||
throw throwable
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ internal class DefaultRegisterAddThreePidTask(
|
|||||||
|
|
||||||
override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse {
|
override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse {
|
||||||
return executeRequest(null) {
|
return executeRequest(null) {
|
||||||
apiCall = authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params))
|
authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ internal class DefaultRegisterTask(
|
|||||||
override suspend fun execute(params: RegisterTask.Params): Credentials {
|
override suspend fun execute(params: RegisterTask.Params): Credentials {
|
||||||
try {
|
try {
|
||||||
return executeRequest(null) {
|
return executeRequest(null) {
|
||||||
apiCall = authAPI.register(params.registrationParams)
|
authAPI.register(params.registrationParams)
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
throw throwable.toRegistrationFlowResponse()
|
throw throwable.toRegistrationFlowResponse()
|
||||||
|
@ -33,7 +33,7 @@ internal class DefaultValidateCodeTask(
|
|||||||
|
|
||||||
override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult {
|
override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult {
|
||||||
return executeRequest(null) {
|
return executeRequest(null) {
|
||||||
apiCall = authAPI.validate3Pid(params.url, params.body)
|
authAPI.validate3Pid(params.url, params.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse
|
|||||||
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.crypto.model.rest.UploadSigningKeysBody
|
import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.HTTP
|
import retrofit2.http.HTTP
|
||||||
@ -46,14 +45,14 @@ internal interface CryptoApi {
|
|||||||
* Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices
|
* Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices")
|
||||||
fun getDevices(): Call<DevicesListResponse>
|
suspend fun getDevices(): DevicesListResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the device info by id
|
* Get the device info by id
|
||||||
* Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices-deviceid
|
* Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices-deviceid
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{deviceId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{deviceId}")
|
||||||
fun getDeviceInfo(@Path("deviceId") deviceId: String): Call<DeviceInfo>
|
suspend fun getDeviceInfo(@Path("deviceId") deviceId: String): DeviceInfo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload device and/or one-time keys.
|
* Upload device and/or one-time keys.
|
||||||
@ -62,7 +61,7 @@ internal interface CryptoApi {
|
|||||||
* @param body the keys to be sent.
|
* @param body the keys to be sent.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
|
||||||
fun uploadKeys(@Body body: KeysUploadBody): Call<KeysUploadResponse>
|
suspend fun uploadKeys(@Body body: KeysUploadBody): KeysUploadResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download device keys.
|
* Download device keys.
|
||||||
@ -71,7 +70,7 @@ internal interface CryptoApi {
|
|||||||
* @param params the params.
|
* @param params the params.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/query")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/query")
|
||||||
fun downloadKeysForUsers(@Body params: KeysQueryBody): Call<KeysQueryResponse>
|
suspend fun downloadKeysForUsers(@Body params: KeysQueryBody): KeysQueryResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CrossSigning - Uploading signing keys
|
* CrossSigning - Uploading signing keys
|
||||||
@ -79,7 +78,7 @@ internal interface CryptoApi {
|
|||||||
* This endpoint requires UI Auth.
|
* This endpoint requires UI Auth.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/device_signing/upload")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/device_signing/upload")
|
||||||
fun uploadSigningKeys(@Body params: UploadSigningKeysBody): Call<KeysQueryResponse>
|
suspend fun uploadSigningKeys(@Body params: UploadSigningKeysBody): KeysQueryResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CrossSigning - Uploading signatures
|
* CrossSigning - Uploading signatures
|
||||||
@ -98,7 +97,7 @@ internal interface CryptoApi {
|
|||||||
* However, signatures made for other users' keys, made by her user-signing key, will not be included.
|
* However, signatures made for other users' keys, made by her user-signing key, will not be included.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/signatures/upload")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/signatures/upload")
|
||||||
fun uploadSignatures(@Body params: Map<String, @JvmSuppressWildcards Any>?): Call<SignatureUploadResponse>
|
suspend fun uploadSignatures(@Body params: Map<String, @JvmSuppressWildcards Any>?): SignatureUploadResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Claim one-time keys.
|
* Claim one-time keys.
|
||||||
@ -107,7 +106,7 @@ internal interface CryptoApi {
|
|||||||
* @param params the params.
|
* @param params the params.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/claim")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/claim")
|
||||||
fun claimOneTimeKeysForUsersDevices(@Body body: KeysClaimBody): Call<KeysClaimResponse>
|
suspend fun claimOneTimeKeysForUsersDevices(@Body body: KeysClaimBody): KeysClaimResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an event to a specific list of devices
|
* Send an event to a specific list of devices
|
||||||
@ -118,9 +117,9 @@ internal interface CryptoApi {
|
|||||||
* @param body the body
|
* @param body the body
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sendToDevice/{eventType}/{txnId}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sendToDevice/{eventType}/{txnId}")
|
||||||
fun sendToDevice(@Path("eventType") eventType: String,
|
suspend fun sendToDevice(@Path("eventType") eventType: String,
|
||||||
@Path("txnId") transactionId: String,
|
@Path("txnId") transactionId: String,
|
||||||
@Body body: SendToDeviceBody): Call<Unit>
|
@Body body: SendToDeviceBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a device.
|
* Delete a device.
|
||||||
@ -130,8 +129,8 @@ internal interface CryptoApi {
|
|||||||
* @param params the deletion parameters
|
* @param params the deletion parameters
|
||||||
*/
|
*/
|
||||||
@HTTP(path = NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}", method = "DELETE", hasBody = true)
|
@HTTP(path = NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}", method = "DELETE", hasBody = true)
|
||||||
fun deleteDevice(@Path("device_id") deviceId: String,
|
suspend fun deleteDevice(@Path("device_id") deviceId: String,
|
||||||
@Body params: DeleteDeviceParams): Call<Unit>
|
@Body params: DeleteDeviceParams)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the device information.
|
* Update the device information.
|
||||||
@ -141,8 +140,8 @@ internal interface CryptoApi {
|
|||||||
* @param params the params
|
* @param params the params
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}")
|
||||||
fun updateDeviceInfo(@Path("device_id") deviceId: String,
|
suspend fun updateDeviceInfo(@Path("device_id") deviceId: String,
|
||||||
@Body params: UpdateDeviceInfoBody): Call<Unit>
|
@Body params: UpdateDeviceInfoBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the update devices list from two sync token.
|
* Get the update devices list from two sync token.
|
||||||
@ -152,6 +151,6 @@ internal interface CryptoApi {
|
|||||||
* @param newToken the up-to token.
|
* @param newToken the up-to token.
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/changes")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/changes")
|
||||||
fun getKeyChanges(@Query("from") oldToken: String,
|
suspend fun getKeyChanges(@Query("from") oldToken: String,
|
||||||
@Query("to") newToken: String): Call<KeyChangesResponse>
|
@Query("to") newToken: String): KeyChangesResponse
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionR
|
|||||||
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.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
|
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.DELETE
|
import retrofit2.http.DELETE
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -48,14 +47,14 @@ internal interface RoomKeysApi {
|
|||||||
* @param createKeysBackupVersionBody the body
|
* @param createKeysBackupVersionBody the body
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
|
||||||
fun createKeysBackupVersion(@Body createKeysBackupVersionBody: CreateKeysBackupVersionBody): Call<KeysVersion>
|
suspend fun createKeysBackupVersion(@Body createKeysBackupVersionBody: CreateKeysBackupVersionBody): KeysVersion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the key backup last version
|
* Get the key backup last version
|
||||||
* If not supported by the server, an error is returned: {"errcode":"M_NOT_FOUND","error":"No backup found"}
|
* If not supported by the server, an error is returned: {"errcode":"M_NOT_FOUND","error":"No backup found"}
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
|
||||||
fun getKeysBackupLastVersion(): Call<KeysVersionResult>
|
suspend fun getKeysBackupLastVersion(): KeysVersionResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about the given version.
|
* Get information about the given version.
|
||||||
@ -64,7 +63,7 @@ internal interface RoomKeysApi {
|
|||||||
* @param version version
|
* @param version version
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
||||||
fun getKeysBackupVersion(@Path("version") version: String): Call<KeysVersionResult>
|
suspend fun getKeysBackupVersion(@Path("version") version: String): KeysVersionResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update information about the given version.
|
* Update information about the given version.
|
||||||
@ -72,8 +71,8 @@ internal interface RoomKeysApi {
|
|||||||
* @param updateKeysBackupVersionBody the body
|
* @param updateKeysBackupVersionBody the body
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
||||||
fun updateKeysBackupVersion(@Path("version") version: String,
|
suspend fun updateKeysBackupVersion(@Path("version") version: String,
|
||||||
@Body keysBackupVersionBody: UpdateKeysBackupVersionBody): Call<Unit>
|
@Body keysBackupVersionBody: UpdateKeysBackupVersionBody)
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Storing keys
|
* Storing keys
|
||||||
@ -94,10 +93,10 @@ internal interface RoomKeysApi {
|
|||||||
* @param keyBackupData the data to send
|
* @param keyBackupData the data to send
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
||||||
fun storeRoomSessionData(@Path("roomId") roomId: String,
|
suspend fun storeRoomSessionData(@Path("roomId") roomId: String,
|
||||||
@Path("sessionId") sessionId: String,
|
@Path("sessionId") sessionId: String,
|
||||||
@Query("version") version: String,
|
@Query("version") version: String,
|
||||||
@Body keyBackupData: KeyBackupData): Call<BackupKeysResult>
|
@Body keyBackupData: KeyBackupData): BackupKeysResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store several keys for the given room, using the given backup version.
|
* Store several keys for the given room, using the given backup version.
|
||||||
@ -107,9 +106,9 @@ internal interface RoomKeysApi {
|
|||||||
* @param roomKeysBackupData the data to send
|
* @param roomKeysBackupData the data to send
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
||||||
fun storeRoomSessionsData(@Path("roomId") roomId: String,
|
suspend fun storeRoomSessionsData(@Path("roomId") roomId: String,
|
||||||
@Query("version") version: String,
|
@Query("version") version: String,
|
||||||
@Body roomKeysBackupData: RoomKeysBackupData): Call<BackupKeysResult>
|
@Body roomKeysBackupData: RoomKeysBackupData): BackupKeysResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store several keys, using the given backup version.
|
* Store several keys, using the given backup version.
|
||||||
@ -118,8 +117,8 @@ internal interface RoomKeysApi {
|
|||||||
* @param keysBackupData the data to send
|
* @param keysBackupData the data to send
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
||||||
fun storeSessionsData(@Query("version") version: String,
|
suspend fun storeSessionsData(@Query("version") version: String,
|
||||||
@Body keysBackupData: KeysBackupData): Call<BackupKeysResult>
|
@Body keysBackupData: KeysBackupData): BackupKeysResult
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Retrieving keys
|
* Retrieving keys
|
||||||
@ -133,9 +132,9 @@ internal interface RoomKeysApi {
|
|||||||
* @param version the version of the backup, or empty String to retrieve the last version
|
* @param version the version of the backup, or empty String to retrieve the last version
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
||||||
fun getRoomSessionData(@Path("roomId") roomId: String,
|
suspend fun getRoomSessionData(@Path("roomId") roomId: String,
|
||||||
@Path("sessionId") sessionId: String,
|
@Path("sessionId") sessionId: String,
|
||||||
@Query("version") version: String): Call<KeyBackupData>
|
@Query("version") version: String): KeyBackupData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all the keys for the given room from the backup.
|
* Retrieve all the keys for the given room from the backup.
|
||||||
@ -144,8 +143,8 @@ internal interface RoomKeysApi {
|
|||||||
* @param version the version of the backup, or empty String to retrieve the last version
|
* @param version the version of the backup, or empty String to retrieve the last version
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
||||||
fun getRoomSessionsData(@Path("roomId") roomId: String,
|
suspend fun getRoomSessionsData(@Path("roomId") roomId: String,
|
||||||
@Query("version") version: String): Call<RoomKeysBackupData>
|
@Query("version") version: String): RoomKeysBackupData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all the keys from the backup.
|
* Retrieve all the keys from the backup.
|
||||||
@ -153,7 +152,7 @@ internal interface RoomKeysApi {
|
|||||||
* @param version the version of the backup, or empty String to retrieve the last version
|
* @param version the version of the backup, or empty String to retrieve the last version
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
||||||
fun getSessionsData(@Query("version") version: String): Call<KeysBackupData>
|
suspend fun getSessionsData(@Query("version") version: String): KeysBackupData
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Deleting keys
|
* Deleting keys
|
||||||
@ -163,22 +162,22 @@ internal interface RoomKeysApi {
|
|||||||
* Deletes keys from the backup.
|
* Deletes keys from the backup.
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
|
||||||
fun deleteRoomSessionData(@Path("roomId") roomId: String,
|
suspend fun deleteRoomSessionData(@Path("roomId") roomId: String,
|
||||||
@Path("sessionId") sessionId: String,
|
@Path("sessionId") sessionId: String,
|
||||||
@Query("version") version: String): Call<Unit>
|
@Query("version") version: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes keys from the backup.
|
* Deletes keys from the backup.
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
|
||||||
fun deleteRoomSessionsData(@Path("roomId") roomId: String,
|
suspend fun deleteRoomSessionsData(@Path("roomId") roomId: String,
|
||||||
@Query("version") version: String): Call<Unit>
|
@Query("version") version: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes keys from the backup.
|
* Deletes keys from the backup.
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
|
||||||
fun deleteSessionsData(@Query("version") version: String): Call<Unit>
|
suspend fun deleteSessionsData(@Query("version") version: String)
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Deleting backup
|
* Deleting backup
|
||||||
@ -188,5 +187,5 @@ internal interface RoomKeysApi {
|
|||||||
* Deletes a backup.
|
* Deletes a backup.
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
|
||||||
fun deleteBackup(@Path("version") version: String): Call<Unit>
|
suspend fun deleteBackup(@Path("version") version: String)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ internal class DefaultCreateKeysBackupVersionTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
|
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.createKeysBackupVersion(params)
|
roomKeysApi.createKeysBackupVersion(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ internal class DefaultDeleteBackupTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: DeleteBackupTask.Params) {
|
override suspend fun execute(params: DeleteBackupTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.deleteBackup(params.version)
|
roomKeysApi.deleteBackup(params.version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ internal class DefaultDeleteRoomSessionDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
|
override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.deleteRoomSessionData(
|
roomKeysApi.deleteRoomSessionData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.sessionId,
|
params.sessionId,
|
||||||
params.version)
|
params.version)
|
||||||
|
@ -36,7 +36,7 @@ internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
|
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.deleteRoomSessionsData(
|
roomKeysApi.deleteRoomSessionsData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.version)
|
params.version)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ internal class DefaultDeleteSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: DeleteSessionsDataTask.Params) {
|
override suspend fun execute(params: DeleteSessionsDataTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.deleteSessionsData(params.version)
|
roomKeysApi.deleteSessionsData(params.version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: Unit): KeysVersionResult {
|
override suspend fun execute(params: Unit): KeysVersionResult {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.getKeysBackupLastVersion()
|
roomKeysApi.getKeysBackupLastVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ internal class DefaultGetKeysBackupVersionTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: String): KeysVersionResult {
|
override suspend fun execute(params: String): KeysVersionResult {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.getKeysBackupVersion(params)
|
roomKeysApi.getKeysBackupVersion(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ internal class DefaultGetRoomSessionDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
|
override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.getRoomSessionData(
|
roomKeysApi.getRoomSessionData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.sessionId,
|
params.sessionId,
|
||||||
params.version)
|
params.version)
|
||||||
|
@ -37,7 +37,7 @@ internal class DefaultGetRoomSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
|
override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.getRoomSessionsData(
|
roomKeysApi.getRoomSessionsData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.version)
|
params.version)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ internal class DefaultGetSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
|
override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.getSessionsData(params.version)
|
roomKeysApi.getSessionsData(params.version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ internal class DefaultStoreRoomSessionDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
|
override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.storeRoomSessionData(
|
roomKeysApi.storeRoomSessionData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.sessionId,
|
params.sessionId,
|
||||||
params.version,
|
params.version,
|
||||||
|
@ -39,7 +39,7 @@ internal class DefaultStoreRoomSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
|
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.storeRoomSessionsData(
|
roomKeysApi.storeRoomSessionsData(
|
||||||
params.roomId,
|
params.roomId,
|
||||||
params.version,
|
params.version,
|
||||||
params.roomKeysBackupData)
|
params.roomKeysBackupData)
|
||||||
|
@ -38,7 +38,7 @@ internal class DefaultStoreSessionsDataTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
|
override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.storeSessionsData(
|
roomKeysApi.storeSessionsData(
|
||||||
params.version,
|
params.version,
|
||||||
params.keysBackupData)
|
params.keysBackupData)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
|
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody)
|
roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi
|
|||||||
import org.matrix.android.sdk.internal.crypto.model.MXKey
|
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.network.GlobalErrorReceiver
|
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
|
||||||
@ -42,8 +41,8 @@ internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(
|
|||||||
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>(globalErrorReceiver) {
|
val keysClaimResponse = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body)
|
cryptoApi.claimOneTimeKeysForUsersDevices(body)
|
||||||
}
|
}
|
||||||
val map = MXUsersDevicesMap<MXKey>()
|
val map = MXUsersDevicesMap<MXKey>()
|
||||||
keysClaimResponse.oneTimeKeys?.let { oneTimeKeys ->
|
keysClaimResponse.oneTimeKeys?.let { oneTimeKeys ->
|
||||||
|
@ -42,8 +42,8 @@ internal class DefaultDeleteDeviceTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: DeleteDeviceTask.Params) {
|
override suspend fun execute(params: DeleteDeviceTask.Params) {
|
||||||
try {
|
try {
|
||||||
executeRequest<Unit>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams(params.userAuthParam?.asMap()))
|
cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams(params.userAuthParam?.asMap()))
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
if (params.userInteractiveAuthInterceptor == null
|
if (params.userInteractiveAuthInterceptor == null
|
||||||
|
@ -72,8 +72,8 @@ internal class DefaultDownloadKeysForUsers @Inject constructor(
|
|||||||
}
|
}
|
||||||
.map { body ->
|
.map { body ->
|
||||||
async {
|
async {
|
||||||
val result = executeRequest<KeysQueryResponse>(globalErrorReceiver) {
|
val result = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.downloadKeysForUsers(body)
|
cryptoApi.downloadKeysForUsers(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
@ -98,7 +98,7 @@ internal class DefaultDownloadKeysForUsers @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
// No need to chunk, direct request
|
// No need to chunk, direct request
|
||||||
executeRequest(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.downloadKeysForUsers(
|
cryptoApi.downloadKeysForUsers(
|
||||||
KeysQueryBody(
|
KeysQueryBody(
|
||||||
deviceKeys = params.userIds.associateWith { emptyList() },
|
deviceKeys = params.userIds.associateWith { emptyList() },
|
||||||
token = token
|
token = token
|
||||||
|
@ -34,7 +34,7 @@ internal class DefaultGetDeviceInfoTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo {
|
override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.getDeviceInfo(params.deviceId)
|
cryptoApi.getDeviceInfo(params.deviceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ internal class DefaultGetDevicesTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: Unit): DevicesListResponse {
|
override suspend fun execute(params: Unit): DevicesListResponse {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.getDevices()
|
cryptoApi.getDevices()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ internal class DefaultGetKeyChangesTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse {
|
override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.getKeyChanges(params.from, params.to)
|
cryptoApi.getKeyChanges(params.from, params.to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.crypto.tasks
|
|||||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
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.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -36,14 +35,14 @@ internal class DefaultRedactEventTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver) : 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>(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomAPI.redactEvent(
|
roomAPI.redactEvent(
|
||||||
txId = params.txID,
|
txId = params.txID,
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
eventId = params.eventId,
|
eventId = params.eventId,
|
||||||
reason = if (params.reason == null) emptyMap() else mapOf("reason" to params.reason)
|
reason = if (params.reason == null) emptyMap() else mapOf("reason" to params.reason)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return executeRequest.eventId
|
return response.eventId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ 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.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.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -52,8 +51,8 @@ internal class DefaultSendEventTask @Inject constructor(
|
|||||||
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>(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomAPI.send(
|
roomAPI.send(
|
||||||
localId,
|
localId,
|
||||||
roomId = event.roomId ?: "",
|
roomId = event.roomId ?: "",
|
||||||
content = event.content,
|
content = event.content,
|
||||||
@ -61,7 +60,7 @@ internal class DefaultSendEventTask @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENT)
|
localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENT)
|
||||||
return executeRequest.eventId
|
return response.eventId
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
// localEchoRepository.updateSendState(params.event.eventId!!, SendState.UNDELIVERED)
|
// localEchoRepository.updateSendState(params.event.eventId!!, SendState.UNDELIVERED)
|
||||||
throw e
|
throw e
|
||||||
|
@ -46,14 +46,16 @@ internal class DefaultSendToDeviceTask @Inject constructor(
|
|||||||
messages = params.contentMap.map
|
messages = params.contentMap.map
|
||||||
)
|
)
|
||||||
|
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(
|
||||||
apiCall = cryptoApi.sendToDevice(
|
globalErrorReceiver,
|
||||||
|
canRetry = true,
|
||||||
|
maxRetriesCount = 3
|
||||||
|
) {
|
||||||
|
cryptoApi.sendToDevice(
|
||||||
params.eventType,
|
params.eventType,
|
||||||
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(),
|
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(),
|
||||||
sendToDeviceBody
|
sendToDeviceBody
|
||||||
)
|
)
|
||||||
isRetryable = true
|
|
||||||
maxRetryCount = 3
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ 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
|
||||||
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
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -45,8 +44,8 @@ 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>(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = roomAPI.send(
|
roomAPI.send(
|
||||||
localId,
|
localId,
|
||||||
roomId = event.roomId ?: "",
|
roomId = event.roomId ?: "",
|
||||||
content = event.content,
|
content = event.content,
|
||||||
@ -54,7 +53,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
localEchoRepository.updateSendState(localId, event.roomId, SendState.SENT)
|
localEchoRepository.updateSendState(localId, event.roomId, SendState.SENT)
|
||||||
return executeRequest.eventId
|
return response.eventId
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
localEchoRepository.updateSendState(localId, event.roomId, SendState.UNDELIVERED)
|
localEchoRepository.updateSendState(localId, event.roomId, SendState.UNDELIVERED)
|
||||||
throw e
|
throw e
|
||||||
|
@ -42,7 +42,7 @@ internal class DefaultSetDeviceNameTask @Inject constructor(
|
|||||||
displayName = params.deviceName
|
displayName = params.deviceName
|
||||||
)
|
)
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body)
|
cryptoApi.updateDeviceInfo(params.deviceId, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ internal class DefaultUploadKeysTask @Inject constructor(
|
|||||||
Timber.i("## Uploading device keys -> $body")
|
Timber.i("## Uploading device keys -> $body")
|
||||||
|
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.uploadKeys(body)
|
cryptoApi.uploadKeys(body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ 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.network.GlobalErrorReceiver
|
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
|
||||||
@ -36,10 +35,12 @@ internal class DefaultUploadSignaturesTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: UploadSignaturesTask.Params) {
|
override suspend fun execute(params: UploadSignaturesTask.Params) {
|
||||||
try {
|
try {
|
||||||
val response = executeRequest<SignatureUploadResponse>(globalErrorReceiver) {
|
val response = executeRequest(
|
||||||
this.isRetryable = true
|
globalErrorReceiver,
|
||||||
this.maxRetryCount = 10
|
canRetry = true,
|
||||||
this.apiCall = cryptoApi.uploadSignatures(params.signatures)
|
maxRetriesCount = 10
|
||||||
|
) {
|
||||||
|
cryptoApi.uploadSignatures(params.signatures)
|
||||||
}
|
}
|
||||||
if (response.failures?.isNotEmpty() == true) {
|
if (response.failures?.isNotEmpty() == true) {
|
||||||
throw Throwable(response.failures.toString())
|
throw Throwable(response.failures.toString())
|
||||||
|
@ -19,7 +19,6 @@ 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.CryptoCrossSigningKey
|
import org.matrix.android.sdk.internal.crypto.model.CryptoCrossSigningKey
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
|
|
||||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||||
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.toRest
|
import org.matrix.android.sdk.internal.crypto.model.toRest
|
||||||
@ -61,8 +60,8 @@ internal class DefaultUploadSigningKeysTask @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) {
|
private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) {
|
||||||
val keysQueryResponse = executeRequest<KeysQueryResponse>(globalErrorReceiver) {
|
val keysQueryResponse = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = cryptoApi.uploadSigningKeys(uploadQuery)
|
cryptoApi.uploadSigningKeys(uploadQuery)
|
||||||
}
|
}
|
||||||
if (keysQueryResponse.failures?.isNotEmpty() == true) {
|
if (keysQueryResponse.failures?.isNotEmpty() == true) {
|
||||||
throw UploadSigningKeys(keysQueryResponse.failures)
|
throw UploadSigningKeys(keysQueryResponse.failures)
|
||||||
|
@ -17,22 +17,27 @@
|
|||||||
package org.matrix.android.sdk.internal.database
|
package org.matrix.android.sdk.internal.database
|
||||||
|
|
||||||
import io.realm.DynamicRealm
|
import io.realm.DynamicRealm
|
||||||
|
import io.realm.FieldAttribute
|
||||||
import io.realm.RealmMigration
|
import io.realm.RealmMigration
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
|
||||||
import org.matrix.android.sdk.internal.database.model.EditAggregatedSummaryEntityFields
|
import org.matrix.android.sdk.internal.database.model.EditAggregatedSummaryEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.EditionOfEventFields
|
import org.matrix.android.sdk.internal.database.model.EditionOfEventFields
|
||||||
|
import org.matrix.android.sdk.internal.database.model.EventEntityFields
|
||||||
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.RoomEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
|
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 org.matrix.android.sdk.internal.database.model.RoomTagEntityFields
|
||||||
|
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SESSION_STORE_SCHEMA_VERSION = 8L
|
const val SESSION_STORE_SCHEMA_VERSION = 9L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||||
@ -46,6 +51,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
|||||||
if (oldVersion <= 5) migrateTo6(realm)
|
if (oldVersion <= 5) migrateTo6(realm)
|
||||||
if (oldVersion <= 6) migrateTo7(realm)
|
if (oldVersion <= 6) migrateTo7(realm)
|
||||||
if (oldVersion <= 7) migrateTo8(realm)
|
if (oldVersion <= 7) migrateTo8(realm)
|
||||||
|
if (oldVersion <= 8) migrateTo9(realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun migrateTo1(realm: DynamicRealm) {
|
private fun migrateTo1(realm: DynamicRealm) {
|
||||||
@ -149,4 +155,43 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
|
|||||||
?.removeField("sourceLocalEchoEvents")
|
?.removeField("sourceLocalEchoEvents")
|
||||||
?.addRealmListField(EditAggregatedSummaryEntityFields.EDITIONS.`$`, editionOfEventSchema)
|
?.addRealmListField(EditAggregatedSummaryEntityFields.EDITIONS.`$`, editionOfEventSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun migrateTo9(realm: DynamicRealm) {
|
||||||
|
Timber.d("Step 8 -> 9")
|
||||||
|
|
||||||
|
realm.schema.get("RoomSummaryEntity")
|
||||||
|
?.addField(RoomSummaryEntityFields.LAST_ACTIVITY_TIME, Long::class.java, FieldAttribute.INDEXED)
|
||||||
|
?.setNullable(RoomSummaryEntityFields.LAST_ACTIVITY_TIME, true)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.MEMBERSHIP_STR)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.IS_DIRECT)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.VERSIONING_STATE_STR)
|
||||||
|
|
||||||
|
?.addField(RoomSummaryEntityFields.IS_FAVOURITE, Boolean::class.java)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.IS_FAVOURITE)
|
||||||
|
?.addField(RoomSummaryEntityFields.IS_LOW_PRIORITY, Boolean::class.java)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.IS_LOW_PRIORITY)
|
||||||
|
?.addField(RoomSummaryEntityFields.IS_SERVER_NOTICE, Boolean::class.java)
|
||||||
|
?.addIndex(RoomSummaryEntityFields.IS_SERVER_NOTICE)
|
||||||
|
|
||||||
|
?.transform { obj ->
|
||||||
|
|
||||||
|
val isFavorite = obj.getList(RoomSummaryEntityFields.TAGS.`$`).any {
|
||||||
|
it.getString(RoomTagEntityFields.TAG_NAME) == RoomTag.ROOM_TAG_FAVOURITE
|
||||||
|
}
|
||||||
|
obj.setBoolean(RoomSummaryEntityFields.IS_FAVOURITE, isFavorite)
|
||||||
|
|
||||||
|
val isLowPriority = obj.getList(RoomSummaryEntityFields.TAGS.`$`).any {
|
||||||
|
it.getString(RoomTagEntityFields.TAG_NAME) == RoomTag.ROOM_TAG_LOW_PRIORITY
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.setBoolean(RoomSummaryEntityFields.IS_LOW_PRIORITY, isLowPriority)
|
||||||
|
|
||||||
|
// XXX migrate last message origin server ts
|
||||||
|
obj.getObject(RoomSummaryEntityFields.LATEST_PREVIEWABLE_EVENT.`$`)
|
||||||
|
?.getObject(TimelineEventEntityFields.ROOT.`$`)
|
||||||
|
?.getLong(EventEntityFields.ORIGIN_SERVER_TS)?.let {
|
||||||
|
obj.setLong(RoomSummaryEntityFields.LAST_ACTIVITY_TIME, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
|
|||||||
private val typingUsersTracker: DefaultTypingUsersTracker) {
|
private val typingUsersTracker: DefaultTypingUsersTracker) {
|
||||||
|
|
||||||
fun map(roomSummaryEntity: RoomSummaryEntity): RoomSummary {
|
fun map(roomSummaryEntity: RoomSummaryEntity): RoomSummary {
|
||||||
val tags = roomSummaryEntity.tags.map {
|
val tags = roomSummaryEntity.tags().map {
|
||||||
RoomTag(it.tagName, it.tagOrder)
|
RoomTag(it.tagName, it.tagOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,61 +16,217 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.database.model
|
package org.matrix.android.sdk.internal.database.model
|
||||||
|
|
||||||
|
import io.realm.RealmList
|
||||||
|
import io.realm.RealmObject
|
||||||
|
import io.realm.annotations.Index
|
||||||
|
import io.realm.annotations.PrimaryKey
|
||||||
import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel
|
import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
import org.matrix.android.sdk.api.session.room.model.VersioningState
|
import org.matrix.android.sdk.api.session.room.model.VersioningState
|
||||||
import io.realm.RealmList
|
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
|
||||||
import io.realm.RealmObject
|
|
||||||
import io.realm.annotations.PrimaryKey
|
|
||||||
|
|
||||||
internal open class RoomSummaryEntity(
|
internal open class RoomSummaryEntity(
|
||||||
@PrimaryKey var roomId: String = "",
|
@PrimaryKey var roomId: String = ""
|
||||||
var displayName: String? = "",
|
|
||||||
var avatarUrl: String? = "",
|
|
||||||
var name: String? = "",
|
|
||||||
var topic: String? = "",
|
|
||||||
var latestPreviewableEvent: TimelineEventEntity? = null,
|
|
||||||
var heroes: RealmList<String> = RealmList(),
|
|
||||||
var joinedMembersCount: Int? = 0,
|
|
||||||
var invitedMembersCount: Int? = 0,
|
|
||||||
var isDirect: Boolean = false,
|
|
||||||
var directUserId: String? = null,
|
|
||||||
var otherMemberIds: RealmList<String> = RealmList(),
|
|
||||||
var notificationCount: Int = 0,
|
|
||||||
var highlightCount: Int = 0,
|
|
||||||
var readMarkerId: String? = null,
|
|
||||||
var hasUnreadMessages: Boolean = false,
|
|
||||||
var tags: RealmList<RoomTagEntity> = RealmList(),
|
|
||||||
var userDrafts: UserDraftsEntity? = null,
|
|
||||||
var breadcrumbsIndex: Int = RoomSummary.NOT_IN_BREADCRUMBS,
|
|
||||||
var canonicalAlias: String? = null,
|
|
||||||
var aliases: RealmList<String> = RealmList(),
|
|
||||||
// this is required for querying
|
|
||||||
var flatAliases: String = "",
|
|
||||||
var isEncrypted: Boolean = false,
|
|
||||||
var encryptionEventTs: Long? = 0,
|
|
||||||
var roomEncryptionTrustLevelStr: String? = null,
|
|
||||||
var inviterId: String? = null,
|
|
||||||
var hasFailedSending: Boolean = false
|
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
|
var displayName: String? = ""
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
var avatarUrl: String? = ""
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
var name: String? = ""
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
var topic: String? = ""
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var latestPreviewableEvent: TimelineEventEntity? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
|
var lastActivityTime: Long? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var heroes: RealmList<String> = RealmList()
|
||||||
|
|
||||||
|
var joinedMembersCount: Int? = 0
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var invitedMembersCount: Int? = 0
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
|
var isDirect: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var directUserId: String? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var otherMemberIds: RealmList<String> = RealmList()
|
||||||
|
|
||||||
|
var notificationCount: Int = 0
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var highlightCount: Int = 0
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var readMarkerId: String? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasUnreadMessages: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private var tags: RealmList<RoomTagEntity> = RealmList()
|
||||||
|
|
||||||
|
fun tags(): List<RoomTagEntity> = tags
|
||||||
|
|
||||||
|
fun updateTags(newTags: List<Pair<String, Double?>>) {
|
||||||
|
val toDelete = mutableListOf<RoomTagEntity>()
|
||||||
|
tags.forEach { existingTag ->
|
||||||
|
val updatedTag = newTags.firstOrNull { it.first == existingTag.tagName }
|
||||||
|
if (updatedTag == null) {
|
||||||
|
toDelete.add(existingTag)
|
||||||
|
} else {
|
||||||
|
existingTag.tagOrder = updatedTag.second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toDelete.forEach { it.deleteFromRealm() }
|
||||||
|
newTags.forEach { newTag ->
|
||||||
|
if (tags.all { it.tagName != newTag.first }) {
|
||||||
|
// we must add it
|
||||||
|
tags.add(
|
||||||
|
RoomTagEntity(newTag.first, newTag.second)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isFavourite = newTags.any { it.first == RoomTag.ROOM_TAG_FAVOURITE }
|
||||||
|
isLowPriority = newTags.any { it.first == RoomTag.ROOM_TAG_LOW_PRIORITY }
|
||||||
|
isServerNotice = newTags.any { it.first == RoomTag.ROOM_TAG_SERVER_NOTICE }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
|
var isFavourite: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
|
var isLowPriority: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
|
var isServerNotice: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var userDrafts: UserDraftsEntity? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var breadcrumbsIndex: Int = RoomSummary.NOT_IN_BREADCRUMBS
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var canonicalAlias: String? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var aliases: RealmList<String> = RealmList()
|
||||||
|
|
||||||
|
fun updateAliases(newAliases: List<String>) {
|
||||||
|
// only update underlying field if there is a diff
|
||||||
|
if (newAliases.distinct().sorted() != aliases.distinct().sorted()) {
|
||||||
|
aliases.clear()
|
||||||
|
aliases.addAll(newAliases)
|
||||||
|
flatAliases = newAliases.joinToString(separator = "|", prefix = "|")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is required for querying
|
||||||
|
var flatAliases: String = ""
|
||||||
|
|
||||||
|
var isEncrypted: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var encryptionEventTs: Long? = 0
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomEncryptionTrustLevelStr: String? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var inviterId: String? = null
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasFailedSending: Boolean = false
|
||||||
|
set(value) {
|
||||||
|
if (value != field) field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
private var membershipStr: String = Membership.NONE.name
|
private var membershipStr: String = Membership.NONE.name
|
||||||
|
|
||||||
var membership: Membership
|
var membership: Membership
|
||||||
get() {
|
get() {
|
||||||
return Membership.valueOf(membershipStr)
|
return Membership.valueOf(membershipStr)
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
membershipStr = value.name
|
if (value.name != membershipStr) {
|
||||||
|
membershipStr = value.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Index
|
||||||
private var versioningStateStr: String = VersioningState.NONE.name
|
private var versioningStateStr: String = VersioningState.NONE.name
|
||||||
var versioningState: VersioningState
|
var versioningState: VersioningState
|
||||||
get() {
|
get() {
|
||||||
return VersioningState.valueOf(versioningStateStr)
|
return VersioningState.valueOf(versioningStateStr)
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
versioningStateStr = value.name
|
if (value.name != versioningStateStr) {
|
||||||
|
versioningStateStr = value.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomEncryptionTrustLevel: RoomEncryptionTrustLevel?
|
var roomEncryptionTrustLevel: RoomEncryptionTrustLevel?
|
||||||
@ -84,7 +240,9 @@ internal open class RoomSummaryEntity(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
roomEncryptionTrustLevelStr = value?.name
|
if (value?.name != roomEncryptionTrustLevelStr) {
|
||||||
|
roomEncryptionTrustLevelStr = value?.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
|
@ -18,10 +18,9 @@
|
|||||||
package org.matrix.android.sdk.internal.federation
|
package org.matrix.android.sdk.internal.federation
|
||||||
|
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
|
||||||
internal interface FederationAPI {
|
internal interface FederationAPI {
|
||||||
@GET(NetworkConstants.URI_FEDERATION_PATH + "version")
|
@GET(NetworkConstants.URI_FEDERATION_PATH + "version")
|
||||||
fun getVersion(): Call<FederationGetVersionResult>
|
suspend fun getVersion(): FederationGetVersionResult
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ internal class DefaultGetFederationVersionTask @Inject constructor(
|
|||||||
) : GetFederationVersionTask {
|
) : GetFederationVersionTask {
|
||||||
|
|
||||||
override suspend fun execute(params: Unit): FederationVersion {
|
override suspend fun execute(params: Unit): FederationVersion {
|
||||||
val result = executeRequest<FederationGetVersionResult>(null) {
|
val result = executeRequest(null) {
|
||||||
apiCall = federationAPI.getVersion()
|
federationAPI.getVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
return FederationVersion(
|
return FederationVersion(
|
||||||
|
@ -19,38 +19,45 @@ 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.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
|
import org.matrix.android.sdk.api.failure.getRetryDelay
|
||||||
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
|
||||||
import retrofit2.Call
|
import retrofit2.HttpException
|
||||||
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(globalErrorReceiver: GlobalErrorReceiver?,
|
/**
|
||||||
block: Request<DATA>.() -> Unit) = Request<DATA>(globalErrorReceiver).apply(block).execute()
|
* Execute a request from the requestBlock and handle some of the Exception it could generate
|
||||||
|
*
|
||||||
|
* @param globalErrorReceiver will be use to notify error such as invalid token error. See [GlobalError]
|
||||||
|
* @param canRetry if set to true, the request will be executed again in case of error, after a delay
|
||||||
|
* @param initialDelayBeforeRetry the first delay to wait before a request is retried. Will be doubled after each retry
|
||||||
|
* @param maxDelayBeforeRetry the max delay to wait before a retry
|
||||||
|
* @param maxRetriesCount the max number of retries
|
||||||
|
* @param requestBlock a suspend lambda to perform the network request
|
||||||
|
*/
|
||||||
|
internal suspend inline fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
|
||||||
|
canRetry: Boolean = false,
|
||||||
|
initialDelayBeforeRetry: Long = 100L,
|
||||||
|
maxDelayBeforeRetry: Long = 10_000L,
|
||||||
|
maxRetriesCount: Int = Int.MAX_VALUE,
|
||||||
|
noinline requestBlock: suspend () -> DATA): DATA {
|
||||||
|
var currentRetryCount = 0
|
||||||
|
var currentDelay = initialDelayBeforeRetry
|
||||||
|
|
||||||
internal class Request<DATA : Any>(private val globalErrorReceiver: GlobalErrorReceiver?) {
|
while (true) {
|
||||||
|
try {
|
||||||
var isRetryable = false
|
return requestBlock()
|
||||||
var initialDelay: Long = 100L
|
} catch (throwable: Throwable) {
|
||||||
var maxDelay: Long = 10_000L
|
val exception = when (throwable) {
|
||||||
var maxRetryCount = Int.MAX_VALUE
|
is KotlinNullPointerException -> IllegalStateException("The request returned a null body")
|
||||||
private var currentRetryCount = 0
|
is HttpException -> throwable.toFailure(globalErrorReceiver)
|
||||||
private var currentDelay = initialDelay
|
else -> throwable
|
||||||
lateinit var apiCall: Call<DATA>
|
|
||||||
|
|
||||||
suspend fun execute(): DATA {
|
|
||||||
return try {
|
|
||||||
val response = apiCall.clone().awaitResponse()
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
response.body()
|
|
||||||
?: throw IllegalStateException("The request returned a null body")
|
|
||||||
} else {
|
|
||||||
throw response.toFailure(globalErrorReceiver)
|
|
||||||
}
|
}
|
||||||
} catch (exception: Throwable) {
|
|
||||||
// Log some details about the request which has failed
|
// Log some details about the request which has failed. This is less useful than before...
|
||||||
Timber.e("Exception when executing request ${apiCall.request().method} ${apiCall.request().url.toString().substringBefore("?")}")
|
// Timber.e("Exception when executing request ${apiCall.request().method} ${apiCall.request().url.toString().substringBefore("?")}")
|
||||||
|
Timber.e("Exception when executing request")
|
||||||
|
|
||||||
// Check if this is a certificateException
|
// Check if this is a certificateException
|
||||||
CertUtil.getCertificateException(exception)
|
CertUtil.getCertificateException(exception)
|
||||||
@ -61,10 +68,11 @@ internal class Request<DATA : Any>(private val globalErrorReceiver: GlobalErrorR
|
|||||||
// }
|
// }
|
||||||
?.also { unrecognizedCertificateException -> throw unrecognizedCertificateException }
|
?.also { unrecognizedCertificateException -> throw unrecognizedCertificateException }
|
||||||
|
|
||||||
if (isRetryable && currentRetryCount++ < maxRetryCount && exception.shouldBeRetried()) {
|
if (canRetry && currentRetryCount++ < maxRetriesCount && exception.shouldBeRetried()) {
|
||||||
delay(currentDelay)
|
// In case of 429, ensure we wait enough
|
||||||
currentDelay = (currentDelay * 2L).coerceAtMost(maxDelay)
|
delay(currentDelay.coerceAtLeast(exception.getRetryDelay(0)))
|
||||||
return execute()
|
currentDelay = currentDelay.times(2L).coerceAtMost(maxDelayBeforeRetry)
|
||||||
|
// Try again (loop)
|
||||||
} else {
|
} else {
|
||||||
throw when (exception) {
|
throw when (exception) {
|
||||||
is IOException -> Failure.NetworkConnection(exception)
|
is IOException -> Failure.NetworkConnection(exception)
|
||||||
|
@ -25,6 +25,7 @@ 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 retrofit2.HttpException
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -57,6 +58,13 @@ internal fun <T> Response<T>.toFailure(globalErrorReceiver: GlobalErrorReceiver?
|
|||||||
return toFailure(errorBody(), code(), globalErrorReceiver)
|
return toFailure(errorBody(), code(), globalErrorReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a HttpException to a Failure, and eventually parse errorBody to convert it to a MatrixError
|
||||||
|
*/
|
||||||
|
internal fun HttpException.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure {
|
||||||
|
return toFailure(response()?.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
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.raw
|
package org.matrix.android.sdk.internal.raw
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import okhttp3.ResponseBody
|
|
||||||
import org.matrix.android.sdk.api.cache.CacheStrategy
|
import org.matrix.android.sdk.api.cache.CacheStrategy
|
||||||
import org.matrix.android.sdk.internal.database.model.RawCacheEntity
|
import org.matrix.android.sdk.internal.database.model.RawCacheEntity
|
||||||
import org.matrix.android.sdk.internal.database.query.get
|
import org.matrix.android.sdk.internal.database.query.get
|
||||||
@ -58,8 +57,8 @@ internal class DefaultGetUrlTask @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun doRequest(url: String): String {
|
private suspend fun doRequest(url: String): String {
|
||||||
return executeRequest<ResponseBody>(null) {
|
return executeRequest(null) {
|
||||||
apiCall = rawAPI.getUrl(url)
|
rawAPI.getUrl(url)
|
||||||
}
|
}
|
||||||
.string()
|
.string()
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,10 @@
|
|||||||
package org.matrix.android.sdk.internal.raw
|
package org.matrix.android.sdk.internal.raw
|
||||||
|
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Url
|
import retrofit2.http.Url
|
||||||
|
|
||||||
internal interface RawAPI {
|
internal interface RawAPI {
|
||||||
@GET
|
@GET
|
||||||
fun getUrl(@Url url: String): Call<ResponseBody>
|
suspend fun getUrl(@Url url: String): ResponseBody
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.session.account
|
package org.matrix.android.sdk.internal.session.account
|
||||||
|
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ internal interface AccountAPI {
|
|||||||
* @param params parameters to change password.
|
* @param params parameters to change password.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password")
|
||||||
fun changePassword(@Body params: ChangePasswordParams): Call<Unit>
|
suspend fun changePassword(@Body params: ChangePasswordParams)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate the user account
|
* Deactivate the user account
|
||||||
@ -36,5 +35,5 @@ internal interface AccountAPI {
|
|||||||
* @param params the deactivate account params
|
* @param params the deactivate account params
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/deactivate")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/deactivate")
|
||||||
fun deactivate(@Body params: DeactivateAccountParams): Call<Unit>
|
suspend fun deactivate(@Body params: DeactivateAccountParams)
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ internal class DefaultChangePasswordTask @Inject constructor(
|
|||||||
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>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = accountAPI.changePassword(changePasswordParams)
|
accountAPI.changePassword(changePasswordParams)
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
val registrationFlowResponse = throwable.toRegistrationFlowResponse()
|
val registrationFlowResponse = throwable.toRegistrationFlowResponse()
|
||||||
@ -49,8 +49,8 @@ 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>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = accountAPI.changePassword(
|
accountAPI.changePassword(
|
||||||
changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session))
|
changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
|
|||||||
val deactivateAccountParams = DeactivateAccountParams.create(params.userAuthParam, params.eraseAllData)
|
val deactivateAccountParams = DeactivateAccountParams.create(params.userAuthParam, params.eraseAllData)
|
||||||
|
|
||||||
val canCleanup = try {
|
val canCleanup = try {
|
||||||
executeRequest<Unit>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = accountAPI.deactivate(deactivateAccountParams)
|
accountAPI.deactivate(deactivateAccountParams)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
|
@ -31,7 +31,7 @@ internal class DefaultGetTurnServerTask @Inject constructor(private val voipAPI:
|
|||||||
|
|
||||||
override suspend fun execute(params: Params): TurnServerResponse {
|
override suspend fun execute(params: Params): TurnServerResponse {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = voipAPI.getTurnServer()
|
voipAPI.getTurnServer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,10 @@ 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.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
|
||||||
internal interface VoipApi {
|
internal interface VoipApi {
|
||||||
|
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "voip/turnServer")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "voip/turnServer")
|
||||||
fun getTurnServer(): Call<TurnServerResponse>
|
suspend fun getTurnServer(): TurnServerResponse
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.directory
|
|||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasBody
|
import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasBody
|
||||||
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription
|
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.DELETE
|
import retrofit2.http.DELETE
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -33,7 +32,7 @@ internal interface DirectoryAPI {
|
|||||||
* @param roomAlias the room alias.
|
* @param roomAlias the room alias.
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
||||||
fun getRoomIdByAlias(@Path("roomAlias") roomAlias: String): Call<RoomAliasDescription>
|
suspend fun getRoomIdByAlias(@Path("roomAlias") roomAlias: String): RoomAliasDescription
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the room directory visibility.
|
* Get the room directory visibility.
|
||||||
@ -41,7 +40,7 @@ internal interface DirectoryAPI {
|
|||||||
* @param roomId the room id.
|
* @param roomId the room id.
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}")
|
||||||
fun getRoomDirectoryVisibility(@Path("roomId") roomId: String): Call<RoomDirectoryVisibilityJson>
|
suspend fun getRoomDirectoryVisibility(@Path("roomId") roomId: String): RoomDirectoryVisibilityJson
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the room directory visibility.
|
* Set the room directory visibility.
|
||||||
@ -50,21 +49,21 @@ internal interface DirectoryAPI {
|
|||||||
* @param body the body containing the new directory visibility
|
* @param body the body containing the new directory visibility
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}")
|
||||||
fun setRoomDirectoryVisibility(@Path("roomId") roomId: String,
|
suspend fun setRoomDirectoryVisibility(@Path("roomId") roomId: String,
|
||||||
@Body body: RoomDirectoryVisibilityJson): Call<Unit>
|
@Body body: RoomDirectoryVisibilityJson)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add alias to the room.
|
* Add alias to the room.
|
||||||
* @param roomAlias the room alias.
|
* @param roomAlias the room alias.
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
||||||
fun addRoomAlias(@Path("roomAlias") roomAlias: String,
|
suspend fun addRoomAlias(@Path("roomAlias") roomAlias: String,
|
||||||
@Body body: AddRoomAliasBody): Call<Unit>
|
@Body body: AddRoomAliasBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a room alias
|
* Delete a room alias
|
||||||
* @param roomAlias the room alias.
|
* @param roomAlias the room alias.
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}")
|
||||||
fun deleteRoomAlias(@Path("roomAlias") roomAlias: String): Call<Unit>
|
suspend fun deleteRoomAlias(@Path("roomAlias") roomAlias: String)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.session.filter
|
package org.matrix.android.sdk.internal.session.filter
|
||||||
|
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@ -32,8 +31,8 @@ internal interface FilterApi {
|
|||||||
* @param body the Json representation of a FilterBody object
|
* @param body the Json representation of a FilterBody object
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter")
|
||||||
fun uploadFilter(@Path("userId") userId: String,
|
suspend fun uploadFilter(@Path("userId") userId: String,
|
||||||
@Body body: Filter): Call<FilterResponse>
|
@Body body: Filter): FilterResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a filter with a given filterId from the homeserver
|
* Gets a filter with a given filterId from the homeserver
|
||||||
@ -43,6 +42,6 @@ internal interface FilterApi {
|
|||||||
* @return Filter
|
* @return Filter
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter/{filterId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter/{filterId}")
|
||||||
fun getFilterById(@Path("userId") userId: String,
|
suspend fun getFilterById(@Path("userId") userId: String,
|
||||||
@Path("filterId") filterId: String): Call<Filter>
|
@Path("filterId") filterId: String): Filter
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,9 @@ 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>(globalErrorReceiver) {
|
val filterResponse = executeRequest(globalErrorReceiver) {
|
||||||
// TODO auto retry
|
// TODO auto retry
|
||||||
apiCall = filterAPI.uploadFilter(userId, filterBody)
|
filterAPI.uploadFilter(userId, filterBody)
|
||||||
}
|
}
|
||||||
filterRepository.storeFilterId(filterBody, filterResponse.filterId)
|
filterRepository.storeFilterId(filterBody, filterResponse.filterId)
|
||||||
}
|
}
|
||||||
|
@ -64,14 +64,14 @@ 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>(globalErrorReceiver) {
|
val groupSummary = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = groupAPI.getSummary(groupId)
|
groupAPI.getSummary(groupId)
|
||||||
}
|
}
|
||||||
val groupRooms = executeRequest<GroupRooms>(globalErrorReceiver) {
|
val groupRooms = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = groupAPI.getRooms(groupId)
|
groupAPI.getRooms(groupId)
|
||||||
}
|
}
|
||||||
val groupUsers = executeRequest<GroupUsers>(globalErrorReceiver) {
|
val groupUsers = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = groupAPI.getUsers(groupId)
|
groupAPI.getUsers(groupId)
|
||||||
}
|
}
|
||||||
GroupData(groupId, groupSummary, groupRooms, groupUsers)
|
GroupData(groupId, groupSummary, groupRooms, groupUsers)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import org.matrix.android.sdk.internal.network.NetworkConstants
|
|||||||
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 retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Path
|
import retrofit2.http.Path
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ internal interface GroupAPI {
|
|||||||
* @param groupId the group id
|
* @param groupId the group id
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/summary")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/summary")
|
||||||
fun getSummary(@Path("groupId") groupId: String): Call<GroupSummaryResponse>
|
suspend fun getSummary(@Path("groupId") groupId: String): GroupSummaryResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the rooms list.
|
* Request the rooms list.
|
||||||
@ -40,7 +39,7 @@ internal interface GroupAPI {
|
|||||||
* @param groupId the group id
|
* @param groupId the group id
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/rooms")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/rooms")
|
||||||
fun getRooms(@Path("groupId") groupId: String): Call<GroupRooms>
|
suspend fun getRooms(@Path("groupId") groupId: String): GroupRooms
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the users list.
|
* Request the users list.
|
||||||
@ -48,5 +47,5 @@ internal interface GroupAPI {
|
|||||||
* @param groupId the group id
|
* @param groupId the group id
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/users")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/users")
|
||||||
fun getUsers(@Path("groupId") groupId: String): Call<GroupUsers>
|
suspend fun getUsers(@Path("groupId") groupId: String): GroupUsers
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.homeserver
|
|||||||
|
|
||||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
|
||||||
internal interface CapabilitiesAPI {
|
internal interface CapabilitiesAPI {
|
||||||
@ -26,17 +25,17 @@ internal interface CapabilitiesAPI {
|
|||||||
* Request the homeserver capabilities
|
* Request the homeserver capabilities
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "capabilities")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "capabilities")
|
||||||
fun getCapabilities(): Call<GetCapabilitiesResult>
|
suspend fun getCapabilities(): GetCapabilitiesResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the versions
|
* Request the versions
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
||||||
fun getVersions(): Call<Versions>
|
suspend fun getVersions(): Versions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ping the homeserver. We do not care about the returned data, so there is no use to parse them
|
* Ping the homeserver. We do not care about the returned data, so there is no use to parse them
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions")
|
||||||
fun ping(): Call<Unit>
|
suspend fun ping()
|
||||||
}
|
}
|
||||||
|
@ -71,20 +71,20 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val capabilities = runCatching {
|
val capabilities = runCatching {
|
||||||
executeRequest<GetCapabilitiesResult>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = capabilitiesAPI.getCapabilities()
|
capabilitiesAPI.getCapabilities()
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
val mediaConfig = runCatching {
|
val mediaConfig = runCatching {
|
||||||
executeRequest<GetMediaConfigResult>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = mediaAPI.getMediaConfig()
|
mediaAPI.getMediaConfig()
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
val versions = runCatching {
|
val versions = runCatching {
|
||||||
executeRequest<Versions>(null) {
|
executeRequest(null) {
|
||||||
apiCall = capabilitiesAPI.getVersions()
|
capabilitiesAPI.getVersions()
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ internal class HomeServerPinger @Inject constructor(private val taskExecutor: Ta
|
|||||||
|
|
||||||
suspend fun canReachHomeServer(): Boolean {
|
suspend fun canReachHomeServer(): Boolean {
|
||||||
return try {
|
return try {
|
||||||
executeRequest<Unit>(null) {
|
executeRequest(null) {
|
||||||
apiCall = capabilitiesAPI.ping()
|
capabilitiesAPI.ping()
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
|
@ -26,7 +26,6 @@ import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestOwn
|
|||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForEmailBody
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForEmailBody
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenResponse
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenResponse
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@ -43,20 +42,20 @@ internal interface IdentityAPI {
|
|||||||
* Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-account
|
* Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-account
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "account")
|
@GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "account")
|
||||||
fun getAccount(): Call<IdentityAccountResponse>
|
suspend fun getAccount(): IdentityAccountResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs out the access token, preventing it from being used to authenticate future requests to the server.
|
* Logs out the access token, preventing it from being used to authenticate future requests to the server.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/logout")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/logout")
|
||||||
fun logout(): Call<Unit>
|
suspend fun logout()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the hash detail to request a bunch of 3PIDs
|
* Request the hash detail to request a bunch of 3PIDs
|
||||||
* Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-hash-details
|
* Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-hash-details
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "hash_details")
|
@GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "hash_details")
|
||||||
fun hashDetails(): Call<IdentityHashDetailResponse>
|
suspend fun hashDetails(): IdentityHashDetailResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a bunch of 3PIDs
|
* Request a bunch of 3PIDs
|
||||||
@ -65,7 +64,7 @@ internal interface IdentityAPI {
|
|||||||
* @param body the body request
|
* @param body the body request
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "lookup")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "lookup")
|
||||||
fun lookup(@Body body: IdentityLookUpParams): Call<IdentityLookUpResponse>
|
suspend fun lookup(@Body body: IdentityLookUpParams): IdentityLookUpResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a session to change the bind status of an email to an identity server
|
* Create a session to change the bind status of an email to an identity server
|
||||||
@ -75,7 +74,7 @@ internal interface IdentityAPI {
|
|||||||
* @return the sid
|
* @return the sid
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/email/requestToken")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/email/requestToken")
|
||||||
fun requestTokenToBindEmail(@Body body: IdentityRequestTokenForEmailBody): Call<IdentityRequestTokenResponse>
|
suspend fun requestTokenToBindEmail(@Body body: IdentityRequestTokenForEmailBody): IdentityRequestTokenResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a session to change the bind status of an phone number to an identity server
|
* Create a session to change the bind status of an phone number to an identity server
|
||||||
@ -85,7 +84,7 @@ internal interface IdentityAPI {
|
|||||||
* @return the sid
|
* @return the sid
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/msisdn/requestToken")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/msisdn/requestToken")
|
||||||
fun requestTokenToBindMsisdn(@Body body: IdentityRequestTokenForMsisdnBody): Call<IdentityRequestTokenResponse>
|
suspend fun requestTokenToBindMsisdn(@Body body: IdentityRequestTokenForMsisdnBody): IdentityRequestTokenResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate ownership of an email address, or a phone number.
|
* Validate ownership of an email address, or a phone number.
|
||||||
@ -94,6 +93,6 @@ internal interface IdentityAPI {
|
|||||||
* - https://matrix.org/docs/spec/identity_service/latest#post-matrix-identity-v2-validate-email-submittoken
|
* - https://matrix.org/docs/spec/identity_service/latest#post-matrix-identity-v2-validate-email-submittoken
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/{medium}/submitToken")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/{medium}/submitToken")
|
||||||
fun submitToken(@Path("medium") medium: String,
|
suspend fun submitToken(@Path("medium") medium: String,
|
||||||
@Body body: IdentityRequestOwnershipParams): Call<SuccessResult>
|
@Body body: IdentityRequestOwnershipParams): SuccessResult
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.identity
|
|||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRegisterResponse
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRegisterResponse
|
||||||
import org.matrix.android.sdk.internal.session.openid.RequestOpenIdTokenResponse
|
import org.matrix.android.sdk.internal.session.openid.RequestOpenIdTokenResponse
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@ -40,18 +39,18 @@ internal interface IdentityAuthAPI {
|
|||||||
* @return 200 in case of success
|
* @return 200 in case of success
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_IDENTITY_PREFIX_PATH)
|
@GET(NetworkConstants.URI_IDENTITY_PREFIX_PATH)
|
||||||
fun ping(): Call<Unit>
|
suspend fun ping()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ping v1 will be used to check outdated Identity server
|
* Ping v1 will be used to check outdated Identity server
|
||||||
*/
|
*/
|
||||||
@GET("_matrix/identity/api/v1")
|
@GET("_matrix/identity/api/v1")
|
||||||
fun pingV1(): Call<Unit>
|
suspend fun pingV1()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exchanges an OpenID token from the homeserver for an access token to access the identity server.
|
* Exchanges an OpenID token from the homeserver for an access token to access the identity server.
|
||||||
* The request body is the same as the values returned by /openid/request_token in the Client-Server API.
|
* The request body is the same as the values returned by /openid/request_token in the Client-Server API.
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/register")
|
@POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/register")
|
||||||
fun register(@Body openIdToken: RequestOpenIdTokenResponse): Call<IdentityRegisterResponse>
|
suspend fun register(@Body openIdToken: RequestOpenIdTokenResponse): IdentityRegisterResponse
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
|
|||||||
return try {
|
return try {
|
||||||
LookUpData(hashedAddresses,
|
LookUpData(hashedAddresses,
|
||||||
executeRequest(null) {
|
executeRequest(null) {
|
||||||
apiCall = identityAPI.lookup(IdentityLookUpParams(
|
identityAPI.lookup(IdentityLookUpParams(
|
||||||
hashedAddresses,
|
hashedAddresses,
|
||||||
IdentityHashDetailResponse.ALGORITHM_SHA256,
|
IdentityHashDetailResponse.ALGORITHM_SHA256,
|
||||||
hashDetailResponse.pepper
|
hashDetailResponse.pepper
|
||||||
@ -126,7 +126,7 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun fetchHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse {
|
private suspend fun fetchHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse {
|
||||||
return executeRequest(null) {
|
return executeRequest(null) {
|
||||||
apiCall = identityAPI.hashDetails()
|
identityAPI.hashDetails()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ internal class DefaultIdentityDisconnectTask @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
executeRequest<Unit>(null) {
|
executeRequest(null) {
|
||||||
apiCall = identityAPI.logout()
|
identityAPI.logout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,14 @@ internal class DefaultIdentityPingTask @Inject constructor() : IdentityPingTask
|
|||||||
|
|
||||||
override suspend fun execute(params: IdentityPingTask.Params) {
|
override suspend fun execute(params: IdentityPingTask.Params) {
|
||||||
try {
|
try {
|
||||||
executeRequest<Unit>(null) {
|
executeRequest(null) {
|
||||||
apiCall = params.identityAuthAPI.ping()
|
params.identityAuthAPI.ping()
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
if (throwable is Failure.ServerError && throwable.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) {
|
if (throwable is Failure.ServerError && throwable.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) {
|
||||||
// Check if API v1 is available
|
// Check if API v1 is available
|
||||||
executeRequest<Unit>(null) {
|
executeRequest(null) {
|
||||||
apiCall = params.identityAuthAPI.pingV1()
|
params.identityAuthAPI.pingV1()
|
||||||
}
|
}
|
||||||
// API V1 is responding, but not V2 -> Outdated
|
// API V1 is responding, but not V2 -> Outdated
|
||||||
throw IdentityServiceError.OutdatedIdentityServer
|
throw IdentityServiceError.OutdatedIdentityServer
|
||||||
|
@ -33,7 +33,7 @@ internal class DefaultIdentityRegisterTask @Inject constructor() : IdentityRegis
|
|||||||
|
|
||||||
override suspend fun execute(params: IdentityRegisterTask.Params): IdentityRegisterResponse {
|
override suspend fun execute(params: IdentityRegisterTask.Params): IdentityRegisterResponse {
|
||||||
return executeRequest(null) {
|
return executeRequest(null) {
|
||||||
apiCall = params.identityAuthAPI.register(params.openIdTokenResponse)
|
params.identityAuthAPI.register(params.openIdTokenResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.session.identity.data.IdentityPendingBind
|
|||||||
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.model.IdentityRequestTokenForEmailBody
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForEmailBody
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody
|
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenResponse
|
|
||||||
import org.matrix.android.sdk.internal.task.Task
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -56,8 +55,8 @@ internal class DefaultIdentityRequestTokenForBindingTask @Inject constructor(
|
|||||||
val clientSecret = identityPendingBinding?.clientSecret ?: UUID.randomUUID().toString()
|
val clientSecret = identityPendingBinding?.clientSecret ?: UUID.randomUUID().toString()
|
||||||
val sendAttempt = identityPendingBinding?.sendAttempt?.inc() ?: 1
|
val sendAttempt = identityPendingBinding?.sendAttempt?.inc() ?: 1
|
||||||
|
|
||||||
val tokenResponse = executeRequest<IdentityRequestTokenResponse>(null) {
|
val tokenResponse = executeRequest(null) {
|
||||||
apiCall = when (params.threePid) {
|
when (params.threePid) {
|
||||||
is ThreePid.Email -> identityAPI.requestTokenToBindEmail(IdentityRequestTokenForEmailBody(
|
is ThreePid.Email -> identityAPI.requestTokenToBindEmail(IdentityRequestTokenForEmailBody(
|
||||||
clientSecret = clientSecret,
|
clientSecret = clientSecret,
|
||||||
sendAttempt = sendAttempt,
|
sendAttempt = sendAttempt,
|
||||||
|
@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.identity
|
|||||||
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.auth.registration.SuccessResult
|
|
||||||
import org.matrix.android.sdk.internal.di.UserId
|
import org.matrix.android.sdk.internal.di.UserId
|
||||||
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
|
||||||
@ -44,8 +43,8 @@ internal class DefaultIdentitySubmitTokenForBindingTask @Inject constructor(
|
|||||||
val identityAPI = getIdentityApiAndEnsureTerms(identityApiProvider, userId)
|
val identityAPI = getIdentityApiAndEnsureTerms(identityApiProvider, userId)
|
||||||
val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError
|
val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError
|
||||||
|
|
||||||
val tokenResponse = executeRequest<SuccessResult>(null) {
|
val tokenResponse = executeRequest(null) {
|
||||||
apiCall = identityAPI.submitToken(
|
identityAPI.submitToken(
|
||||||
params.threePid.toMedium(),
|
params.threePid.toMedium(),
|
||||||
IdentityRequestOwnershipParams(
|
IdentityRequestOwnershipParams(
|
||||||
clientSecret = identityPendingBinding.clientSecret,
|
clientSecret = identityPendingBinding.clientSecret,
|
||||||
|
@ -18,14 +18,13 @@ package org.matrix.android.sdk.internal.session.identity
|
|||||||
|
|
||||||
import org.matrix.android.sdk.api.session.identity.IdentityServiceError
|
import org.matrix.android.sdk.api.session.identity.IdentityServiceError
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
import org.matrix.android.sdk.internal.session.identity.model.IdentityAccountResponse
|
|
||||||
|
|
||||||
internal suspend fun getIdentityApiAndEnsureTerms(identityApiProvider: IdentityApiProvider, userId: String): IdentityAPI {
|
internal suspend fun getIdentityApiAndEnsureTerms(identityApiProvider: IdentityApiProvider, userId: String): IdentityAPI {
|
||||||
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
|
val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
|
|
||||||
// Always check that we have access to the service (regarding terms)
|
// Always check that we have access to the service (regarding terms)
|
||||||
val identityAccountResponse = executeRequest<IdentityAccountResponse>(null) {
|
val identityAccountResponse = executeRequest(null) {
|
||||||
apiCall = identityAPI.getAccount()
|
identityAPI.getAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(userId == identityAccountResponse.userId)
|
assert(userId == identityAccountResponse.userId)
|
||||||
|
@ -65,8 +65,8 @@ 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>(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = mediaAPI.getPreviewUrlData(url, timestamp)
|
mediaAPI.getPreviewUrlData(url, timestamp)
|
||||||
}
|
}
|
||||||
.toPreviewUrlData(url)
|
.toPreviewUrlData(url)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ internal class DefaultGetRawPreviewUrlTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
|
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = mediaAPI.getPreviewUrlData(params.url, params.timestamp)
|
mediaAPI.getPreviewUrlData(params.url, params.timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.media
|
|||||||
|
|
||||||
import org.matrix.android.sdk.api.util.JsonDict
|
import org.matrix.android.sdk.api.util.JsonDict
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ internal interface MediaAPI {
|
|||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-media-r0-config
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-media-r0-config
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "config")
|
@GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "config")
|
||||||
fun getMediaConfig(): Call<GetMediaConfigResult>
|
suspend fun getMediaConfig(): GetMediaConfigResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about a URL for the client. Typically this is called when a client
|
* Get information about a URL for the client. Typically this is called when a client
|
||||||
@ -39,5 +38,5 @@ internal interface MediaAPI {
|
|||||||
* if it does not have the requested version available.
|
* if it does not have the requested version available.
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "preview_url")
|
@GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "preview_url")
|
||||||
fun getPreviewUrlData(@Query("url") url: String, @Query("ts") ts: Long?): Call<JsonDict>
|
suspend fun getPreviewUrlData(@Query("url") url: String, @Query("ts") ts: Long?): JsonDict
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ internal class DefaultGetOpenIdTokenTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: Unit): RequestOpenIdTokenResponse {
|
override suspend fun execute(params: Unit): RequestOpenIdTokenResponse {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = openIdAPI.openIdToken(userId)
|
openIdAPI.openIdToken(userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.openid
|
|||||||
|
|
||||||
import org.matrix.android.sdk.api.util.JsonDict
|
import org.matrix.android.sdk.api.util.JsonDict
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.Path
|
import retrofit2.http.Path
|
||||||
@ -34,6 +33,6 @@ internal interface OpenIdAPI {
|
|||||||
* @param userId the user id
|
* @param userId the user id
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/openid/request_token")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/openid/request_token")
|
||||||
fun openIdToken(@Path("userId") userId: String,
|
suspend fun openIdToken(@Path("userId") userId: String,
|
||||||
@Body body: JsonDict = emptyMap()): Call<RequestOpenIdTokenResponse>
|
@Body body: JsonDict = emptyMap()): RequestOpenIdTokenResponse
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,14 @@ 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>(globalErrorReceiver) {
|
val body = AddEmailBody(
|
||||||
val body = AddEmailBody(
|
clientSecret = clientSecret,
|
||||||
clientSecret = clientSecret,
|
email = threePid.email,
|
||||||
email = threePid.email,
|
sendAttempt = sendAttempt
|
||||||
sendAttempt = sendAttempt
|
)
|
||||||
)
|
|
||||||
apiCall = profileAPI.addEmail(body)
|
val result = executeRequest(globalErrorReceiver) {
|
||||||
|
profileAPI.addEmail(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store as a pending three pid
|
// Store as a pending three pid
|
||||||
@ -84,14 +85,15 @@ 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>(globalErrorReceiver) {
|
val body = AddMsisdnBody(
|
||||||
val body = AddMsisdnBody(
|
clientSecret = clientSecret,
|
||||||
clientSecret = clientSecret,
|
country = country,
|
||||||
country = country,
|
phoneNumber = parsedNumber.nationalNumber.toString(),
|
||||||
phoneNumber = parsedNumber.nationalNumber.toString(),
|
sendAttempt = sendAttempt
|
||||||
sendAttempt = sendAttempt
|
)
|
||||||
)
|
|
||||||
apiCall = profileAPI.addMsisdn(body)
|
val result = executeRequest(globalErrorReceiver) {
|
||||||
|
profileAPI.addMsisdn(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store as a pending three pid
|
// Store as a pending three pid
|
||||||
|
@ -43,8 +43,8 @@ internal class DefaultBindThreePidsTask @Inject constructor(private val profileA
|
|||||||
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>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.bindThreePid(
|
profileAPI.bindThreePid(
|
||||||
BindThreePidBody(
|
BindThreePidBody(
|
||||||
clientSecret = identityPendingBinding.clientSecret,
|
clientSecret = identityPendingBinding.clientSecret,
|
||||||
identityServerUrlWithoutProtocol = identityServerUrlWithoutProtocol,
|
identityServerUrlWithoutProtocol = identityServerUrlWithoutProtocol,
|
||||||
|
@ -34,12 +34,12 @@ internal class DefaultDeleteThreePidTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver) : DeleteThreePidTask() {
|
private val globalErrorReceiver: GlobalErrorReceiver) : DeleteThreePidTask() {
|
||||||
|
|
||||||
override suspend fun execute(params: Params) {
|
override suspend fun execute(params: Params) {
|
||||||
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
|
)
|
||||||
)
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.deleteThreePid(body)
|
profileAPI.deleteThreePid(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not really care about the result for the moment
|
// We do not really care about the result for the moment
|
||||||
|
@ -61,13 +61,13 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
|
|||||||
?: throw IllegalArgumentException("unknown threepid")
|
?: throw IllegalArgumentException("unknown threepid")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executeRequest<Unit>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
val body = FinalizeAddThreePidBody(
|
val body = FinalizeAddThreePidBody(
|
||||||
clientSecret = pendingThreePids.clientSecret,
|
clientSecret = pendingThreePids.clientSecret,
|
||||||
sid = pendingThreePids.sid,
|
sid = pendingThreePids.sid,
|
||||||
auth = params.userAuthParam?.asMap()
|
auth = params.userAuthParam?.asMap()
|
||||||
)
|
)
|
||||||
apiCall = profileAPI.finalizeAddThreePid(body)
|
profileAPI.finalizeAddThreePid(body)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
|
@ -34,7 +34,7 @@ internal class DefaultGetProfileInfoTask @Inject constructor(private val profile
|
|||||||
|
|
||||||
override suspend fun execute(params: Params): JsonDict {
|
override suspend fun execute(params: Params): JsonDict {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.getProfile(params.userId)
|
profileAPI.getProfile(params.userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import org.matrix.android.sdk.api.util.JsonDict
|
|||||||
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.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@ -37,70 +36,70 @@ internal interface ProfileAPI {
|
|||||||
* @param userId the user id to fetch profile info
|
* @param userId the user id to fetch profile info
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}")
|
||||||
fun getProfile(@Path("userId") userId: String): Call<JsonDict>
|
suspend fun getProfile(@Path("userId") userId: String): JsonDict
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all 3PIDs linked to the Matrix user account.
|
* List all 3PIDs linked to the Matrix user account.
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid")
|
||||||
fun getThreePIDs(): Call<AccountThreePidsResponse>
|
suspend fun getThreePIDs(): AccountThreePidsResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change user display name
|
* Change user display name
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/displayname")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/displayname")
|
||||||
fun setDisplayName(@Path("userId") userId: String,
|
suspend fun setDisplayName(@Path("userId") userId: String,
|
||||||
@Body body: SetDisplayNameBody): Call<Unit>
|
@Body body: SetDisplayNameBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change user avatar url.
|
* Change user avatar url.
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/avatar_url")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/avatar_url")
|
||||||
fun setAvatarUrl(@Path("userId") userId: String,
|
suspend fun setAvatarUrl(@Path("userId") userId: String,
|
||||||
@Body body: SetAvatarUrlBody): Call<Unit>
|
@Body body: SetAvatarUrlBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind a threePid
|
* Bind a threePid
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-bind
|
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-bind
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/bind")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/bind")
|
||||||
fun bindThreePid(@Body body: BindThreePidBody): Call<Unit>
|
suspend fun bindThreePid(@Body body: BindThreePidBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unbind a threePid
|
* Unbind a threePid
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-unbind
|
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-unbind
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/unbind")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/unbind")
|
||||||
fun unbindThreePid(@Body body: UnbindThreePidBody): Call<UnbindThreePidResponse>
|
suspend fun unbindThreePid(@Body body: UnbindThreePidBody): UnbindThreePidResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-email-requesttoken
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-email-requesttoken
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/email/requestToken")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/email/requestToken")
|
||||||
fun addEmail(@Body body: AddEmailBody): Call<AddEmailResponse>
|
suspend fun addEmail(@Body body: AddEmailBody): AddEmailResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-msisdn-requesttoken
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-msisdn-requesttoken
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/msisdn/requestToken")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/msisdn/requestToken")
|
||||||
fun addMsisdn(@Body body: AddMsisdnBody): Call<AddMsisdnResponse>
|
suspend fun addMsisdn(@Body body: AddMsisdnBody): AddMsisdnResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate Msisdn code (same model than for Identity server API)
|
* Validate Msisdn code (same model than for Identity server API)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
fun validateMsisdn(@Url url: String,
|
suspend fun validateMsisdn(@Url url: String,
|
||||||
@Body params: ValidationCodeBody): Call<SuccessResult>
|
@Body params: ValidationCodeBody): SuccessResult
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-add
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-add
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/add")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/add")
|
||||||
fun finalizeAddThreePid(@Body body: FinalizeAddThreePidBody): Call<Unit>
|
suspend fun finalizeAddThreePid(@Body body: FinalizeAddThreePidBody)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-delete
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-delete
|
||||||
*/
|
*/
|
||||||
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/delete")
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/delete")
|
||||||
fun deleteThreePid(@Body body: DeleteThreePidBody): Call<DeleteThreePidResponse>
|
suspend fun deleteThreePid(@Body body: DeleteThreePidBody): DeleteThreePidResponse
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val p
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() {
|
private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() {
|
||||||
|
|
||||||
override suspend fun execute(params: Unit) {
|
override suspend fun execute(params: Unit) {
|
||||||
val accountThreePidsResponse = executeRequest<AccountThreePidsResponse>(globalErrorReceiver) {
|
val accountThreePidsResponse = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.getThreePIDs()
|
profileAPI.getThreePIDs()
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.d("Get ${accountThreePidsResponse.threePids?.size} threePids")
|
Timber.d("Get ${accountThreePidsResponse.threePids?.size} threePids")
|
||||||
|
@ -33,11 +33,11 @@ internal class DefaultSetAvatarUrlTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() {
|
private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() {
|
||||||
|
|
||||||
override suspend fun execute(params: Params) {
|
override suspend fun execute(params: Params) {
|
||||||
|
val body = SetAvatarUrlBody(
|
||||||
|
avatarUrl = params.newAvatarUrl
|
||||||
|
)
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
val body = SetAvatarUrlBody(
|
profileAPI.setAvatarUrl(params.userId, body)
|
||||||
avatarUrl = params.newAvatarUrl
|
|
||||||
)
|
|
||||||
apiCall = profileAPI.setAvatarUrl(params.userId, body)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ internal class DefaultSetDisplayNameTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver) : SetDisplayNameTask() {
|
private val globalErrorReceiver: GlobalErrorReceiver) : SetDisplayNameTask() {
|
||||||
|
|
||||||
override suspend fun execute(params: Params) {
|
override suspend fun execute(params: Params) {
|
||||||
|
val body = SetDisplayNameBody(
|
||||||
|
displayName = params.newDisplayName
|
||||||
|
)
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
val body = SetDisplayNameBody(
|
profileAPI.setDisplayName(params.userId, body)
|
||||||
displayName = params.newDisplayName
|
|
||||||
)
|
|
||||||
apiCall = profileAPI.setDisplayName(params.userId, body)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ internal class DefaultUnbindThreePidsTask @Inject constructor(private val profil
|
|||||||
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol()
|
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol()
|
||||||
?: throw IdentityServiceError.NoIdentityServerConfigured
|
?: throw IdentityServiceError.NoIdentityServerConfigured
|
||||||
|
|
||||||
return executeRequest<UnbindThreePidResponse>(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.unbindThreePid(
|
profileAPI.unbindThreePid(
|
||||||
UnbindThreePidBody(
|
UnbindThreePidBody(
|
||||||
identityServerUrlWithoutProtocol,
|
identityServerUrlWithoutProtocol,
|
||||||
params.threePid.toMedium(),
|
params.threePid.toMedium(),
|
||||||
|
@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.profile
|
|||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
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.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
|
||||||
@ -58,8 +57,8 @@ internal class DefaultValidateSmsCodeTask @Inject constructor(
|
|||||||
sid = pendingThreePids.sid,
|
sid = pendingThreePids.sid,
|
||||||
code = params.code
|
code = params.code
|
||||||
)
|
)
|
||||||
val result = executeRequest<SuccessResult>(globalErrorReceiver) {
|
val result = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = profileAPI.validateMsisdn(url, body)
|
profileAPI.validateMsisdn(url, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
|
@ -81,8 +81,8 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun setPusher(pusher: JsonPusher) {
|
private suspend fun setPusher(pusher: JsonPusher) {
|
||||||
executeRequest<Unit>(globalErrorReceiver) {
|
executeRequest(globalErrorReceiver) {
|
||||||
apiCall = pushersAPI.setPusher(pusher)
|
pushersAPI.setPusher(pusher)
|
||||||
}
|
}
|
||||||
monarchy.awaitTransaction { realm ->
|
monarchy.awaitTransaction { realm ->
|
||||||
val echo = PusherEntity.where(realm, pusher.pushKey).findFirst()
|
val echo = PusherEntity.where(realm, pusher.pushKey).findFirst()
|
||||||
|
@ -36,7 +36,7 @@ internal class DefaultAddPushRuleTask @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun execute(params: AddPushRuleTask.Params) {
|
override suspend fun execute(params: AddPushRuleTask.Params) {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
|
pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
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.internal.network.GlobalErrorReceiver
|
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
|
||||||
@ -35,8 +34,8 @@ internal class DefaultGetPushRulesTask @Inject constructor(
|
|||||||
) : GetPushRulesTask {
|
) : GetPushRulesTask {
|
||||||
|
|
||||||
override suspend fun execute(params: GetPushRulesTask.Params) {
|
override suspend fun execute(params: GetPushRulesTask.Params) {
|
||||||
val response = executeRequest<GetPushRulesResponse>(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = pushRulesApi.getAllRules()
|
pushRulesApi.getAllRules()
|
||||||
}
|
}
|
||||||
|
|
||||||
savePushRulesTask.execute(SavePushRulesTask.Params(response))
|
savePushRulesTask.execute(SavePushRulesTask.Params(response))
|
||||||
|
@ -36,8 +36,8 @@ internal class DefaultGetPushersTask @Inject constructor(
|
|||||||
) : GetPushersTask {
|
) : GetPushersTask {
|
||||||
|
|
||||||
override suspend fun execute(params: Unit) {
|
override suspend fun execute(params: Unit) {
|
||||||
val response = executeRequest<GetPushersResponse>(globalErrorReceiver) {
|
val response = executeRequest(globalErrorReceiver) {
|
||||||
apiCall = pushersAPI.getPushers()
|
pushersAPI.getPushers()
|
||||||
}
|
}
|
||||||
monarchy.awaitTransaction { realm ->
|
monarchy.awaitTransaction { realm ->
|
||||||
// clear existings?
|
// clear existings?
|
||||||
|
@ -18,7 +18,6 @@ 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.api.pushrules.rest.PushRule
|
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||||
import org.matrix.android.sdk.internal.network.NetworkConstants
|
import org.matrix.android.sdk.internal.network.NetworkConstants
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.DELETE
|
import retrofit2.http.DELETE
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@ -30,7 +29,7 @@ internal interface PushRulesApi {
|
|||||||
* Get all push rules
|
* Get all push rules
|
||||||
*/
|
*/
|
||||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/")
|
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/")
|
||||||
fun getAllRules(): Call<GetPushRulesResponse>
|
suspend fun getAllRules(): GetPushRulesResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the ruleID enable status
|
* Update the ruleID enable status
|
||||||
@ -40,10 +39,9 @@ internal interface PushRulesApi {
|
|||||||
* @param enable the new enable status
|
* @param enable the new enable status
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled")
|
||||||
fun updateEnableRuleStatus(@Path("kind") kind: String,
|
suspend fun updateEnableRuleStatus(@Path("kind") kind: String,
|
||||||
@Path("ruleId") ruleId: String,
|
@Path("ruleId") ruleId: String,
|
||||||
@Body enable: Boolean?)
|
@Body enable: Boolean?)
|
||||||
: Call<Unit>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the ruleID action
|
* Update the ruleID action
|
||||||
@ -54,10 +52,9 @@ internal interface PushRulesApi {
|
|||||||
* @param actions the actions
|
* @param actions the actions
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions")
|
||||||
fun updateRuleActions(@Path("kind") kind: String,
|
suspend fun updateRuleActions(@Path("kind") kind: String,
|
||||||
@Path("ruleId") ruleId: String,
|
@Path("ruleId") ruleId: String,
|
||||||
@Body actions: Any)
|
@Body actions: Any)
|
||||||
: Call<Unit>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a rule
|
* Delete a rule
|
||||||
@ -66,9 +63,8 @@ internal interface PushRulesApi {
|
|||||||
* @param ruleId the ruleId
|
* @param ruleId the ruleId
|
||||||
*/
|
*/
|
||||||
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
|
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
|
||||||
fun deleteRule(@Path("kind") kind: String,
|
suspend fun deleteRule(@Path("kind") kind: String,
|
||||||
@Path("ruleId") ruleId: String)
|
@Path("ruleId") ruleId: String)
|
||||||
: Call<Unit>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the ruleID enable status
|
* Add the ruleID enable status
|
||||||
@ -78,8 +74,7 @@ internal interface PushRulesApi {
|
|||||||
* @param rule the rule to add.
|
* @param rule the rule to add.
|
||||||
*/
|
*/
|
||||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
|
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}")
|
||||||
fun addRule(@Path("kind") kind: String,
|
suspend fun addRule(@Path("kind") kind: String,
|
||||||
@Path("ruleId") ruleId: String,
|
@Path("ruleId") ruleId: String,
|
||||||
@Body rule: PushRule)
|
@Body rule: PushRule)
|
||||||
: Call<Unit>
|
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user