浏览代码

Reply privately

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 年之前
父节点
当前提交
7bbe954d47

+ 75 - 5
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -112,6 +112,7 @@ import com.nextcloud.talk.presenters.MentionAutocompletePresenter
 import com.nextcloud.talk.ui.dialog.AttachmentDialog
 import com.nextcloud.talk.utils.ApiUtils
 import com.nextcloud.talk.utils.ConductorRemapping
+import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
 import com.nextcloud.talk.utils.DateUtils
 import com.nextcloud.talk.utils.DisplayUtils
 import com.nextcloud.talk.utils.KeyboardUtils
@@ -119,6 +120,10 @@ import com.nextcloud.talk.utils.MagicCharPolicy
 import com.nextcloud.talk.utils.NotificationUtils
 import com.nextcloud.talk.utils.UriUtils
 import com.nextcloud.talk.utils.bundle.BundleKeys
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
 import com.nextcloud.talk.utils.database.user.UserUtils
 import com.nextcloud.talk.utils.preferences.AppPreferences
 import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
@@ -543,7 +548,7 @@ class ChatController(args: Bundle) :
                 if (s.length >= lengthFilter) {
                     messageInput?.error = String.format(
                         Objects.requireNonNull<Resources>
-                        (resources).getString(R.string.nc_limit_hit),
+                            (resources).getString(R.string.nc_limit_hit),
                         Integer.toString(lengthFilter)
                     )
                 } else {
@@ -620,7 +625,7 @@ class ChatController(args: Bundle) :
                 }
 
                 if (currentConversation != null && currentConversation!!.shouldShowLobby
-                    (conversationUser)
+                        (conversationUser)
                 ) {
                     messageInputView?.visibility = View.GONE
                 } else {
@@ -1304,9 +1309,9 @@ class ChatController(args: Bundle) :
                             TextUtils.isEmpty(chatMessageList[i + 1].systemMessage) &&
                             chatMessageList[i + 1].actorId == chatMessageList[i].actorId &&
                             countGroupedMessages < 4 && DateFormatter.isSameDay(
-                                    chatMessageList[i].createdAt,
-                                    chatMessageList[i + 1].createdAt
-                                )
+                                chatMessageList[i].createdAt,
+                                chatMessageList[i + 1].createdAt
+                            )
                         ) {
                             chatMessageList[i].isGrouped = true
                             countGroupedMessages++
@@ -1616,6 +1621,66 @@ class ChatController(args: Bundle) :
                         }
                         true
                     }
+                    R.id.action_reply_privately -> {
+                        val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
+                        val retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
+                            apiVersion,
+                            conversationUser?.baseUrl,
+                            "1",
+                            message?.user?.id?.substring(6),
+                            null
+                        )
+                        ncApi!!.createRoom(
+                            credentials,
+                            retrofitBucket.getUrl(), retrofitBucket.getQueryMap()
+                        )
+                            .subscribeOn(Schedulers.io())
+                            .observeOn(AndroidSchedulers.mainThread())
+                            .subscribe(object : Observer<RoomOverall> {
+                                override fun onSubscribe(d: Disposable) {}
+                                override fun onNext(roomOverall: RoomOverall) {
+                                    val bundle = Bundle()
+                                    bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
+                                    bundle.putString(KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken())
+                                    bundle.putString(KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId())
+
+                                    // FIXME once APIv2 or later is used only, the createRoom already returns all the data
+                                    ncApi!!.getRoom(
+                                        credentials,
+                                        ApiUtils.getUrlForRoom(
+                                            apiVersion, conversationUser?.baseUrl,
+                                            roomOverall.getOcs().getData().getToken()
+                                        )
+                                    )
+                                        .subscribeOn(Schedulers.io())
+                                        .observeOn(AndroidSchedulers.mainThread())
+                                        .subscribe(object : Observer<RoomOverall> {
+                                            override fun onSubscribe(d: Disposable) {}
+                                            override fun onNext(roomOverall: RoomOverall) {
+                                                bundle.putParcelable(
+                                                    KEY_ACTIVE_CONVERSATION,
+                                                    Parcels.wrap(roomOverall.getOcs().getData())
+                                                )
+                                                remapChatController(
+                                                    router, conversationUser!!.id,
+                                                    roomOverall.getOcs().getData().getToken(), bundle, true
+                                                )
+                                            }
+
+                                            override fun onError(e: Throwable) {
+                                                Log.e(TAG, e.message, e)
+                                            }
+                                            override fun onComplete() {}
+                                        })
+                                }
+
+                                override fun onError(e: Throwable) {
+                                    Log.e(TAG, e.message, e)
+                                }
+                                override fun onComplete() {}
+                            })
+                        true
+                    }
                     R.id.action_delete_message -> {
                         var apiVersion = 1
                         // FIXME Fix API checking with guests?
@@ -1667,6 +1732,11 @@ class ChatController(args: Bundle) :
             inflate(R.menu.chat_message_menu)
             menu.findItem(R.id.action_copy_message).isVisible = !(message as ChatMessage).isDeleted
             menu.findItem(R.id.action_reply_to_message).isVisible = (message as ChatMessage).replyable
+            menu.findItem(R.id.action_reply_privately).isVisible = (message as ChatMessage).replyable &&
+                conversationUser?.userId?.isNotEmpty() == true && conversationUser.userId != "?" &&
+                (message as ChatMessage).user.id.startsWith("users/") &&
+                (message as ChatMessage).user.id.substring(6) != currentConversation?.actorId &&
+                currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
             menu.findItem(R.id.action_delete_message).isVisible = isShowMessageDeletionButton(message)
             if (menu.hasVisibleItems()) {
                 show()

+ 6 - 0
app/src/main/res/menu/chat_message_menu.xml

@@ -14,6 +14,12 @@
         android:title="@string/nc_reply"
         app:showAsAction="always" />
 
+    <item
+        android:id="@+id/action_reply_privately"
+        android:icon="@drawable/ic_reply_white_24dp"
+        android:title="@string/nc_reply_privately"
+        app:showAsAction="always" />
+
     <item
         android:id="@+id/action_delete_message"
         android:icon="@drawable/ic_delete_white_24dp"

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -355,6 +355,7 @@
     <string name="nc_99_plus">99+</string>
     <string name="nc_copy_message">Copy</string>
     <string name="nc_reply">Reply</string>
+    <string name="nc_reply_privately">Reply privately</string>
     <string name="nc_delete_message">Delete</string>
     <string name="nc_delete_message_leaked_to_matterbridge">Message deleted successfully, but it might have been leaked to other services</string>