Implement copy public key action for group chats

This commit is contained in:
Niels Andriesse 2019-09-12 14:10:04 +10:00
parent 7cf543bdf8
commit 7cc7f907fe
3 changed files with 19 additions and 1 deletions

View File

@ -16,6 +16,11 @@
android:icon="?menu_copy_icon"
app:showAsAction="always" />
<item android:title="@string/activity_conversation_copy_public_key_button_title"
android:id="@+id/menu_context_copy_public_key"
android:icon="@drawable/ic_profile_default"
app:showAsAction="always" />
<!-- <item android:title="@string/conversation_context__menu_forward_message"
android:id="@+id/menu_context_forward"
android:icon="?menu_forward_icon"

View File

@ -1613,5 +1613,7 @@
<!-- Scan QR code fragment -->
<string name="fragment_scan_qr_code_title">Scan QR Code</string>
<string name="fragment_scan_qr_code_explanation">Scan the QR code of the person you\'d like to securely message. They can find their QR code by going into Loki Messenger\'s in-app settings and clicking \"Show QR Code\".</string>
<!-- Conversation activity -->
<string name="activity_conversation_copy_public_key_button_title">Copy public key</string>
</resources>

View File

@ -410,13 +410,15 @@ public class ConversationFragment extends Fragment
if (isGroupChat) {
boolean isLokiPublicChat = recipient.getName() != null && recipient.getName().equals("Loki Public Chat");
int selectedMessageCount = messageRecords.size();
boolean isSentByUser = ((MessageRecord)messageRecords.toArray()[0]).isOutgoing();
menu.findItem(R.id.menu_context_copy_public_key).setVisible(isLokiPublicChat && selectedMessageCount == 1 && !isSentByUser);
menu.findItem(R.id.menu_context_reply).setVisible(isLokiPublicChat && selectedMessageCount == 1);
LokiAPIDatabase lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(getContext());
boolean isSentByUser = ((MessageRecord)messageRecords.toArray()[0]).isOutgoing();
boolean userCanModerate = lokiAPIDatabase.isModerator(LokiGroupChatAPI.getPublicChatServerID(), LokiGroupChatAPI.getPublicChatServer());
boolean isDeleteOptionVisible = isLokiPublicChat && selectedMessageCount == 1 && (isSentByUser || userCanModerate);
menu.findItem(R.id.menu_context_delete_message).setVisible(isDeleteOptionVisible);
} else {
menu.findItem(R.id.menu_context_copy_public_key).setVisible(false);
menu.findItem(R.id.menu_context_delete_message).setVisible(true);
}
}
@ -493,6 +495,11 @@ public class ConversationFragment extends Fragment
clipboard.setText(result);
}
private void handleCopyPublicKey(MessageRecord messageRecord) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(messageRecord.getRecipient().getAddress().toString());
}
private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
int messagesCount = messageRecords.size();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@ -1121,6 +1128,10 @@ public class ConversationFragment extends Fragment
handleCopyMessage(getListAdapter().getSelectedItems());
actionMode.finish();
return true;
case R.id.menu_context_copy_public_key:
handleCopyPublicKey((MessageRecord) getListAdapter().getSelectedItems().toArray()[0]);
actionMode.finish();
return true;
case R.id.menu_context_delete_message:
handleDeleteMessages(getListAdapter().getSelectedItems());
actionMode.finish();