Compare commits

...

1 Commits

Author SHA1 Message Date
Valere
d1e9844469 Use CS API to send relation
fix scroll on login view when hs field is hidden
2019-05-20 16:03:10 +02:00
6 changed files with 29 additions and 34 deletions

View File

@ -20,5 +20,6 @@ internal object NetworkConstants {

const val URI_API_PREFIX_PATH = "_matrix/client/"
const val URI_API_PREFIX_PATH_R0 = "_matrix/client/r0/"
const val URI_API_PREFIX_PATH_UNSTABLE = "_matrix/client/unstable/"

}

View File

@ -18,7 +18,7 @@ internal class EventRelationsAggregationUpdater(private val credentials: Credent
when (event.type) {
EventType.REACTION -> {
//we got a reaction!!
Timber.v("###REACTION in room $roomId")
Timber.v("###REACTION in room $roomId for event ${event.eventId}")
handleReaction(event, roomId, realm)
}
EventType.MESSAGE -> {

View File

@ -27,12 +27,7 @@ import im.vector.matrix.android.internal.session.room.send.SendResponse
import im.vector.matrix.android.internal.session.room.timeline.EventContextResponse
import im.vector.matrix.android.internal.session.room.timeline.PaginationResponse
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.*

internal interface RoomAPI {

@ -170,11 +165,13 @@ internal interface RoomAPI {
* @param eventType the event type
* @param content the event content
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send_relation/{parent_id}/{relation_type}/{event_type}")
fun sendRelation(@Path("roomId") roomId: String,
@Path("parentId") parent_id: String,
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "rooms/{roomId}/send_relation/{parent_id}/{relation_type}/{event_type}/{txnId}")
fun sendRelation(@Path("txnId") txId: String,
@Path("roomId") roomId: String,
@Path("parent_id") parentId: String,
@Path("relation_type") relationType: String,
@Path("eventType") eventType: String,
@Path("event_type") eventType: String,
@Query("key") key: String,
@Body content: Content?
): Call<SendResponse>

@ -213,6 +210,6 @@ internal interface RoomAPI {
@Path("txnId") txId: String,
@Path("roomId") roomId: String,
@Path("eventId") parent_id: String,
@Body reason: Map<String, String>
@Body reason: Map<String, String>
): Call<SendResponse>
}

View File

@ -18,11 +18,11 @@ package im.vector.matrix.android.internal.session.room.annotation
import androidx.work.*
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.RelationType
import im.vector.matrix.android.api.session.room.model.annotation.ReactionService
import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
import im.vector.matrix.android.internal.session.room.send.RedactEventWorker
import im.vector.matrix.android.internal.session.room.send.SendEventWorker
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.util.CancelableWork
@ -46,9 +46,6 @@ internal class DefaultReactionService(private val roomId: String,

override fun sendReaction(reaction: String, targetEventId: String): Cancelable {
val event = eventFactory.createReactionEvent(roomId, targetEventId, reaction)
// .also {
// //saveLocalEcho(it)
// }
val sendRelationWork = createSendRelationWork(event)
WorkManager.getInstance()
.beginUniqueWork(buildWorkIdentifier(REACTION_WORK), ExistingWorkPolicy.APPEND, sendRelationWork)
@ -58,12 +55,13 @@ internal class DefaultReactionService(private val roomId: String,


private fun createSendRelationWork(event: Event): OneTimeWorkRequest {
//TODO use the new API to send relation (for now use regular send)
val sendContentWorkerParams = SendEventWorker.Params(
roomId, event)
// val sendContentWorkerParams = SendEventWorker.Params(
// roomId, event)
val sendContentWorkerParams = SendRelationWorker.Params(
roomId, event, RelationType.ANNOTATION)
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)

return OneTimeWorkRequestBuilder<SendEventWorker>()
return OneTimeWorkRequestBuilder<SendRelationWorker>()
.setConstraints(WORK_CONSTRAINTS)
.setInputData(sendWorkData)
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
@ -124,17 +122,6 @@ internal class DefaultReactionService(private val roomId: String,
return "${roomId}_$identifier"
}

// private fun saveLocalEcho(event: Event) {
// monarchy.tryTransactionAsync { realm ->
// val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst()
// ?: return@tryTransactionAsync
// val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId = roomId)
// ?: return@tryTransactionAsync
//
// roomEntity.addSendingEvent(event, liveChunk.forwardsStateIndex ?: 0)
// }
// }

//TODO duplicate with send service?
private fun createRedactEventWork(eventId: String, reason: String?): OneTimeWorkRequest {


View File

@ -24,12 +24,14 @@ import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.annotation.ReactionContent
import im.vector.matrix.android.api.session.room.model.annotation.ReactionInfo
import im.vector.matrix.android.internal.database.mapper.ContentMapper
import im.vector.matrix.android.internal.di.MatrixKoinComponent
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.session.room.send.SendResponse
import im.vector.matrix.android.internal.util.WorkerParamsFactory
import org.koin.standalone.inject
import java.util.*

class SendRelationWorker(context: Context, params: WorkerParameters)
: Worker(context, params), MatrixKoinComponent {
@ -57,14 +59,17 @@ class SendRelationWorker(context: Context, params: WorkerParameters)
val relatedEventId = relationContent.relatesTo?.eventId ?: return Result.failure()
val relationType = (relationContent.relatesTo as? ReactionInfo)?.type ?: params.relationType
?: return Result.failure()
val key = relationContent.relatesTo.key

val result = executeRequest<SendResponse> {
apiCall = roomAPI.sendRelation(
txId = UUID.randomUUID().toString(),
roomId = params.roomId,
parent_id = relatedEventId,
parentId = relatedEventId,
relationType = relationType,
eventType = localEvent.type,
content = localEvent.content
content = emptyMap(),
key = key
)
}
return result.fold({

View File

@ -15,7 +15,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
android:paddingStart="24dp"
android:paddingLeft="24dp"
android:paddingTop="24dp"
android:paddingEnd="24dp"
android:paddingRight="24dp"
android:paddingBottom="80dp">

<ImageView
android:id="@+id/logoImageView"