Merge pull request #1246 from nextcloud/feature/noid/reply-privately

↖️ Reply privately
This commit is contained in:
Joas Schilling 2021-05-14 14:18:51 +02:00 committed by GitHub
commit e40e3d6c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 11 deletions

View File

@ -112,6 +112,7 @@ import com.nextcloud.talk.presenters.MentionAutocompletePresenter
import com.nextcloud.talk.ui.dialog.AttachmentDialog import com.nextcloud.talk.ui.dialog.AttachmentDialog
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ConductorRemapping import com.nextcloud.talk.utils.ConductorRemapping
import com.nextcloud.talk.utils.ConductorRemapping.remapChatController
import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.KeyboardUtils 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.NotificationUtils
import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.bundle.BundleKeys 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.database.user.UserUtils
import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.utils.preferences.AppPreferences
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
@ -542,8 +547,7 @@ class ChatController(args: Bundle) :
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.length >= lengthFilter) { if (s.length >= lengthFilter) {
messageInput?.error = String.format( messageInput?.error = String.format(
Objects.requireNonNull<Resources> Objects.requireNonNull<Resources> (resources).getString(R.string.nc_limit_hit),
(resources).getString(R.string.nc_limit_hit),
Integer.toString(lengthFilter) Integer.toString(lengthFilter)
) )
} else { } else {
@ -619,8 +623,7 @@ class ChatController(args: Bundle) :
conversationVideoMenuItem?.icon?.alpha = 255 conversationVideoMenuItem?.icon?.alpha = 255
} }
if (currentConversation != null && currentConversation!!.shouldShowLobby if (currentConversation != null && currentConversation!!.shouldShowLobby(conversationUser)
(conversationUser)
) { ) {
messageInputView?.visibility = View.GONE messageInputView?.visibility = View.GONE
} else { } else {
@ -1557,7 +1560,7 @@ class ChatController(args: Bundle) :
PopupMenu( PopupMenu(
ContextThemeWrapper(view?.context, R.style.appActionBarPopupMenu), ContextThemeWrapper(view?.context, R.style.appActionBarPopupMenu),
view, view,
if (message?.user?.id == conversationUser?.userId) Gravity.END else Gravity.START if (message?.user?.id == currentConversation?.actorType + "/" + currentConversation?.actorId) Gravity.END else Gravity.START
).apply { ).apply {
setOnMenuItemClickListener { item -> setOnMenuItemClickListener { item ->
when (item?.itemId) { when (item?.itemId) {
@ -1616,6 +1619,66 @@ class ChatController(args: Bundle) :
} }
true 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 -> { R.id.action_delete_message -> {
var apiVersion = 1 var apiVersion = 1
// FIXME Fix API checking with guests? // FIXME Fix API checking with guests?
@ -1667,8 +1730,16 @@ class ChatController(args: Bundle) :
inflate(R.menu.chat_message_menu) inflate(R.menu.chat_message_menu)
menu.findItem(R.id.action_copy_message).isVisible = !(message as ChatMessage).isDeleted 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_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) menu.findItem(R.id.action_delete_message).isVisible = isShowMessageDeletionButton(message)
if (menu.hasVisibleItems()) { if (menu.hasVisibleItems()) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
setForceShowIcon(true)
}
show() show()
} }
} }

View File

@ -1,5 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp" <vector android:autoMirrored="true" android:height="24dp"
android:tint="#FFFFFF" android:viewportHeight="24.0" android:tint="@color/medium_emphasis_text" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/> <path android:fillColor="#FF000000" android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
</vector> </vector>

View File

@ -21,5 +21,5 @@
<vector android:autoMirrored="true" android:height="24dp" <vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0" android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/> <path android:fillColor="@color/medium_emphasis_text" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector> </vector>

View File

@ -1,5 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp" <vector android:autoMirrored="true" android:height="24dp"
android:tint="#FFFFFF" android:viewportHeight="24.0" android:tint="@color/medium_emphasis_text" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z"/> <path android:fillColor="#FF000000" android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z"/>
</vector> </vector>

View File

@ -4,19 +4,25 @@
<item <item
android:id="@+id/action_copy_message" android:id="@+id/action_copy_message"
android:icon="@drawable/ic_content_copy_white_24dp" android:icon="@drawable/ic_content_copy"
android:title="@string/nc_copy_message" android:title="@string/nc_copy_message"
app:showAsAction="always" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_reply_to_message" android:id="@+id/action_reply_to_message"
android:icon="@drawable/ic_reply_white_24dp" android:icon="@drawable/ic_reply"
android:title="@string/nc_reply" android:title="@string/nc_reply"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/action_reply_privately"
android:icon="@drawable/ic_reply"
android:title="@string/nc_reply_privately"
app:showAsAction="always" />
<item <item
android:id="@+id/action_delete_message" android:id="@+id/action_delete_message"
android:icon="@drawable/ic_delete_white_24dp" android:icon="@drawable/ic_delete"
android:title="@string/nc_delete_message" android:title="@string/nc_delete_message"
app:showAsAction="always" /> app:showAsAction="always" />
</menu> </menu>

View File

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