From 761c12addd234dd6c8e26df352375a0342be6598 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 29 Apr 2021 10:02:07 +1000 Subject: [PATCH] Clean --- .../securesms/ApplicationContext.java | 3 +- .../conversation/ConversationActivity.java | 2 +- .../securesms/database/GroupDatabase.java | 2 +- .../loki/activities/LinkDeviceActivity.kt | 2 +- .../RecoveryPhraseRestoreActivity.kt | 2 +- .../securesms/loki/activities/SeedActivity.kt | 2 +- .../loki/database/LokiAPIDatabase.kt | 2 +- .../loki/database/LokiMessageDatabase.kt | 3 +- .../loki/database/LokiUserDatabase.kt | 2 +- .../securesms/loki/dialogs/SeedDialog.kt | 2 +- .../securesms/loki/utilities/Broadcaster.kt | 3 +- .../loki/utilities/MnemonicUtilities.kt | 4 -- .../views/MentionCandidateSelectionView.kt | 2 +- .../loki/views/MentionCandidateView.kt | 2 +- .../messaging/file_server/FileServerAPI.kt | 2 +- .../messaging/jobs/AttachmentUploadJob.kt | 2 +- .../messaging/mentions/MentionsManager.kt | 4 +- .../messaging/open_groups/OpenGroupAPI.kt | 13 +++-- .../messaging/utilities/DotNetAPI.kt | 2 +- .../libsession/snode/OnionRequestAPI.kt | 6 ++- .../org/session/libsession/snode/SnodeAPI.kt | 6 +-- .../session/libsession/snode/SnodeModule.kt | 4 +- .../api/crypto/SignalServiceCipher.java | 3 +- .../api/messages/shared/SharedContact.java | 1 - .../loki/{utilities => }/Broadcaster.kt | 2 +- .../service/loki/{api/utilities => }/HTTP.kt | 2 +- .../loki/{utilities => }/HexEncoding.kt | 0 .../{database => }/LokiAPIDatabaseProtocol.kt | 2 +- .../LokiMessageDatabaseProtocol.kt | 2 +- .../LokiOpenGroupDatabaseProtocol.kt | 2 +- .../LokiUserDatabaseProtocol.kt | 2 +- .../loki/{utilities/mentions => }/Mention.kt | 2 +- .../loki/{crypto => }/MnemonicCodec.kt | 15 +++--- .../PlaintextOutputStreamFactory.kt | 2 +- .../{utilities => }/PrettifiedDescription.kt | 0 .../service/loki/{utilities => }/Random.kt | 0 .../loki/{utilities => }/Reflection.kt | 0 .../service/loki/{utilities => }/Retrying.kt | 0 .../loki/{api/crypto => }/SessionProtocol.kt | 2 +- .../loki/{api => }/SignalMessageInfo.kt | 2 +- .../service/loki/{utilities => }/Trimming.kt | 0 .../loki/{utilities => }/Validation.kt | 0 .../loki/api/utilities/OKHTTPUtilities.kt | 49 ------------------- .../session/libsignal/utilities/JsonUtil.java | 23 +-------- .../libsignal/utilities/PromiseUtilities.kt | 14 ------ .../libsignal/utilities/ThreadUtils.kt | 5 +- 46 files changed, 56 insertions(+), 146 deletions(-) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Broadcaster.kt (66%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{api/utilities => }/HTTP.kt (98%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/HexEncoding.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{database => }/LokiAPIDatabaseProtocol.kt (97%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{database => }/LokiMessageDatabaseProtocol.kt (76%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{database => }/LokiOpenGroupDatabaseProtocol.kt (76%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{database => }/LokiUserDatabaseProtocol.kt (81%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities/mentions => }/Mention.kt (52%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{crypto => }/MnemonicCodec.kt (97%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/PlaintextOutputStreamFactory.kt (92%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/PrettifiedDescription.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Random.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Reflection.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Retrying.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{api/crypto => }/SessionProtocol.kt (97%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{api => }/SignalMessageInfo.kt (88%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Trimming.kt (100%) rename libsignal/src/main/java/org/session/libsignal/service/loki/{utilities => }/Validation.kt (100%) delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/OKHTTPUtilities.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index e5b8b7fd5a..00a2c4f01f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -49,7 +49,7 @@ import org.session.libsession.utilities.dynamiclanguage.DynamicLanguageContextWr import org.session.libsession.utilities.dynamiclanguage.LocaleParser; import org.session.libsession.utilities.preferences.ProfileKeyUtil; import org.session.libsignal.service.api.util.StreamDetails; -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol; +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol; import org.session.libsignal.utilities.logging.Log; import org.signal.aesgcmprovider.AesGcmProvider; import org.thoughtcrime.securesms.components.TypingStatusSender; @@ -93,7 +93,6 @@ import org.webrtc.voiceengine.WebRtcAudioUtils; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.security.SecureRandom; import java.security.Security; import java.util.Date; 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 80a6ffb5d8..56e44d6b25 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -95,7 +95,7 @@ import org.session.libsession.utilities.GroupUtil; import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.guava.Optional; -import org.session.libsignal.service.loki.utilities.mentions.Mention; +import org.session.libsignal.service.loki.Mention; import org.session.libsignal.service.loki.utilities.HexEncodingKt; import org.session.libsignal.service.loki.utilities.PublicKeyValidation; import org.thoughtcrime.securesms.ApplicationContext; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java index fb1fbd6d28..7f3d0cd97f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java @@ -25,7 +25,7 @@ import org.session.libsession.utilities.Util; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer; -import org.session.libsignal.service.loki.database.LokiOpenGroupDatabaseProtocol; +import org.session.libsignal.service.loki.LokiOpenGroupDatabaseProtocol; import java.io.Closeable; import java.security.SecureRandom; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LinkDeviceActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LinkDeviceActivity.kt index 6f3ef464bc..cc878e4beb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LinkDeviceActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LinkDeviceActivity.kt @@ -27,7 +27,7 @@ import kotlinx.coroutines.launch import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.KeyHelper -import org.session.libsignal.service.loki.crypto.MnemonicCodec +import org.session.libsignal.service.loki.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey import org.session.libsignal.utilities.Hex import org.session.libsignal.utilities.logging.Log diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt index 24d160f880..0ee7e0f574 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt @@ -15,7 +15,7 @@ import kotlinx.android.synthetic.main.activity_recovery_phrase_restore.* import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.KeyHelper -import org.session.libsignal.service.loki.crypto.MnemonicCodec +import org.session.libsignal.service.loki.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey import org.session.libsignal.utilities.Hex import org.thoughtcrime.securesms.BaseActionBarActivity diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt index 2c79b4fc87..9ee8025335 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt @@ -16,7 +16,7 @@ import org.session.libsession.utilities.IdentityKeyUtil import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.crypto.MnemonicCodec +import org.session.libsignal.service.loki.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPrivateKey class SeedActivity : BaseActionBarActivity() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt index 58b9aeeec7..06da1f0676 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt @@ -8,7 +8,7 @@ import org.session.libsignal.libsignal.ecc.DjbECPrivateKey import org.session.libsignal.libsignal.ecc.DjbECPublicKey import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.service.loki.Snode -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.utilities.PublicKeyValidation 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/database/LokiMessageDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt index 66c1907405..1da93f7ec3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.loki.database import android.content.ContentValues import android.content.Context -import org.session.libsession.messaging.threads.Address import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper @@ -10,7 +9,7 @@ import org.thoughtcrime.securesms.loki.utilities.get import org.thoughtcrime.securesms.loki.utilities.getInt import org.thoughtcrime.securesms.loki.utilities.getString import org.thoughtcrime.securesms.loki.utilities.insertOrUpdate -import org.session.libsignal.service.loki.database.LokiMessageDatabaseProtocol +import org.session.libsignal.service.loki.LokiMessageDatabaseProtocol class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiMessageDatabaseProtocol { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt index 05e5f666db..cea0f52d9f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt @@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.loki.utilities.get import org.thoughtcrime.securesms.loki.utilities.insertOrUpdate import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.database.LokiUserDatabaseProtocol +import org.session.libsignal.service.loki.LokiUserDatabaseProtocol class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt index 12446cf57b..d327efe973 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/SeedDialog.kt @@ -15,7 +15,7 @@ import kotlinx.android.synthetic.main.dialog_seed.view.* import network.loki.messenger.R import org.session.libsession.utilities.IdentityKeyUtil import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities -import org.session.libsignal.service.loki.crypto.MnemonicCodec +import org.session.libsignal.service.loki.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPrivateKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/Broadcaster.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/Broadcaster.kt index 5156ff2572..dfc42c9340 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/Broadcaster.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/Broadcaster.kt @@ -3,8 +3,9 @@ package org.thoughtcrime.securesms.loki.utilities import android.content.Context import android.content.Intent import androidx.localbroadcastmanager.content.LocalBroadcastManager +import org.session.libsignal.service.loki.Broadcaster -class Broadcaster(private val context: Context) : org.session.libsignal.service.loki.utilities.Broadcaster { +class Broadcaster(private val context: Context) : Broadcaster { override fun broadcast(event: String) { val intent = Intent(event) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MnemonicUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MnemonicUtilities.kt index 27a2a78cfc..226bb1abfd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MnemonicUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MnemonicUtilities.kt @@ -1,10 +1,6 @@ package org.thoughtcrime.securesms.loki.utilities import android.content.Context -import org.session.libsignal.service.loki.crypto.MnemonicCodec -import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded -import java.io.File -import java.io.FileOutputStream object MnemonicUtilities { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateSelectionView.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateSelectionView.kt index ddda015d77..2da55501cf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateSelectionView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateSelectionView.kt @@ -10,7 +10,7 @@ import android.widget.ListView import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.mms.GlideRequests -import org.session.libsignal.service.loki.utilities.mentions.Mention +import org.session.libsignal.service.loki.Mention class MentionCandidateSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) { private var mentionCandidates = listOf() diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateView.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateView.kt index f7af85ed13..f353402806 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/views/MentionCandidateView.kt @@ -9,7 +9,7 @@ import android.widget.LinearLayout import kotlinx.android.synthetic.main.view_mention_candidate.view.* import network.loki.messenger.R import org.session.libsession.messaging.open_groups.OpenGroupAPI -import org.session.libsignal.service.loki.utilities.mentions.Mention +import org.session.libsignal.service.loki.Mention import org.thoughtcrime.securesms.mms.GlideRequests class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/file_server/FileServerAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/file_server/FileServerAPI.kt index 5e78caf6f0..b4a1861875 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/file_server/FileServerAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/file_server/FileServerAPI.kt @@ -8,7 +8,7 @@ import org.session.libsession.snode.OnionRequestAPI import org.session.libsignal.utilities.logging.Log import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.JsonUtil -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.utilities.* import java.net.URL diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt index ffdf459693..2d16b7b9b9 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt @@ -14,7 +14,7 @@ import org.session.libsignal.service.internal.crypto.PaddingInputStream import org.session.libsignal.service.internal.push.PushAttachmentData import org.session.libsignal.service.internal.push.http.AttachmentCipherOutputStreamFactory import org.session.libsignal.service.internal.util.Util -import org.session.libsignal.service.loki.utilities.PlaintextOutputStreamFactory +import org.session.libsignal.service.loki.PlaintextOutputStreamFactory import org.session.libsignal.utilities.logging.Log class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val message: Message, val messageSendJobID: String) : Job { diff --git a/libsession/src/main/java/org/session/libsession/messaging/mentions/MentionsManager.kt b/libsession/src/main/java/org/session/libsession/messaging/mentions/MentionsManager.kt index 715204825a..e421489b19 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/mentions/MentionsManager.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/mentions/MentionsManager.kt @@ -1,9 +1,9 @@ package org.session.libsession.messaging.mentions import org.session.libsession.messaging.MessagingModuleConfiguration -import org.session.libsignal.service.loki.utilities.mentions.Mention +import org.session.libsignal.service.loki.Mention -import org.session.libsignal.service.loki.database.LokiUserDatabaseProtocol +import org.session.libsignal.service.loki.LokiUserDatabaseProtocol class MentionsManager(private val userPublicKey: String, private val userDatabase: LokiUserDatabaseProtocol) { var userPublicKeyCache = mutableMapOf>() // Thread ID to set of user hex encoded public keys diff --git a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPI.kt index bd70118abd..0aba366d9f 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupAPI.kt @@ -21,7 +21,6 @@ import java.util.* object OpenGroupAPI: DotNetAPI() { private val moderators: HashMap>> = hashMapOf() // Server URL to (channel ID to set of moderator IDs) - val sharedContext = Kovenant.createContext() // region Settings private val fallbackBatchCount = 64 @@ -61,7 +60,7 @@ object OpenGroupAPI: DotNetAPI() { parameters["count"] = fallbackBatchCount parameters["include_deleted"] = 0 } - return execute(HTTPVerb.GET, server, "channels/$channel/messages", parameters = parameters).then(sharedContext) { json -> + return execute(HTTPVerb.GET, server, "channels/$channel/messages", parameters = parameters).then { json -> try { val data = json["data"] as List> val messages = data.mapNotNull { message -> @@ -166,7 +165,7 @@ object OpenGroupAPI: DotNetAPI() { } else { parameters["count"] = fallbackBatchCount } - return execute(HTTPVerb.GET, server, "loki/v1/channel/$channel/deletes", parameters = parameters).then(sharedContext) { json -> + return execute(HTTPVerb.GET, server, "loki/v1/channel/$channel/deletes", parameters = parameters).then { json -> try { val deletedMessageServerIDs = (json["data"] as List>).mapNotNull { deletion -> try { @@ -202,7 +201,7 @@ object OpenGroupAPI: DotNetAPI() { retryIfNeeded(maxRetryCount) { Log.d("Loki", "Sending message to open group with ID: $channel on server: $server.") val parameters = signedMessage.toJSON() - execute(HTTPVerb.POST, server, "channels/$channel/messages", parameters = parameters).then(sharedContext) { json -> + execute(HTTPVerb.POST, server, "channels/$channel/messages", parameters = parameters).then { json -> try { val data = json["data"] as Map<*, *> val serverID = (data["id"] as? Long) ?: (data["id"] as? Int)?.toLong() ?: (data["id"] as String).toLong() @@ -255,7 +254,7 @@ object OpenGroupAPI: DotNetAPI() { @JvmStatic fun getModerators(channel: Long, server: String): Promise, Exception> { - return execute(HTTPVerb.GET, server, "loki/v1/channel/$channel/get_moderators").then(sharedContext) { json -> + return execute(HTTPVerb.GET, server, "loki/v1/channel/$channel/get_moderators").then { json -> try { @Suppress("UNCHECKED_CAST") val moderators = json["moderators"] as? List val moderatorsAsSet = moderators.orEmpty().toSet() @@ -276,7 +275,7 @@ object OpenGroupAPI: DotNetAPI() { fun getChannelInfo(channel: Long, server: String): Promise { return retryIfNeeded(maxRetryCount) { val parameters = mapOf( "include_annotations" to 1 ) - execute(HTTPVerb.GET, server, "/channels/$channel", parameters = parameters).then(sharedContext) { json -> + execute(HTTPVerb.GET, server, "/channels/$channel", parameters = parameters).then { json -> try { val data = json["data"] as Map<*, *> val annotations = data["annotations"] as List> @@ -357,7 +356,7 @@ object OpenGroupAPI: DotNetAPI() { @JvmStatic fun getDisplayNames(publicKeys: Set, server: String): Promise, Exception> { - return getUserProfiles(publicKeys, server, false).map(sharedContext) { json -> + return getUserProfiles(publicKeys, server, false).map { json -> val mapping = mutableMapOf() for (user in json) { if (user["username"] != null) { 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 562715a90a..1fac9ca922 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 @@ -23,7 +23,7 @@ import org.session.libsignal.service.internal.push.http.DigestingRequestBody import org.session.libsignal.service.internal.push.http.ProfileCipherOutputStreamFactory 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.HTTP import org.session.libsignal.service.loki.utilities.* import org.session.libsignal.utilities.* import org.session.libsignal.utilities.Base64 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 6a9bd70fdf..ba103ee42c 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -12,12 +12,14 @@ import org.session.libsignal.utilities.logging.Log import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.* import org.session.libsignal.service.loki.Snode -import org.session.libsignal.service.loki.api.utilities.* +import org.session.libsignal.service.loki.* import org.session.libsession.utilities.AESGCM.EncryptionResult import org.session.libsignal.utilities.ThreadUtils import org.session.libsession.utilities.getBodyForOnionRequest import org.session.libsession.utilities.getHeadersForOnionRequest -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.Broadcaster +import org.session.libsignal.service.loki.HTTP +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.utilities.* private typealias Path = List 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 afb3050d99..b4209f6ff5 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -10,9 +10,9 @@ import org.session.libsession.messaging.utilities.MessageWrapper import org.session.libsession.snode.utilities.getRandomElement import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.loki.Snode -import org.session.libsignal.service.loki.api.utilities.HTTP -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol -import org.session.libsignal.service.loki.utilities.Broadcaster +import org.session.libsignal.service.loki.HTTP +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.Broadcaster import org.session.libsignal.service.loki.utilities.prettifiedDescription import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded import org.session.libsignal.service.loki.utilities.retryIfNeeded diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt index 95613ffda2..0d9381ab95 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt @@ -1,7 +1,7 @@ package org.session.libsession.snode -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol -import org.session.libsignal.service.loki.utilities.Broadcaster +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.Broadcaster class SnodeModule(val storage: LokiAPIDatabaseProtocol, val broadcaster: Broadcaster) { diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/SignalServiceCipher.java b/libsignal/src/main/java/org/session/libsignal/service/api/crypto/SignalServiceCipher.java index a8c2ca0bd9..5e425464ea 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/crypto/SignalServiceCipher.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/crypto/SignalServiceCipher.java @@ -22,7 +22,6 @@ import org.session.libsignal.service.api.messages.SignalServiceEnvelope; import org.session.libsignal.service.api.messages.SignalServiceGroup; import org.session.libsignal.service.api.messages.SignalServiceReceiptMessage; import org.session.libsignal.service.api.messages.SignalServiceTypingMessage; -import org.session.libsignal.service.api.messages.shared.SharedContact; import org.session.libsignal.service.api.push.SignalServiceAddress; import org.session.libsignal.service.internal.push.PushTransportDetails; import org.session.libsignal.service.internal.push.SignalServiceProtos; @@ -34,7 +33,7 @@ import org.session.libsignal.service.internal.push.SignalServiceProtos.ReceiptMe import org.session.libsignal.service.internal.push.SignalServiceProtos.TypingMessage; import org.session.libsignal.service.loki.api.crypto.SessionProtocol; import org.session.libsignal.service.loki.api.crypto.SessionProtocolUtilities; -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol; +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol; import java.util.ArrayList; import java.util.LinkedList; diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/messages/shared/SharedContact.java b/libsignal/src/main/java/org/session/libsignal/service/api/messages/shared/SharedContact.java index 75ee56835d..6993eb8189 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/messages/shared/SharedContact.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/messages/shared/SharedContact.java @@ -1,6 +1,5 @@ package org.session.libsignal.service.api.messages.shared; - import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.messages.SignalServiceAttachment; diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Broadcaster.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Broadcaster.kt similarity index 66% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Broadcaster.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Broadcaster.kt index 17106c00b8..a251b89459 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Broadcaster.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/Broadcaster.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.utilities +package org.session.libsignal.service.loki interface Broadcaster { diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/HTTP.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/HTTP.kt similarity index 98% rename from libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/HTTP.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/HTTP.kt index 29d1cddb6e..11e7ed6154 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/HTTP.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/HTTP.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.api.utilities +package org.session.libsignal.service.loki import okhttp3.* import org.session.libsignal.utilities.logging.Log diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/HexEncoding.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/HexEncoding.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/HexEncoding.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/HexEncoding.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiAPIDatabaseProtocol.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiAPIDatabaseProtocol.kt similarity index 97% rename from libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiAPIDatabaseProtocol.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/LokiAPIDatabaseProtocol.kt index d564706ee8..a771b38ef9 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiAPIDatabaseProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiAPIDatabaseProtocol.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.database +package org.session.libsignal.service.loki import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.service.loki.Snode diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiMessageDatabaseProtocol.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiMessageDatabaseProtocol.kt similarity index 76% rename from libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiMessageDatabaseProtocol.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/LokiMessageDatabaseProtocol.kt index 45f162de63..694d989af7 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiMessageDatabaseProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiMessageDatabaseProtocol.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.database +package org.session.libsignal.service.loki interface LokiMessageDatabaseProtocol { diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiOpenGroupDatabaseProtocol.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiOpenGroupDatabaseProtocol.kt similarity index 76% rename from libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiOpenGroupDatabaseProtocol.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/LokiOpenGroupDatabaseProtocol.kt index 5380c1a8fe..4c983e33fc 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiOpenGroupDatabaseProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiOpenGroupDatabaseProtocol.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.database +package org.session.libsignal.service.loki interface LokiOpenGroupDatabaseProtocol { diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiUserDatabaseProtocol.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiUserDatabaseProtocol.kt similarity index 81% rename from libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiUserDatabaseProtocol.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/LokiUserDatabaseProtocol.kt index 6879ee893a..b4428a4edf 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/database/LokiUserDatabaseProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/LokiUserDatabaseProtocol.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.database +package org.session.libsignal.service.loki interface LokiUserDatabaseProtocol { diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/mentions/Mention.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Mention.kt similarity index 52% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/mentions/Mention.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Mention.kt index 8d97c45268..0dd2165854 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/mentions/Mention.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/Mention.kt @@ -1,3 +1,3 @@ -package org.session.libsignal.service.loki.utilities.mentions +package org.session.libsignal.service.loki data class Mention(val publicKey: String, val displayName: String) diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/MnemonicCodec.kt similarity index 97% rename from libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/MnemonicCodec.kt index b3c15dd132..122354f33d 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/crypto/MnemonicCodec.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/MnemonicCodec.kt @@ -1,6 +1,5 @@ -package org.session.libsignal.service.loki.crypto +package org.session.libsignal.service.loki -import java.io.File import java.util.zip.CRC32 /** @@ -95,8 +94,10 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { var result = "" val n = truncatedWordSet.size.toLong() // Check preconditions - if (words.size < 12) { throw DecodingError.InputTooShort } - if (words.size % 3 == 0) { throw DecodingError.MissingLastWord } + if (words.size < 12) { throw DecodingError.InputTooShort + } + if (words.size % 3 == 0) { throw DecodingError.MissingLastWord + } // Get checksum word val checksumWord = words.removeAt(words.lastIndex) // Decode @@ -106,7 +107,8 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { val w2 = truncatedWordSet.indexOf(words[chunkStartIndex + 1].substring(0 until prefixLength)) val w3 = truncatedWordSet.indexOf(words[chunkStartIndex + 2].substring(0 until prefixLength)) val x = w1 + n * ((n - w1 + w2) % n) + n * n * ((n - w2 + w3) % n) - if (x % n != w1.toLong()) { throw DecodingError.Generic } + if (x % n != w1.toLong()) { throw DecodingError.Generic + } val string = "0000000" + x.toString(16) result += swap(string.substring(string.length - 8 until string.length)) } catch (e: Exception) { @@ -116,7 +118,8 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { // Verify checksum val checksumIndex = determineChecksumIndex(words, prefixLength) val expectedChecksumWord = words[checksumIndex] - if (expectedChecksumWord.substring(0 until prefixLength) != checksumWord.substring(0 until prefixLength)) { throw DecodingError.VerificationFailed } + if (expectedChecksumWord.substring(0 until prefixLength) != checksumWord.substring(0 until prefixLength)) { throw DecodingError.VerificationFailed + } // Return return result } diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PlaintextOutputStreamFactory.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/PlaintextOutputStreamFactory.kt similarity index 92% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PlaintextOutputStreamFactory.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/PlaintextOutputStreamFactory.kt index b913289b08..412f66458f 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PlaintextOutputStreamFactory.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/PlaintextOutputStreamFactory.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.utilities +package org.session.libsignal.service.loki import org.session.libsignal.service.api.crypto.DigestingOutputStream import org.session.libsignal.service.internal.push.http.OutputStreamFactory diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PrettifiedDescription.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/PrettifiedDescription.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/PrettifiedDescription.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/PrettifiedDescription.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Random.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Random.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Random.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Random.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Reflection.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Reflection.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Reflection.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Reflection.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Retrying.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Retrying.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Retrying.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Retrying.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/crypto/SessionProtocol.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/SessionProtocol.kt similarity index 97% rename from libsignal/src/main/java/org/session/libsignal/service/loki/api/crypto/SessionProtocol.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/SessionProtocol.kt index 3851919052..201ad4e85d 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/crypto/SessionProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/SessionProtocol.kt @@ -1,7 +1,7 @@ package org.session.libsignal.service.loki.api.crypto import org.session.libsignal.libsignal.ecc.ECKeyPair -import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol +import org.session.libsignal.service.loki.LokiAPIDatabaseProtocol interface SessionProtocol { diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SignalMessageInfo.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/SignalMessageInfo.kt similarity index 88% rename from libsignal/src/main/java/org/session/libsignal/service/loki/api/SignalMessageInfo.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/SignalMessageInfo.kt index 5b41d26a5f..f5e20f4168 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/SignalMessageInfo.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/SignalMessageInfo.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.service.loki.api +package org.session.libsignal.service.loki import org.session.libsignal.service.internal.push.SignalServiceProtos diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Trimming.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Trimming.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Trimming.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Trimming.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Validation.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/Validation.kt similarity index 100% rename from libsignal/src/main/java/org/session/libsignal/service/loki/utilities/Validation.kt rename to libsignal/src/main/java/org/session/libsignal/service/loki/Validation.kt diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/OKHTTPUtilities.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/OKHTTPUtilities.kt deleted file mode 100644 index 442edc5549..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/utilities/OKHTTPUtilities.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.session.libsignal.service.loki.api.utilities - -import okhttp3.MultipartBody -import okhttp3.Request -import okio.Buffer -import org.session.libsignal.utilities.Base64 -import java.io.IOException -import java.util.* - -internal fun Request.getHeadersForOnionRequest(): Map { - val result = mutableMapOf() - val contentType = body()?.contentType() - if (contentType != null) { - result["content-type"] = contentType.toString() - } - val headers = headers() - for (name in headers.names()) { - val value = headers.get(name) - if (value != null) { - if (value.toLowerCase(Locale.US) == "true" || value.toLowerCase(Locale.US) == "false") { - result[name] = value.toBoolean() - } else if (value.toIntOrNull() != null) { - result[name] = value.toInt() - } else { - result[name] = value - } - } - } - return result -} - -internal fun Request.getBodyForOnionRequest(): Any? { - try { - val copyOfThis = newBuilder().build() - val buffer = Buffer() - val body = copyOfThis.body() ?: return null - body.writeTo(buffer) - val bodyAsData = buffer.readByteArray() - if (body is MultipartBody) { - val base64EncodedBody: String = Base64.encodeBytes(bodyAsData) - return mapOf( "fileUpload" to base64EncodedBody ) - } else { - val charset = body.contentType()?.charset() ?: Charsets.UTF_8 - return bodyAsData?.toString(charset) - } - } catch (e: IOException) { - return null - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/JsonUtil.java b/libsignal/src/main/java/org/session/libsignal/utilities/JsonUtil.java index b20a870d10..f5767a8da2 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/JsonUtil.java +++ b/libsignal/src/main/java/org/session/libsignal/utilities/JsonUtil.java @@ -58,7 +58,7 @@ public class JsonUtil { return objectMapper.writeValueAsString(object); } - public static String toJson(Object object) { + public static String toJson(Object object) { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { @@ -67,32 +67,11 @@ public class JsonUtil { } } - public static class IdentityKeySerializer extends JsonSerializer { - @Override - public void serialize(IdentityKey value, JsonGenerator gen, SerializerProvider serializers) - throws IOException - { - gen.writeString(Base64.encodeBytesWithoutPadding(value.serialize())); - } - } - - public static class IdentityKeyDeserializer extends JsonDeserializer { - @Override - public IdentityKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - try { - return new IdentityKey(Base64.decodeWithoutPadding(p.getValueAsString()), 0); - } catch (InvalidKeyException e) { - throw new IOException(e); - } - } - } - public static ObjectMapper getMapper() { return objectMapper; } public static class SaneJSONObject { - private final JSONObject delegate; public SaneJSONObject(JSONObject delegate) { diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt b/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt index 8fe7ce7355..530d432d57 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/PromiseUtilities.kt @@ -1,25 +1,11 @@ @file:JvmName("PromiseUtilities") package org.session.libsignal.utilities -import nl.komponents.kovenant.Context -import nl.komponents.kovenant.Kovenant import nl.komponents.kovenant.Promise import nl.komponents.kovenant.deferred -import nl.komponents.kovenant.jvm.asDispatcher import org.session.libsignal.utilities.logging.Log -import java.util.concurrent.Executors import java.util.concurrent.TimeoutException -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() diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt b/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt index 1ad277f345..9436a54832 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/ThreadUtils.kt @@ -3,7 +3,6 @@ package org.session.libsignal.utilities import java.util.concurrent.* object ThreadUtils { - val executorPool = Executors.newCachedThreadPool() @JvmStatic @@ -17,10 +16,8 @@ object ThreadUtils { @JvmStatic fun newDynamicSingleThreadedExecutor(): ExecutorService { - val executor = ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, - LinkedBlockingQueue()) + val executor = ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, LinkedBlockingQueue()) executor.allowCoreThreadTimeOut(true) return executor } - } \ No newline at end of file