Merge pull request #1492 from nextcloud/feature/1335/forwarding-chat-messages

Forwarding chat messages
This commit is contained in:
Andy Scherzinger 2021-07-22 23:27:05 +02:00 committed by GitHub
commit 9fa8643494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 9 deletions

View File

@ -111,7 +111,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
if (!router!!.hasRootController()) { if (!router!!.hasRootController()) {
router!!.setRoot( router!!.setRoot(
RouterTransaction.with(ConversationsListController()) RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler()) .pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler())
) )
@ -121,7 +121,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
if (hasDb) { if (hasDb) {
if (userUtils.anyUserExists()) { if (userUtils.anyUserExists()) {
router!!.setRoot( router!!.setRoot(
RouterTransaction.with(ConversationsListController()) RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler()) .pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler())
) )
@ -174,7 +174,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
fun resetConversationsList() { fun resetConversationsList() {
if (userUtils.anyUserExists()) { if (userUtils.anyUserExists()) {
router!!.setRoot( router!!.setRoot(
RouterTransaction.with(ConversationsListController()) RouterTransaction.with(ConversationsListController(Bundle()))
.pushChangeHandler(HorizontalChangeHandler()) .pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler())
) )

View File

@ -69,6 +69,7 @@ import java.util.concurrent.ExecutionException;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.emoji.widget.EmojiTextView; import androidx.emoji.widget.EmojiTextView;
@ -407,7 +408,19 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
return; return;
} }
PopupMenu popupMenu = new PopupMenu(this.context, itemView, Gravity.START); Context viewContext;
if (itemView != null && itemView.getContext() != null) {
viewContext = itemView.getContext();
} else {
viewContext = this.context;
}
PopupMenu popupMenu = new PopupMenu(
new ContextThemeWrapper(viewContext, R.style.appActionBarPopupMenu),
itemView,
Gravity.START
);
popupMenu.inflate(R.menu.chat_preview_message_menu); popupMenu.inflate(R.menu.chat_preview_message_menu);
popupMenu.setOnMenuItemClickListener(item -> { popupMenu.setOnMenuItemClickListener(item -> {

View File

@ -443,7 +443,7 @@ public class AccountVerificationController extends BaseController {
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
if (userUtils.getUsers().size() == 1) { if (userUtils.getUsers().size() == 1) {
getRouter().setRoot(RouterTransaction.with(new getRouter().setRoot(RouterTransaction.with(new
ConversationsListController()) ConversationsListController(new Bundle()))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} else { } else {
@ -524,7 +524,7 @@ public class AccountVerificationController extends BaseController {
} else { } else {
if (userUtils.anyUserExists()) { if (userUtils.anyUserExists()) {
getRouter().setRoot(RouterTransaction.with(new ConversationsListController()) getRouter().setRoot(RouterTransaction.with(new ConversationsListController(new Bundle()))
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} else { } else {

View File

@ -95,6 +95,7 @@ import com.facebook.imagepipeline.image.CloseableImage
import com.google.android.flexbox.FlexboxLayout import com.google.android.flexbox.FlexboxLayout
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.activities.MagicCallActivity import com.nextcloud.talk.activities.MagicCallActivity
import com.nextcloud.talk.activities.MainActivity
import com.nextcloud.talk.adapters.messages.IncomingLocationMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingLocationMessageViewHolder
import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder
import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder
@ -2061,7 +2062,7 @@ class ChatController(args: Bundle) :
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
router.popCurrentController() (activity as MainActivity).resetConversationsList()
return true return true
} }
R.id.conversation_video_call -> { R.id.conversation_video_call -> {
@ -2165,6 +2166,17 @@ class ChatController(args: Bundle) :
clipboardManager.setPrimaryClip(clipData) clipboardManager.setPrimaryClip(clipData)
true true
} }
R.id.action_forward_message -> {
val bundle = Bundle()
bundle.putBoolean(BundleKeys.KEY_FORWARD_MSG_FLAG, true)
bundle.putString(BundleKeys.KEY_FORWARD_MSG_TEXT, message?.text)
getRouter().pushController(
RouterTransaction.with(ConversationsListController(bundle))
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
true
}
R.id.action_reply_to_message -> { R.id.action_reply_to_message -> {
val chatMessage = message as ChatMessage? val chatMessage = message as ChatMessage?
replyToMessage(chatMessage, message?.jsonMessageId) replyToMessage(chatMessage, message?.jsonMessageId)
@ -2303,6 +2315,10 @@ class ChatController(args: Bundle) :
(message as ChatMessage).user.id.substring(6) != currentConversation?.actorId && (message as ChatMessage).user.id.substring(6) != currentConversation?.actorId &&
currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL 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)
menu.findItem(R.id.action_forward_message).isVisible = ChatMessage.MessageType.REGULAR_TEXT_MESSAGE.equals(
(message as ChatMessage)
.getMessageType()
)
if (menu.hasVisibleItems()) { if (menu.hasVisibleItems()) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
setForceShowIcon(true) setForceShowIcon(true)

View File

@ -139,6 +139,7 @@ public class ConversationsListController extends BaseController implements Searc
public static final String TAG = "ConvListController"; public static final String TAG = "ConvListController";
public static final int ID_DELETE_CONVERSATION_DIALOG = 0; public static final int ID_DELETE_CONVERSATION_DIALOG = 0;
private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery"; private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery";
private final Bundle bundle;
@Inject @Inject
UserUtils userUtils; UserUtils userUtils;
@ -203,9 +204,13 @@ public class ConversationsListController extends BaseController implements Searc
private String textToPaste = ""; private String textToPaste = "";
public ConversationsListController() { private boolean forwardMessage = false;
public ConversationsListController(Bundle bundle) {
super(); super();
setHasOptionsMenu(true); setHasOptionsMenu(true);
forwardMessage = bundle.getBoolean(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_FLAG());
this.bundle = bundle;
} }
@Override @Override
@ -340,9 +345,13 @@ public class ConversationsListController extends BaseController implements Searc
showShareToScreen = !shareToScreenWasShown && hasActivityActionSendIntent(); showShareToScreen = !shareToScreenWasShown && hasActivityActionSendIntent();
if (showShareToScreen) { if (showShareToScreen) {
hideSearchBar(); hideSearchBar();
getActionBar().setTitle(R.string.send_to_three_dots); getActionBar().setTitle(R.string.send_to_three_dots);
} else if (forwardMessage) {
hideSearchBar();
getActionBar().setTitle(R.string.nc_forward_to_three_dots);
} else { } else {
MainActivity activity = (MainActivity) getActivity(); MainActivity activity = (MainActivity) getActivity();
@ -752,6 +761,8 @@ public class ConversationsListController extends BaseController implements Searc
if (showShareToScreen) { if (showShareToScreen) {
shareToScreenWasShown = true; shareToScreenWasShown = true;
handleSharedData(); handleSharedData();
} else if (forwardMessage) {
openConversation(bundle.getString(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_TEXT()));
} else { } else {
openConversation(); openConversation();
} }

View File

@ -68,4 +68,6 @@ object BundleKeys {
val KEY_SHARED_TEXT = "KEY_SHARED_TEXT" val KEY_SHARED_TEXT = "KEY_SHARED_TEXT"
val KEY_GEOCODING_QUERY = "KEY_GEOCODING_QUERY" val KEY_GEOCODING_QUERY = "KEY_GEOCODING_QUERY"
val KEY_META_DATA = "KEY_META_DATA" val KEY_META_DATA = "KEY_META_DATA"
val KEY_FORWARD_MSG_FLAG = "KEY_FORWARD_MSG_FLAG"
val KEY_FORWARD_MSG_TEXT = "KEY_FORWARD_MSG_TEXT"
} }

View File

@ -0,0 +1,27 @@
<!--
@author Google LLC
Copyright (C) 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="@color/medium_emphasis_text"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M21,12L14,5V9C7,10 4,15 3,20C5.5,16.5 9,14.9 14,14.9V19L21,12Z" />
</vector>

View File

@ -8,6 +8,12 @@
android:title="@string/nc_copy_message" android:title="@string/nc_copy_message"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/action_forward_message"
android:icon="@drawable/ic_share_action"
android:title="@string/nc_forward_message"
app:showAsAction="always" />
<item <item
android:id="@+id/action_reply_to_message" android:id="@+id/action_reply_to_message"
android:icon="@drawable/ic_reply" android:icon="@drawable/ic_reply"
@ -25,4 +31,4 @@
android:icon="@drawable/ic_delete" 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

@ -189,6 +189,8 @@
<string name="nc_add_to_favorites">Add to favorites</string> <string name="nc_add_to_favorites">Add to favorites</string>
<string name="nc_remove_from_favorites">Remove from favorites</string> <string name="nc_remove_from_favorites">Remove from favorites</string>
<string name="nc_forward_to_three_dots">Forward to …</string>
<!-- Contacts --> <!-- Contacts -->
<string name="nc_select_participants">Select participants</string> <string name="nc_select_participants">Select participants</string>
<string name="nc_add_participants">Add participants</string> <string name="nc_add_participants">Add participants</string>
@ -357,6 +359,7 @@
<!-- Chat --> <!-- Chat -->
<string name="nc_copy_message">Copy</string> <string name="nc_copy_message">Copy</string>
<string name="nc_forward_message">Forward</string>
<string name="nc_reply">Reply</string> <string name="nc_reply">Reply</string>
<string name="nc_reply_privately">Reply privately</string> <string name="nc_reply_privately">Reply privately</string>
<string name="nc_delete_message">Delete</string> <string name="nc_delete_message">Delete</string>