From daacbb06f33b0ed2c6466ede9721343e8513fbe2 Mon Sep 17 00:00:00 2001
From: Taras Smakula <tarassmakula@gmail.com>
Date: Fri, 27 Oct 2023 18:01:51 +0300
Subject: [PATCH] Add message to knock request

---
 .../well_known/RoomWellKnownDialogFragment.kt |  4 ++-
 .../room/well_known/RoomWellKnownViewModel.kt |  6 ++--
 .../dialog_fragment_room_well_known.xml       | 34 +++++++++++++++++--
 app/src/main/res/values/strings.xml           |  1 +
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownDialogFragment.kt b/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownDialogFragment.kt
index b42111f87..e2fa98343 100644
--- a/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownDialogFragment.kt
+++ b/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownDialogFragment.kt
@@ -7,6 +7,7 @@ import androidx.fragment.app.viewModels
 import dagger.hilt.android.AndroidEntryPoint
 import org.futo.circles.R
 import org.futo.circles.core.base.fragment.BaseFullscreenDialogFragment
+import org.futo.circles.core.extensions.getText
 import org.futo.circles.core.extensions.gone
 import org.futo.circles.core.extensions.loadProfileIcon
 import org.futo.circles.core.extensions.observeData
@@ -38,7 +39,7 @@ class RoomWellKnownDialogFragment :
 
     private fun setupViews() {
         binding.btnRequest.setOnClickListener {
-            viewModel.sendKnockRequest()
+            viewModel.sendKnockRequest(binding.tilRequestMessage.getText().takeIf { it.isNotEmpty() })
             binding.btnRequest.setIsLoading(true)
         }
     }
@@ -83,6 +84,7 @@ class RoomWellKnownDialogFragment :
                 text = roomInfo.name
             }
             btnRequest.setIsVisible(shouldShowKnockButton(roomInfo.membership))
+            tilRequestMessage.setIsVisible(shouldShowKnockButton(roomInfo.membership))
             binding.tvRoomId.text = roomInfo.id
             tvMembersCount.apply {
                 setIsVisible(roomInfo.memberCount > 0)
diff --git a/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownViewModel.kt b/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownViewModel.kt
index 97e05cc08..4a8f3ff15 100644
--- a/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownViewModel.kt
+++ b/app/src/main/java/org/futo/circles/feature/room/well_known/RoomWellKnownViewModel.kt
@@ -38,11 +38,13 @@ class RoomWellKnownViewModel @Inject constructor(
         }
     }
 
-    fun sendKnockRequest() {
+    fun sendKnockRequest(message: String?) {
         val roomId = urlData?.roomId ?: return
         launchBg {
             val result =
-                createResult { MatrixSessionProvider.currentSession?.roomService()?.knock(roomId) }
+                createResult {
+                    MatrixSessionProvider.currentSession?.roomService()?.knock(roomId, message)
+                }
             knockRequestLiveData.postValue(result)
         }
     }
diff --git a/app/src/main/res/layout/dialog_fragment_room_well_known.xml b/app/src/main/res/layout/dialog_fragment_room_well_known.xml
index 078ffb64c..3dd2d0bfc 100644
--- a/app/src/main/res/layout/dialog_fragment_room_well_known.xml
+++ b/app/src/main/res/layout/dialog_fragment_room_well_known.xml
@@ -135,25 +135,53 @@
         android:layout_marginHorizontal="36dp"
         android:layout_marginTop="8dp"
         android:gravity="center"
-        app:layout_constraintBottom_toTopOf="@id/btnRequest"
+        app:layout_constraintBottom_toTopOf="@id/tilRequestMessage"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@id/tvMembersCount"
         tools:text="@string/you_have_pending_invitation_room" />
 
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/tilRequestMessage"
+        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginHorizontal="16dp"
+        android:layout_marginTop="24dp"
+        android:visibility="gone"
+        app:hintEnabled="false"
+        app:layout_constraintBottom_toTopOf="@id/btnRequest"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/tvMembersip"
+        tools:visibility="visible">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="top"
+            android:hint="@string/optional_request_message"
+            android:imeOptions="actionDone"
+            android:inputType="textMultiLine"
+            android:lines="3"
+            android:maxLines="3"
+            android:padding="12dp" />
+
+    </com.google.android.material.textfield.TextInputLayout>
+
 
     <org.futo.circles.core.view.LoadingButton
         android:id="@+id/btnRequest"
         style="@style/AccentButtonStyle"
         android:layout_width="450dp"
         android:layout_height="wrap_content"
-        android:layout_marginTop="16dp"
+        android:layout_marginTop="24dp"
         android:text="@string/request_to_join"
         android:visibility="gone"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@id/tvMembersip"
+        app:layout_constraintTop_toBottomOf="@id/tilRequestMessage"
         tools:visibility="visible" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2d49f60d4..eade56ad3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -214,6 +214,7 @@
     <string name="group_topic_optional">Group topic (optional)</string>
     <string name="session">Session</string>
     <string name="help">Help</string>
+    <string name="optional_request_message">Optional: Request message</string>
 
     <string-array name="report_categories">
         <item>@string/crude_language</item>
-- 
GitLab