From c7af1cabe3864ebb4987168a57b1f859184eb521 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 1 Feb 2021 12:10:48 +1100 Subject: [PATCH] clean --- .../securesms/audio/AudioRecorder.java | 6 +- .../GlideBitmapListeningTarget.java | 2 +- .../GlideDrawableListeningTarget.java | 2 +- .../securesms/components/InputPanel.java | 4 +- .../securesms/components/ThumbnailView.java | 4 +- .../components/location/SignalMapView.java | 4 +- .../conversation/ConversationActivity.java | 4 +- .../ConversationPopupActivity.java | 3 +- .../securesms/jobs/PushDecryptJob.java | 2 +- .../securesms/logging/PersistentLogger.java | 4 +- .../securesms/loki/activities/HomeActivity.kt | 3 +- .../securesms/loki/api/ClosedGroupPoller.kt | 3 +- .../securesms/loki/api/PublicChatPoller.kt | 3 +- .../loki/protocol/ClosedGroupsProtocolV2.kt | 2 +- .../securesms/loki/utilities/IP2Country.kt | 2 +- .../mediasend/MediaSendFragment.java | 4 +- .../securesms/mms/AttachmentManager.java | 6 +- .../OptimizedMessageNotifier.java | 2 +- .../messaging/opengroups/OpenGroupAPI.kt | 7 +- .../pollers/ClosedGroupPoller.kt | 2 +- .../pollers/OpenGroupPoller.kt | 3 +- .../messaging/utilities/DotNetAPI.kt | 1 + .../libsession/snode/OnionRequestAPI.kt | 4 +- .../snode/OnionRequestEncryption.kt | 2 +- .../org/session/libsession/snode/SnodeAPI.kt | 3 +- .../libsession/utilities/ViewUtil.java | 4 +- .../concurrent/AssertedSuccessListener.java | 2 +- .../api/SignalServiceMessageSender.java | 2 +- .../util/concurrent/ListenableFuture.java | 13 -- .../util/concurrent/SettableFuture.java | 117 ------------------ .../websocket/WebSocketConnection.java | 2 +- .../libsignal/service/loki/api/DotNetAPI.kt | 2 +- .../libsignal/service/loki/api/LokiMessage.kt | 2 +- .../libsignal/service/loki/api/SnodeAPI.kt | 1 + .../libsignal/service/loki/api/SwarmAPI.kt | 2 +- .../loki/api/onionrequests/OnionRequestAPI.kt | 1 + .../onionrequests/OnionRequestEncryption.kt | 2 +- .../loki/api/opengroups/PublicChatAPI.kt | 3 +- .../loki/utilities/PromiseUtilities.kt | 40 ------ .../libsignal}/utilities/PromiseUtilities.kt | 3 +- .../loki => }/utilities/ThreadUtils.kt | 2 +- .../concurrent/ListenableFuture.java | 2 +- .../utilities/concurrent/SettableFuture.java | 2 +- 43 files changed, 53 insertions(+), 231 deletions(-) delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/ListenableFuture.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/SettableFuture.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PromiseUtilities.kt rename {libsession/src/main/java/org/session/libsession => libsignal/src/main/java/org/session/libsignal}/utilities/PromiseUtilities.kt (95%) rename libsignal/src/main/java/org/session/libsignal/{service/loki => }/utilities/ThreadUtils.kt (91%) rename {libsession/src/main/java/org/session/libsession => libsignal/src/main/java/org/session/libsignal}/utilities/concurrent/ListenableFuture.java (85%) rename {libsession/src/main/java/org/session/libsession => libsignal/src/main/java/org/session/libsignal}/utilities/concurrent/SettableFuture.java (98%) diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java index 7e94f3cdb8..580bd688f5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java @@ -12,10 +12,10 @@ import android.util.Pair; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.util.MediaUtil; -import org.session.libsignal.service.loki.utilities.ThreadUtils; +import org.session.libsignal.utilities.ThreadUtils; import org.session.libsession.utilities.Util; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.io.IOException; import java.util.concurrent.ExecutorService; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java b/app/src/main/java/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java index acb267e203..ea5103dc12 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/GlideBitmapListeningTarget.java @@ -8,7 +8,7 @@ import android.widget.ImageView; import com.bumptech.glide.request.target.BitmapImageViewTarget; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; public class GlideBitmapListeningTarget extends BitmapImageViewTarget { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java b/app/src/main/java/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java index 9a2c594230..0c8b502448 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/GlideDrawableListeningTarget.java @@ -7,7 +7,7 @@ import android.widget.ImageView; import com.bumptech.glide.request.target.DrawableImageViewTarget; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; public class GlideDrawableListeningTarget extends DrawableImageViewTarget { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/InputPanel.java b/app/src/main/java/org/thoughtcrime/securesms/components/InputPanel.java index 6c7958ed4e..b625c61349 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/InputPanel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/InputPanel.java @@ -44,8 +44,8 @@ import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.Util; import org.session.libsession.utilities.ViewUtil; import org.session.libsession.utilities.concurrent.AssertedSuccessListener; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import org.session.libsignal.libsignal.util.guava.Optional; import java.util.List; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ThumbnailView.java b/app/src/main/java/org/thoughtcrime/securesms/components/ThumbnailView.java index 4ca23c773e..9dc35bfcc2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ThumbnailView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ThumbnailView.java @@ -33,8 +33,8 @@ import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsession.utilities.Util; import org.session.libsession.utilities.ViewUtil; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.util.Collections; import java.util.Locale; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/location/SignalMapView.java b/app/src/main/java/org/thoughtcrime/securesms/components/location/SignalMapView.java index 176b86866d..744ac64f8b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/location/SignalMapView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/location/SignalMapView.java @@ -11,8 +11,8 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import org.session.libsession.utilities.ViewUtil; 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 b4b6d73d7a..ba2965f6a8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -204,8 +204,8 @@ import org.session.libsession.utilities.ExpirationUtil; import org.session.libsession.utilities.views.Stub; import org.session.libsession.utilities.ViewUtil; import org.session.libsession.utilities.concurrent.AssertedSuccessListener; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.TextSecurePreferences.MediaKeyboardMode; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java index 6ab5325334..1dd4a345b9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java @@ -10,11 +10,10 @@ import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; import android.view.WindowManager; import org.thoughtcrime.securesms.logging.Log; -import org.session.libsession.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; import java.util.concurrent.ExecutionException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index caec924e70..fb3304f4bb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -27,6 +27,7 @@ import org.session.libsignal.metadata.ProtocolNoSessionException; import org.session.libsignal.metadata.ProtocolUntrustedIdentityException; import org.session.libsignal.metadata.SelfSendException; import org.session.libsignal.service.loki.api.crypto.SessionProtocol; +import org.session.libsignal.utilities.PromiseUtilities; import org.thoughtcrime.securesms.ApplicationContext; import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; @@ -40,7 +41,6 @@ import org.session.libsession.messaging.sending_receiving.attachments.StickerLoc import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier; -import org.session.libsession.utilities.PromiseUtilities; import org.session.libsession.utilities.GroupUtil; import org.session.libsession.utilities.TextSecurePreferences; diff --git a/app/src/main/java/org/thoughtcrime/securesms/logging/PersistentLogger.java b/app/src/main/java/org/thoughtcrime/securesms/logging/PersistentLogger.java index df814c8391..51eb70f4c0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/logging/PersistentLogger.java +++ b/app/src/main/java/org/thoughtcrime/securesms/logging/PersistentLogger.java @@ -6,8 +6,8 @@ import androidx.annotation.WorkerThread; import org.thoughtcrime.securesms.database.NoExternalStorageException; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.io.ByteArrayOutputStream; import java.io.File; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index b685a73de8..e23e7bb531 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.database.Cursor -import android.net.Uri import android.os.Bundle import android.text.Spannable import android.text.SpannableString @@ -51,7 +50,7 @@ import org.session.libsignal.service.loki.protocol.meta.SessionMetaProtocol import org.session.libsignal.service.loki.protocol.sessionmanagement.SessionManagementProtocol import org.session.libsignal.service.loki.protocol.shelved.multidevice.MultiDeviceProtocol import org.session.libsignal.service.loki.protocol.shelved.syncmessages.SyncMessagesProtocol -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.toHexString import org.thoughtcrime.securesms.loki.dialogs.* import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocolV2 diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt index 6df63603e1..aa17f4a784 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt @@ -8,9 +8,8 @@ import nl.komponents.kovenant.functional.map import org.thoughtcrime.securesms.jobs.PushContentReceiveJob import org.thoughtcrime.securesms.logging.Log import org.thoughtcrime.securesms.loki.database.SharedSenderKeysDatabase -import org.session.libsession.utilities.successBackground +import org.session.libsignal.utilities.successBackground import org.session.libsignal.service.api.messages.SignalServiceEnvelope -import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.loki.api.SnodeAPI import org.session.libsignal.service.loki.api.SwarmAPI import org.session.libsignal.service.loki.utilities.getRandomElementOrNull diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt index edc811f550..6bd6f80ffd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt @@ -14,10 +14,10 @@ import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobs.PushDecryptJob import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol -import org.session.libsession.utilities.successBackground import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.guava.Optional +import org.session.libsignal.utilities.successBackground import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer import org.session.libsignal.service.api.messages.SignalServiceContent import org.session.libsignal.service.api.messages.SignalServiceDataMessage @@ -31,7 +31,6 @@ import org.session.libsignal.service.loki.api.opengroups.PublicChatMessage import org.session.libsignal.service.loki.protocol.shelved.multidevice.MultiDeviceProtocol import java.security.MessageDigest import java.util.* -import java.util.concurrent.CompletableFuture class PublicChatPoller(private val context: Context, private val group: PublicChat) { private val handler by lazy { Handler() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt index 7c76829a58..ad544e9327 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt @@ -12,7 +12,7 @@ import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.libsignal.util.guava.Optional import org.session.libsignal.service.api.messages.SignalServiceGroup import org.session.libsignal.service.internal.push.SignalServiceProtos -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded import org.session.libsignal.service.loki.utilities.toHexString diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt index e2a64eb652..6c78762f44 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/IP2Country.kt @@ -8,7 +8,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager import org.thoughtcrime.securesms.logging.Log import com.opencsv.CSVReader import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import java.io.File import java.io.FileOutputStream import java.io.FileReader diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java index 505af715b8..8300f0866d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java @@ -52,8 +52,8 @@ import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.Util; import org.session.libsession.utilities.views.Stub; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java index e9a3c21146..7fc01e672c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -67,9 +67,9 @@ import org.session.libsession.utilities.ViewUtil; import org.session.libsession.utilities.views.Stub; import org.session.libsession.utilities.Util; import org.session.libsession.utilities.concurrent.AssertedSuccessListener; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.ListenableFuture.Listener; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture.Listener; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.io.File; import java.io.IOException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java index 3e63383882..ade793e48b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java @@ -10,7 +10,7 @@ import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.loki.api.PublicChatManager; import org.thoughtcrime.securesms.util.Debouncer; import org.session.libsignal.service.loki.api.Poller; -import org.session.libsignal.service.loki.utilities.ThreadUtils; +import org.session.libsignal.utilities.ThreadUtils; import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier; diff --git a/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt index dd583b185e..908c0b30b3 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt @@ -9,15 +9,12 @@ import org.session.libsession.messaging.MessagingConfiguration import org.session.libsession.messaging.utilities.DotNetAPI import org.session.libsession.messaging.fileserver.FileServerAPI -import org.session.libsignal.service.loki.utilities.ThreadUtils -import org.session.libsession.utilities.createContext import org.session.libsignal.libsignal.logging.Log -import org.session.libsignal.utilities.Hex -import org.session.libsignal.utilities.Base64 -import org.session.libsignal.utilities.JsonUtil +import org.session.libsignal.utilities.* import org.session.libsignal.service.loki.utilities.DownloadUtilities import org.session.libsignal.service.loki.utilities.retryIfNeeded +import org.session.libsignal.utilities.Base64 import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat import java.util.* diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt index 674c37d6f1..a130f229f5 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt @@ -10,7 +10,7 @@ import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.messaging.jobs.MessageReceiveJob import org.session.libsession.messaging.utilities.MessageWrapper import org.session.libsession.snode.SnodeAPI -import org.session.libsession.utilities.successBackground +import org.session.libsignal.utilities.successBackground import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.utilities.Base64 diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt index 1f618801de..d65079273f 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt @@ -11,9 +11,8 @@ import org.session.libsession.messaging.jobs.MessageReceiveJob import org.session.libsession.messaging.opengroups.OpenGroup import org.session.libsession.messaging.opengroups.OpenGroupAPI import org.session.libsession.messaging.opengroups.OpenGroupMessage -import org.session.libsession.utilities.GroupUtil -import org.session.libsession.utilities.successBackground +import org.session.libsignal.utilities.successBackground import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.service.internal.push.SignalServiceProtos.* diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt index dd27f07d1a..10408398f1 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt @@ -26,6 +26,7 @@ import org.session.libsignal.utilities.Hex import org.session.libsignal.utilities.JsonUtil import org.session.libsignal.service.loki.api.utilities.HTTP import org.session.libsignal.service.loki.utilities.* +import org.session.libsignal.utilities.* import org.session.libsignal.utilities.Base64 import java.io.File diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index cb0940bfc7..138efcfc75 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -9,12 +9,12 @@ import okhttp3.Request import org.session.libsession.utilities.AESGCM import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.utilities.Base64 -import org.session.libsignal.utilities.JsonUtil +import org.session.libsignal.utilities.* import org.session.libsignal.service.loki.api.* import org.session.libsignal.service.loki.api.fileserver.FileServerAPI import org.session.libsignal.service.loki.api.utilities.* import org.session.libsession.utilities.AESGCM.EncryptionResult -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsession.utilities.getBodyForOnionRequest import org.session.libsession.utilities.getHeadersForOnionRequest import org.session.libsignal.service.loki.utilities.* diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt index 283641986a..c0e1e77b25 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt @@ -5,7 +5,7 @@ import nl.komponents.kovenant.deferred import org.session.libsignal.utilities.JsonUtil import org.session.libsession.utilities.AESGCM.EncryptionResult import org.session.libsession.utilities.AESGCM -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.toHexString import java.nio.Buffer import java.nio.ByteBuffer diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 2973931c70..b9592f28f6 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -7,13 +7,12 @@ import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.functional.map import org.session.libsession.snode.utilities.getRandomElement -import org.session.libsignal.service.loki.utilities.ThreadUtils -import org.session.libsession.utilities.createContext import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.service.loki.api.utilities.HTTP import org.session.libsignal.service.loki.utilities.prettifiedDescription import org.session.libsignal.service.loki.utilities.retryIfNeeded +import org.session.libsignal.utilities.* import java.security.SecureRandom diff --git a/libsession/src/main/java/org/session/libsession/utilities/ViewUtil.java b/libsession/src/main/java/org/session/libsession/utilities/ViewUtil.java index 07467e40fd..5249becd34 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ViewUtil.java +++ b/libsession/src/main/java/org/session/libsession/utilities/ViewUtil.java @@ -39,8 +39,8 @@ import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import org.session.libsession.utilities.concurrent.ListenableFuture; -import org.session.libsession.utilities.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.ListenableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import org.session.libsession.utilities.views.Stub; public class ViewUtil { diff --git a/libsession/src/main/java/org/session/libsession/utilities/concurrent/AssertedSuccessListener.java b/libsession/src/main/java/org/session/libsession/utilities/concurrent/AssertedSuccessListener.java index 7c21fa095f..bda2ecc474 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/concurrent/AssertedSuccessListener.java +++ b/libsession/src/main/java/org/session/libsession/utilities/concurrent/AssertedSuccessListener.java @@ -1,6 +1,6 @@ package org.session.libsession.utilities.concurrent; -import org.session.libsession.utilities.concurrent.ListenableFuture.Listener; +import org.session.libsignal.utilities.concurrent.ListenableFuture.Listener; import java.util.concurrent.ExecutionException; diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java index 62c75fa183..48ca7244f7 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java @@ -64,7 +64,7 @@ import org.session.libsignal.service.internal.push.http.OutputStreamFactory; import org.session.libsignal.utilities.Base64; import org.session.libsignal.service.internal.util.StaticCredentialsProvider; import org.session.libsignal.service.internal.util.Util; -import org.session.libsignal.service.internal.util.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import org.session.libsignal.service.loki.api.LokiDotNetAPI; import org.session.libsignal.service.loki.api.PushNotificationAPI; import org.session.libsignal.service.loki.api.SignalMessageInfo; diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/ListenableFuture.java b/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/ListenableFuture.java deleted file mode 100644 index b284387892..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/ListenableFuture.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.session.libsignal.service.internal.util.concurrent; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -public interface ListenableFuture extends Future { - void addListener(Listener listener); - - public interface Listener { - public void onSuccess(T result); - public void onFailure(ExecutionException e); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/SettableFuture.java b/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/SettableFuture.java deleted file mode 100644 index 0f2c0c2540..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/util/concurrent/SettableFuture.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.session.libsignal.service.internal.util.concurrent; - -import org.session.libsignal.service.internal.util.concurrent.ListenableFuture; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -public class SettableFuture implements ListenableFuture { - - private final List> listeners = new LinkedList>(); - - private boolean completed; - private boolean canceled; - private volatile T result; - private volatile Throwable exception; - - @Override - public synchronized boolean cancel(boolean mayInterruptIfRunning) { - if (!completed && !canceled) { - canceled = true; - return true; - } - - return false; - } - - @Override - public synchronized boolean isCancelled() { - return canceled; - } - - @Override - public synchronized boolean isDone() { - return completed; - } - - public boolean set(T result) { - synchronized (this) { - if (completed || canceled) return false; - - this.result = result; - this.completed = true; - - notifyAll(); - } - - notifyAllListeners(); - return true; - } - - public boolean setException(Throwable throwable) { - synchronized (this) { - if (completed || canceled) return false; - - this.exception = throwable; - this.completed = true; - - notifyAll(); - } - - notifyAllListeners(); - return true; - } - - @Override - public synchronized T get() throws InterruptedException, ExecutionException { - while (!completed) wait(); - - if (exception != null) throw new ExecutionException(exception); - else return result; - } - - @Override - public synchronized T get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, TimeoutException - { - long startTime = System.currentTimeMillis(); - - while (!completed && System.currentTimeMillis() - startTime < unit.toMillis(timeout)) { - wait(unit.toMillis(timeout)); - } - - if (!completed) throw new TimeoutException(); - else return get(); - } - - @Override - public void addListener(Listener listener) { - synchronized (this) { - listeners.add(listener); - - if (!completed) return; - } - - notifyListener(listener); - } - - private void notifyAllListeners() { - List> localListeners; - - synchronized (this) { - localListeners = new LinkedList>(listeners); - } - - for (Listener listener : localListeners) { - notifyListener(listener); - } - } - - private void notifyListener(Listener listener) { - if (exception != null) listener.onFailure(new ExecutionException(exception)); - else listener.onSuccess(result); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/websocket/WebSocketConnection.java b/libsignal/src/main/java/org/session/libsignal/service/internal/websocket/WebSocketConnection.java index 684193b222..329b65c6a4 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/websocket/WebSocketConnection.java +++ b/libsignal/src/main/java/org/session/libsignal/service/internal/websocket/WebSocketConnection.java @@ -12,7 +12,7 @@ import org.session.libsignal.service.api.util.Tls12SocketFactory; import org.session.libsignal.service.api.websocket.ConnectivityListener; import org.session.libsignal.service.internal.util.BlacklistingTrustManager; import org.session.libsignal.service.internal.util.Util; -import org.session.libsignal.service.internal.util.concurrent.SettableFuture; +import org.session.libsignal.utilities.concurrent.SettableFuture; import java.io.IOException; import java.security.KeyManagementException; diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt index 1fae4e715b..0d5591335a 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt @@ -25,9 +25,9 @@ import org.session.libsignal.service.loki.api.fileserver.FileServerAPI import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI import org.session.libsignal.service.loki.api.utilities.HTTP import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol -import org.session.libsignal.service.loki.utilities.recover import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded import org.session.libsignal.service.loki.utilities.retryIfNeeded +import org.session.libsignal.utilities.recover import java.util.* /** diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/LokiMessage.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/LokiMessage.kt index 557cfa1e18..11611218e5 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/LokiMessage.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/LokiMessage.kt @@ -6,7 +6,7 @@ import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.utilities.Base64 import org.session.libsignal.service.loki.api.crypto.ProofOfWork import org.session.libsignal.service.loki.protocol.meta.TTLUtilities -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.prettifiedDescription internal data class LokiMessage( diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SnodeAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/SnodeAPI.kt index aa4535f937..6932653733 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SnodeAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/SnodeAPI.kt @@ -13,6 +13,7 @@ import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI import org.session.libsignal.service.loki.api.utilities.HTTP import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.utilities.* +import org.session.libsignal.utilities.* import java.net.ConnectException import java.net.SocketTimeoutException diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SwarmAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/SwarmAPI.kt index 918d6bf250..209836a93b 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SwarmAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/SwarmAPI.kt @@ -8,7 +8,7 @@ import nl.komponents.kovenant.task import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.service.loki.api.utilities.HTTP import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.getRandomElement import org.session.libsignal.service.loki.utilities.prettifiedDescription import org.session.libsignal.service.loki.utilities.retryIfNeeded diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestAPI.kt index 7bcadf0d05..08a43506dc 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestAPI.kt @@ -16,6 +16,7 @@ import org.session.libsignal.service.loki.api.utilities.EncryptionResult import org.session.libsignal.service.loki.api.utilities.getBodyForOnionRequest import org.session.libsignal.service.loki.api.utilities.getHeadersForOnionRequest import org.session.libsignal.service.loki.utilities.* +import org.session.libsignal.utilities.* private typealias Path = List diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestEncryption.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestEncryption.kt index 70d41e922f..63f1c9636e 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestEncryption.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/onionrequests/OnionRequestEncryption.kt @@ -5,7 +5,7 @@ import nl.komponents.kovenant.deferred import org.session.libsignal.utilities.JsonUtil import org.session.libsignal.service.loki.api.utilities.EncryptionResult import org.session.libsignal.service.loki.api.utilities.EncryptionUtilities -import org.session.libsignal.service.loki.utilities.ThreadUtils +import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.toHexString import java.nio.Buffer import java.nio.ByteBuffer diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/opengroups/PublicChatAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/opengroups/PublicChatAPI.kt index e56f4810ac..a592cdcbd2 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/opengroups/PublicChatAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/opengroups/PublicChatAPI.kt @@ -16,8 +16,7 @@ import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.database.LokiOpenGroupDatabaseProtocol import org.session.libsignal.service.loki.database.LokiUserDatabaseProtocol import org.session.libsignal.service.loki.utilities.DownloadUtilities -import org.session.libsignal.service.loki.utilities.ThreadUtils -import org.session.libsignal.service.loki.utilities.createContext +import org.session.libsignal.utilities.* import org.session.libsignal.service.loki.utilities.retryIfNeeded import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PromiseUtilities.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PromiseUtilities.kt deleted file mode 100644 index d7b268c279..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PromiseUtilities.kt +++ /dev/null @@ -1,40 +0,0 @@ -@file:JvmName("PromiseUtilities") -package org.session.libsignal.service.loki.utilities - -import nl.komponents.kovenant.* -import nl.komponents.kovenant.jvm.asDispatcher -import org.session.libsignal.libsignal.logging.Log -import java.util.concurrent.Executors - -fun Kovenant.createContext(): Context { - return createContext { - callbackContext.dispatcher = Executors.newSingleThreadExecutor().asDispatcher() - workerContext.dispatcher = ThreadUtils.executorPool.asDispatcher() - multipleCompletion = { v1, v2 -> - Log.d("Loki", "Promise resolved more than once (first with $v1, then with $v2); ignoring $v2.") - } - } -} - -fun Promise.get(defaultValue: V): V { - return try { - get() - } catch (e: Exception) { - defaultValue - } -} - -fun Promise.recover(callback: (exception: E) -> V): Promise { - val deferred = deferred() - success { - deferred.resolve(it) - }.fail { - try { - val value = callback(it) - deferred.resolve(value) - } catch (e: Throwable) { - deferred.reject(it) - } - } - return deferred.promise -} diff --git a/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt b/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt similarity index 95% rename from libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt rename to libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt index 50a70aa478..522de79490 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt @@ -1,5 +1,5 @@ @file:JvmName("PromiseUtilities") -package org.session.libsession.utilities +package org.session.libsignal.utilities import nl.komponents.kovenant.Context import nl.komponents.kovenant.Kovenant @@ -7,7 +7,6 @@ import nl.komponents.kovenant.Promise import nl.komponents.kovenant.deferred import nl.komponents.kovenant.jvm.asDispatcher import org.session.libsignal.libsignal.logging.Log -import org.session.libsignal.service.loki.utilities.ThreadUtils import java.util.concurrent.Executors import java.util.concurrent.TimeoutException diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt b/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt similarity index 91% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt rename to libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt index a7c56008e0..1ad277f345 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.utilities +package org.session.libsignal.utilities import java.util.concurrent.* diff --git a/libsession/src/main/java/org/session/libsession/utilities/concurrent/ListenableFuture.java b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/ListenableFuture.java similarity index 85% rename from libsession/src/main/java/org/session/libsession/utilities/concurrent/ListenableFuture.java rename to libsignal/src/main/java/org/session/libsignal/utilities/concurrent/ListenableFuture.java index 896bae9baf..d621f9db83 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/concurrent/ListenableFuture.java +++ b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/ListenableFuture.java @@ -1,4 +1,4 @@ -package org.session.libsession.utilities.concurrent; +package org.session.libsignal.utilities.concurrent; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; diff --git a/libsession/src/main/java/org/session/libsession/utilities/concurrent/SettableFuture.java b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java similarity index 98% rename from libsession/src/main/java/org/session/libsession/utilities/concurrent/SettableFuture.java rename to libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java index ab7b4cfaf1..cde571d5e1 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/concurrent/SettableFuture.java +++ b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java @@ -1,4 +1,4 @@ -package org.session.libsession.utilities.concurrent; +package org.session.libsignal.utilities.concurrent; import java.util.LinkedList; import java.util.List;