From 4e6424718c33f0e2406b3e665bfc009741b561b3 Mon Sep 17 00:00:00 2001
From: Taras <tarassmakula@gmail.com>
Date: Sun, 13 Mar 2022 13:19:51 +0200
Subject: [PATCH] Create accept terms data source

---
 .../data_source/AcceptTermsDataSource.kt      | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 app/src/main/java/com/futo/circles/feature/terms/data_source/AcceptTermsDataSource.kt

diff --git a/app/src/main/java/com/futo/circles/feature/terms/data_source/AcceptTermsDataSource.kt b/app/src/main/java/com/futo/circles/feature/terms/data_source/AcceptTermsDataSource.kt
new file mode 100644
index 000000000..be5e025af
--- /dev/null
+++ b/app/src/main/java/com/futo/circles/feature/terms/data_source/AcceptTermsDataSource.kt
@@ -0,0 +1,25 @@
+package com.futo.circles.feature.terms.data_source
+
+
+import com.futo.circles.extensions.Response
+import com.futo.circles.extensions.createResult
+import com.futo.circles.feature.sign_up.data_source.SignUpDataSource
+import com.futo.circles.provider.MatrixInstanceProvider
+import org.matrix.android.sdk.api.auth.registration.RegistrationResult
+
+class AcceptTermsDataSource(
+    private val signUpDataSource: SignUpDataSource
+) {
+
+    private val wizard by lazy {
+        MatrixInstanceProvider.matrix.authenticationService().getRegistrationWizard()
+    }
+
+    suspend fun acceptTerms(): Response<RegistrationResult> {
+        val result = createResult { wizard.acceptTerms() }
+
+        (result as? Response.Success)?.let { signUpDataSource.stageCompleted(result.data) }
+
+        return result
+    }
+}
\ No newline at end of file
-- 
GitLab