From 781a8500df4a40e9430170d057ac72848304c1f5 Mon Sep 17 00:00:00 2001
From: Niels Andriesse <andriesseniels@gmail.com>
Date: Wed, 7 Aug 2019 15:24:05 +1000
Subject: [PATCH] Clean

---
 build.gradle                                  |  3 +-
 .../conversation/ConversationActivity.java    | 69 +++++++------------
 2 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/build.gradle b/build.gradle
index 5a0db003c3..a6675c26dc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -356,7 +356,7 @@ def assembleWebsiteDescriptor = { variant, file ->
         descriptorFile.write(descriptor)
     }
 }
-
+/*
 def signProductionRelease = { variant ->
     variant.outputs.collect { output ->
         String apkName    = output.outputFile.name
@@ -397,6 +397,7 @@ tasks.whenTaskAdded { task ->
         task.finalizedBy signProductionWebsiteRelease
     }
 }
+ */
 
 def getLastCommitTimestamp() {
     new ByteArrayOutputStream().withStream { os ->
diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java
index 2f6e070a1d..b91e4a46a9 100644
--- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java
+++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java
@@ -232,7 +232,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import kotlin.Unit;
-import kotlin.jvm.functions.Function1;
 import network.loki.messenger.R;
 
 import static org.thoughtcrime.securesms.TransportOption.Type;
@@ -2122,31 +2121,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
                                                   final int subscriptionId,
                                                   final boolean initiating)
   {
-    final SettableFuture<Void> future  = new SettableFuture<>();
-
     boolean isLokiPublicChat = isGroupConversation(); // TODO: Figure out a better way of determining this
     if (isLokiPublicChat) {
-      String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
-      String displayName = DatabaseFactory.getLokiAPIDatabase(this).getUserDisplayName();
-      if (displayName == null) displayName = "Anonymous";
-      long timestamp = new Date().getTime();
-      LokiGroupMessage message = new LokiGroupMessage(hexEncodedPublicKey, displayName, body, timestamp);
-      LokiGroupChatAPI.sendMessage(message, LokiGroupChatAPI.getPublicChatID()).success(new Function1<Unit, Unit>() {
-
-        @Override
-        public Unit invoke(Unit unit) {
-          future.set(null);
-          return Unit.INSTANCE;
-        }
-      }).fail(new Function1<Exception, Unit>() {
-
-        @Override
-        public Unit invoke(Exception e) {
-          future.setException(e);
-          return Unit.INSTANCE;
-        }
-      });
-      return future;
+      try {
+        return sendGroupMessage();
+      } catch (Exception e) {
+        // Do nothing
+      }
     }
 
     if (!isDefaultSms && (!isSecureText || forceSms)) {
@@ -2165,6 +2146,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
 
     OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(recipient, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType, inputPanel.getQuote().orNull(), contacts, previews);
 
+    final SettableFuture<Void> future  = new SettableFuture<>();
     final Context              context = getApplicationContext();
 
     final OutgoingMediaMessage outgoingMessage;
@@ -2213,27 +2195,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
       throws InvalidMessageException
   {
     boolean isLokiPublicChat = isGroupConversation(); // TODO: Figure out a better way of determining this
-    if (isLokiPublicChat) {
-      String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
-      String displayName = DatabaseFactory.getLokiAPIDatabase(this).getUserDisplayName();
-      if (displayName == null) displayName = "Anonymous";
-      long timestamp = new Date().getTime();
-      LokiGroupMessage message = new LokiGroupMessage(hexEncodedPublicKey, displayName, getMessage(), timestamp);
-      LokiGroupChatAPI.sendMessage(message, LokiGroupChatAPI.getPublicChatID()).success(new Function1<Unit, Unit>() {
-
-        @Override
-        public Unit invoke(Unit unit) {
-          return Unit.INSTANCE;
-        }
-      }).fail(new Function1<Exception, Unit>() {
-
-        @Override
-        public Unit invoke(Exception e) {
-          return null;
-        }
-      });
-      return;
-    }
+    if (isLokiPublicChat) { sendGroupMessage(); return; }
 
     if (!isDefaultSms && (!isSecureText || forceSms)) {
       showDefaultSmsPrompt();
@@ -2791,5 +2753,22 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
     String contactID = DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(this.threadId).getAddress().toString();
     DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(contactID);
   }
+
+  public ListenableFuture<Void> sendGroupMessage() throws InvalidMessageException {
+    final SettableFuture<Void> future  = new SettableFuture<>();
+    String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
+    String displayName = DatabaseFactory.getLokiAPIDatabase(this).getUserDisplayName();
+    if (displayName == null) displayName = "Anonymous";
+    long timestamp = new Date().getTime();
+    LokiGroupMessage message = new LokiGroupMessage(hexEncodedPublicKey, displayName, getMessage(), timestamp);
+    LokiGroupChatAPI.sendMessage(message, LokiGroupChatAPI.getPublicChatID()).success(unit -> {
+      future.set(null);
+      return Unit.INSTANCE;
+    }).fail(e -> {
+      future.setException(e);
+      return Unit.INSTANCE;
+    });
+    return future;
+  }
   // endregion
 }