From f51268b587d4a7ff83a71fb8b867380b8a5eb3ac Mon Sep 17 00:00:00 2001 From: Brice-W Date: Wed, 12 May 2021 13:41:00 +1000 Subject: [PATCH] open group invitation sending part --- .../conversation/ConversationActivity.java | 36 ++++++++++++++++++- .../database/model/ThreadRecord.java | 2 ++ .../menu/conversation_invite_open_group.xml | 8 +++++ app/src/main/res/values-fr/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 2 ++ .../messages/visible/VisibleMessage.kt | 2 +- 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/menu/conversation_invite_open_group.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 178b29cebe..92845a3ab0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -88,6 +88,7 @@ import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate; import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage; import org.session.libsession.messaging.messages.signal.OutgoingSecureMediaMessage; import org.session.libsession.messaging.messages.signal.OutgoingTextMessage; +import org.session.libsession.messaging.messages.visible.OpenGroupInvitation; import org.session.libsession.messaging.messages.visible.VisibleMessage; import org.session.libsession.messaging.open_groups.OpenGroup; import org.session.libsession.messaging.open_groups.OpenGroupV2; @@ -157,6 +158,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel; import org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity; import org.thoughtcrime.securesms.loki.activities.HomeActivity; +import org.thoughtcrime.securesms.loki.activities.SelectContactsActivity; import org.thoughtcrime.securesms.loki.api.PublicChatInfoUpdateWorker; import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase; import org.thoughtcrime.securesms.loki.database.LokiUserDatabase; @@ -249,11 +251,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private static final int PICK_GIF = 10; private static final int SMS_DEFAULT = 11; private static final int MEDIA_SENDER = 12; + private static final int INVITE_CONTACTS = 124; private GlideRequests glideRequests; protected ComposeText composeText; private AnimatingToggle buttonToggle; - private ImageButton sendButton; + private ImageButton sendButton; private ImageButton attachButton; private ProfilePictureView profilePictureView; private TextView titleTextView; @@ -593,6 +596,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity }); break; + case INVITE_CONTACTS: + if (data.getExtras() == null || !data.hasExtra(SelectContactsActivity.Companion.getSelectedContactsKey())) return; + String[] selectedContacts = data.getExtras().getStringArray(SelectContactsActivity.Companion.getSelectedContactsKey()); + sendOpenGroupInvitations(selectedContacts); + break; } } @@ -655,6 +663,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } else if (isActiveGroup()) { inflater.inflate(R.menu.conversation_push_group_options, menu); } + } else if (isOpenGroupOrRSSFeed) { + inflater.inflate(R.menu.conversation_invite_open_group, menu); } inflater.inflate(R.menu.conversation, menu); @@ -763,6 +773,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity // case R.id.menu_conversation_settings: handleConversationSettings(); return true; case R.id.menu_expiring_messages_off: case R.id.menu_expiring_messages: handleSelectMessageExpiration(); return true; + case R.id.menu_invite_to_open_group: handleInviteToOpenGroup(); return true; case android.R.id.home: handleReturnToConversationList(); return true; } @@ -1031,6 +1042,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity startActivity(intent); } + private void handleInviteToOpenGroup() { + Intent intent = new Intent(this, SelectContactsActivity.class); + startActivityForResult(intent, INVITE_CONTACTS); + } + private void handleDistributionBroadcastEnabled(MenuItem item) { distributionType = DistributionTypes.BROADCAST; item.setChecked(true); @@ -1838,6 +1854,24 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity sendComplete(allocatedThreadId); } + private void sendOpenGroupInvitations(String[] contactsID) { + final Context context = getApplicationContext(); + OpenGroupV2 openGroup = DatabaseFactory.getLokiThreadDatabase(context).getOpenGroupChat(threadId); + for (String contactId: contactsID) { + Recipient recipient = Recipient.from(context, Address.fromSerialized(contactId), true); + VisibleMessage message = new VisibleMessage(); + message.setSentTimestamp(System.currentTimeMillis()); + OpenGroupInvitation openGroupInvitationMessage = new OpenGroupInvitation(); + openGroupInvitationMessage.setGroupName(openGroup.getName()); + openGroupInvitationMessage.setGroupUrl(openGroup.toJoinUrl()); + message.setOpenGroupInvitation(openGroupInvitationMessage); + OutgoingTextMessage outgoingTextMessage = OutgoingTextMessage.fromOpenGroupInvitation(openGroupInvitationMessage, recipient, message.getSentTimestamp()); + + DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(-1, outgoingTextMessage, message.getSentTimestamp()); + MessageSender.send(message, recipient.getAddress()); + } + } + private void updateToggleButtonState() { if (inputPanel.isRecordingInLockedMode()) { buttonToggle.display(sendButton); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java index b0183cff63..1833ac4270 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java @@ -77,6 +77,8 @@ public class ThreadRecord extends DisplayRecord { return emphasisAdded(context.getString(R.string.ThreadRecord_group_updated)); } else if (isGroupQuit()) { return emphasisAdded(context.getString(R.string.ThreadRecord_left_the_group)); + } else if (isOpenGroupInvitation()) { + return emphasisAdded(context.getString(R.string.ThreadRecord_open_group_invitation)); } else if (isKeyExchange()) { return emphasisAdded(context.getString(R.string.ConversationListItem_key_exchange_message)); } else if (SmsDatabase.Types.isFailedDecryptType(type)) { diff --git a/app/src/main/res/menu/conversation_invite_open_group.xml b/app/src/main/res/menu/conversation_invite_open_group.xml new file mode 100644 index 0000000000..0cef563b7c --- /dev/null +++ b/app/src/main/res/menu/conversation_invite_open_group.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index b4c1cdcd1e..403685a6c5 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -151,6 +151,7 @@ La pièce jointe dépasse la limite de taille autorisée. L’appareil photo n’est pas disponible Impossible d’enregistrer l’audio ! + Ajouter des membres Il n’y a aucune appli pour gérer ce lien sur votre appareil. Pour envoyer des messages audio, autorisez Session à accéder à votre microphone. Session exige l’autorisation Microphone afin d’envoyer des messages audio, mais elle a été refusée définitivement. Veuillez accéder au menu des paramètres des applis, sélectionner « Autorisations » et activer « Microphone ». @@ -599,6 +600,8 @@ Vous avez reçu un message d’échange de clés pour une version de protocole i Votre numéro de sécurité avec %s a changé Vous avez marqué comme vérifié Vous avez marqué comme non vérifié + Cette conversation est vide + Invitation à un groupe public Mise à jour de Session Une nouvelle version de Session est proposée. Touchez pour lancer la mise à jour diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b5a6f20f1..a6efce07db 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -175,6 +175,7 @@ Camera unavailable Unable to record audio! There is no app available to handle this link on your device. + Add members Session needs microphone access to send audio messages. Session needs microphone access to send audio messages, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Microphone\". @@ -722,6 +723,7 @@ You marked verified You marked unverified This conversation is empty + Open group invitation Session update diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt index 5452ba7b51..11a398df42 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/visible/VisibleMessage.kt @@ -70,9 +70,9 @@ class VisibleMessage : Message() { override fun isValid(): Boolean { if (!super.isValid()) return false if (attachmentIDs.isNotEmpty()) return true + if (openGroupInvitation != null) return true val text = text?.trim() ?: return false if (text.isNotEmpty()) return true - if (openGroupInvitation != null) return true return false }