Fix "uploads don't work with Room v6" #1558
This commit is contained in:
parent
6e0095edb0
commit
27207a27ae
|
@ -10,6 +10,7 @@ Improvements 🙌:
|
|||
Bugfix 🐛:
|
||||
- Fix theme issue on Room directory screen (#1613)
|
||||
- Fix notification not dismissing when entering a room
|
||||
- Fix uploads don't work with Room v6 (#1558)
|
||||
|
||||
Translations 🗣:
|
||||
-
|
||||
|
|
|
@ -116,6 +116,7 @@ dependencies {
|
|||
def markwon_version = '3.1.0'
|
||||
def daggerVersion = '2.25.4'
|
||||
def work_version = '2.3.3'
|
||||
def retrofit_version = '2.6.2'
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
|
||||
|
@ -128,8 +129,9 @@ dependencies {
|
|||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||
|
||||
// Network
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
|
||||
implementation 'com.squareup.retrofit2:converter-moshi:2.6.2'
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:converter-scalars:$retrofit_version"
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'
|
||||
implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
|
||||
|
|
|
@ -24,6 +24,7 @@ import okhttp3.OkHttpClient
|
|||
import okhttp3.Request
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RetrofitFactory @Inject constructor(private val moshi: Moshi) {
|
||||
|
@ -48,6 +49,7 @@ internal class RetrofitFactory @Inject constructor(private val moshi: Moshi) {
|
|||
return okHttpClient.get().newCall(request)
|
||||
}
|
||||
})
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(UnitConverterFactory)
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.build()
|
||||
|
|
|
@ -129,6 +129,21 @@ internal interface RoomAPI {
|
|||
@Body content: Content?
|
||||
): Call<SendResponse>
|
||||
|
||||
/**
|
||||
* Send an event to a room.
|
||||
*
|
||||
* @param txId the transaction Id
|
||||
* @param roomId the room id
|
||||
* @param eventType the event type
|
||||
* @param content the event content as string
|
||||
*/
|
||||
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send/{eventType}/{txId}")
|
||||
fun send(@Path("txId") txId: String,
|
||||
@Path("roomId") roomId: String,
|
||||
@Path("eventType") eventType: String,
|
||||
@Body content: String?
|
||||
): Call<SendResponse>
|
||||
|
||||
/**
|
||||
* Get the context surrounding an event.
|
||||
*
|
||||
|
|
|
@ -282,12 +282,6 @@ internal class DefaultSendService @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
||||
return SendEventWorker.Params(sessionId, event)
|
||||
.let { WorkerParamsFactory.toData(it) }
|
||||
.let { timelineSendEventWorkCommon.createWork<SendEventWorker>(it, startChain) }
|
||||
}
|
||||
|
||||
private fun createRedactEventWork(event: Event, reason: String?): OneTimeWorkRequest {
|
||||
return localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason)
|
||||
.also { createLocalEcho(it) }
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.squareup.moshi.JsonClass
|
|||
import im.vector.matrix.android.api.failure.shouldBeRetried
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.room.send.SendState
|
||||
import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.worker.SessionWorkerParams
|
||||
|
@ -43,9 +44,24 @@ internal class SendEventWorker(context: Context,
|
|||
@JsonClass(generateAdapter = true)
|
||||
internal data class Params(
|
||||
override val sessionId: String,
|
||||
val event: Event,
|
||||
//TODO remove after some time, it's used for compat
|
||||
val event: Event? = null,
|
||||
val eventId: String? = null,
|
||||
val roomId: String? = null,
|
||||
val type: String? = null,
|
||||
val contentStr: String? = null,
|
||||
override val lastFailureMessage: String? = null
|
||||
) : SessionWorkerParams
|
||||
) : SessionWorkerParams {
|
||||
|
||||
constructor(sessionId: String, event: Event, lastFailureMessage: String? = null) : this(
|
||||
sessionId = sessionId,
|
||||
eventId = event.eventId,
|
||||
roomId = event.roomId,
|
||||
type = event.type,
|
||||
contentStr = ContentMapper.map(event.content),
|
||||
lastFailureMessage = lastFailureMessage
|
||||
)
|
||||
}
|
||||
|
||||
@Inject lateinit var localEchoUpdater: LocalEchoUpdater
|
||||
@Inject lateinit var roomAPI: RoomAPI
|
||||
|
@ -59,41 +75,38 @@ internal class SendEventWorker(context: Context,
|
|||
val sessionComponent = getSessionComponent(params.sessionId) ?: return Result.success()
|
||||
sessionComponent.inject(this)
|
||||
|
||||
val event = params.event
|
||||
if (event.eventId == null) {
|
||||
if (params.eventId == null || params.roomId == null || params.type == null) {
|
||||
// compat with old params, make it fail if any
|
||||
if (params.event?.eventId != null) {
|
||||
localEchoUpdater.updateSendState(params.event.eventId, SendState.UNDELIVERED)
|
||||
}
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
if (params.lastFailureMessage != null) {
|
||||
localEchoUpdater.updateSendState(event.eventId, SendState.UNDELIVERED)
|
||||
localEchoUpdater.updateSendState(params.eventId, SendState.UNDELIVERED)
|
||||
// Transmit the error
|
||||
return Result.success(inputData)
|
||||
.also { Timber.e("Work cancelled due to input error from parent") }
|
||||
}
|
||||
return try {
|
||||
sendEvent(event)
|
||||
sendEvent(params.eventId, params.roomId, params.type, params.contentStr)
|
||||
Result.success()
|
||||
} catch (exception: Throwable) {
|
||||
if (exception.shouldBeRetried()) {
|
||||
Result.retry()
|
||||
} else {
|
||||
localEchoUpdater.updateSendState(event.eventId, SendState.UNDELIVERED)
|
||||
localEchoUpdater.updateSendState(params.eventId, SendState.UNDELIVERED)
|
||||
// always return success, or the chain will be stuck for ever!
|
||||
Result.success()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun sendEvent(event: Event) {
|
||||
localEchoUpdater.updateSendState(event.eventId!!, SendState.SENDING)
|
||||
private suspend fun sendEvent(eventId: String, roomId: String, type: String, contentStr: String?) {
|
||||
localEchoUpdater.updateSendState(eventId, SendState.SENDING)
|
||||
executeRequest<SendResponse>(eventBus) {
|
||||
apiCall = roomAPI.send(
|
||||
event.eventId,
|
||||
event.roomId!!,
|
||||
event.type,
|
||||
event.content
|
||||
)
|
||||
apiCall = roomAPI.send(eventId, roomId, type, contentStr)
|
||||
}
|
||||
localEchoUpdater.updateSendState(event.eventId, SendState.SENT)
|
||||
localEchoUpdater.updateSendState(eventId, SendState.SENT)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue