|
16 | 16 |
|
17 | 17 | package org.matrix.android.sdk.internal.session.room.timeline
|
18 | 18 |
|
| 19 | +import org.matrix.android.sdk.api.extensions.tryOrNull |
19 | 20 | import org.matrix.android.sdk.api.session.events.model.Event
|
| 21 | +import org.matrix.android.sdk.internal.crypto.EventDecryptor |
| 22 | +import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult |
20 | 23 | import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
21 | 24 | import org.matrix.android.sdk.internal.network.executeRequest
|
22 | 25 | import org.matrix.android.sdk.internal.session.room.RoomAPI
|
23 | 26 | import org.matrix.android.sdk.internal.task.Task
|
24 | 27 | import javax.inject.Inject
|
25 | 28 |
|
26 |
| -// TODO Add parent task |
27 |
| - |
28 |
| -internal class GetEventTask @Inject constructor( |
29 |
| - private val roomAPI: RoomAPI, |
30 |
| - private val globalErrorReceiver: GlobalErrorReceiver |
31 |
| -) : Task<GetEventTask.Params, Event> { |
32 |
| - |
33 |
| - internal data class Params( |
| 29 | +internal interface GetEventTask : Task<GetEventTask.Params, Event> { |
| 30 | + data class Params( |
34 | 31 | val roomId: String,
|
35 |
| - val eventId: String |
| 32 | + val eventId: String, |
36 | 33 | )
|
| 34 | +} |
37 | 35 |
|
38 |
| - override suspend fun execute(params: Params): Event { |
39 |
| - return executeRequest(globalErrorReceiver) { |
| 36 | +internal class DefaultGetEventTask @Inject constructor( |
| 37 | + private val roomAPI: RoomAPI, |
| 38 | + private val globalErrorReceiver: GlobalErrorReceiver, |
| 39 | + private val eventDecryptor: EventDecryptor |
| 40 | +) : GetEventTask { |
| 41 | + |
| 42 | + override suspend fun execute(params: GetEventTask.Params): Event { |
| 43 | + val event = executeRequest(globalErrorReceiver) { |
40 | 44 | roomAPI.getEvent(params.roomId, params.eventId)
|
41 | 45 | }
|
| 46 | + |
| 47 | + // Try to decrypt the Event |
| 48 | + if (event.isEncrypted()) { |
| 49 | + tryOrNull(message = "Unable to decrypt the event") { |
| 50 | + eventDecryptor.decryptEvent(event, "") |
| 51 | + } |
| 52 | + ?.let { result -> |
| 53 | + event.mxDecryptionResult = OlmDecryptionResult( |
| 54 | + payload = result.clearEvent, |
| 55 | + senderKey = result.senderCurve25519Key, |
| 56 | + keysClaimed = result.claimedEd25519Key?.let { mapOf("ed25519" to it) }, |
| 57 | + forwardingCurve25519KeyChain = result.forwardingCurve25519KeyChain |
| 58 | + ) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return event |
42 | 63 | }
|
43 | 64 | }
|
0 commit comments