From e668341e38693adadcaebca66b3459c074b44c4e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 14 May 2020 13:52:20 +1000 Subject: [PATCH] Glue some things together again --- .../securesms/ApplicationContext.java | 5 +- .../securesms/ConversationListActivity.java | 7 --- .../conversation/ConversationActivity.java | 4 +- .../database/loaders/DeviceListLoader.java | 8 ++-- .../SignalCommunicationModule.java | 3 +- .../securesms/jobs/JobManagerFactories.java | 4 +- .../securesms/jobs/PushDecryptJob.java | 46 ++++++++++--------- .../securesms/loki/activities/HomeActivity.kt | 26 ++++++++--- .../loki/activities/PNModeActivity.kt | 8 ---- .../loki/api/LokiPublicChatPoller.kt | 20 ++++---- .../loki/protocol/FriendRequestProtocol.kt | 1 + .../protocol/SessionManagementProtocol.kt | 9 +++- .../loki/shelved/LokiRSSFeedPoller.kt | 2 +- .../loki/utilities/PromiseUtilities.kt | 15 ++++++ .../notifications/MessageNotifier.java | 4 -- 15 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/loki/utilities/PromiseUtilities.kt diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 7a496f3a53..3af959795f 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -19,7 +19,6 @@ package org.thoughtcrime.securesms; import android.arch.lifecycle.DefaultLifecycleObserver; import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.ProcessLifecycleOwner; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; @@ -106,6 +105,7 @@ import org.whispersystems.signalservice.loki.database.LokiAPIDatabaseProtocol; import org.whispersystems.signalservice.loki.protocol.friendrequests.FriendRequestProtocol; import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager; import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol; +import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink; import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol; import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionManagementProtocol; import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionManagementProtocolDelegate; @@ -201,7 +201,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc LokiPushNotificationAcknowledgement.Companion.configureIfNeeded(BuildConfig.DEBUG); if (setUpStorageAPIIfNeeded()) { if (userPublicKey != null) { - MultiDeviceUtilities.updateDeviceLinksOnServer(this); + Set deviceLinks = DatabaseFactory.getLokiAPIDatabase(this).getDeviceLinks(userPublicKey); + LokiFileServerAPI.shared.setDeviceLinks(deviceLinks); } } resubmitProfilePictureIfNeeded(); diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index 1c3180ee35..49fc125778 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -86,13 +86,6 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit protected void onPreCreate() { dynamicTheme.onCreate(this); dynamicLanguage.onCreate(this); - if (TextSecurePreferences.getLocalNumber(this) != null) { - ApplicationContext application = ApplicationContext.getInstance(this); - application.createDefaultPublicChatsIfNeeded(); - application.createRSSFeedsIfNeeded(); - application.getLokiPublicChatManager().startPollersIfNeeded(); - application.startRSSFeedPollersIfNeeded(); - } } @Override diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index d1c9208dea..ea3f2bbac2 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2272,7 +2272,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void updateInputPanel() { - boolean shouldInputPanelBeEnabled = FriendRequestProtocol.shouldInputPanelBeEnabled(this, threadId); + boolean shouldInputPanelBeEnabled = FriendRequestProtocol.shouldInputPanelBeEnabled(this, recipient); Util.runOnMain(() -> { updateToggleButtonState(); String hint = shouldInputPanelBeEnabled ? "Message" : "Pending session request"; @@ -2472,7 +2472,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void updateToggleButtonState() { - if (!FriendRequestProtocol.shouldAttachmentButtonBeEnabled(this, threadId)) { + if (!FriendRequestProtocol.shouldAttachmentButtonBeEnabled(this, recipient)) { buttonToggle.display(sendButton); quickAttachmentToggle.hide(); inlineAttachmentToggle.hide(); diff --git a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java index ad8513d37d..596d4f84f0 100644 --- a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java +++ b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java @@ -11,8 +11,8 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities; import org.thoughtcrime.securesms.util.AsyncLoader; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.whispersystems.signalservice.loki.protocol.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; +import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol; import java.io.File; import java.util.Collections; @@ -33,9 +33,9 @@ public class DeviceListLoader extends AsyncLoader> { @Override public List loadInBackground() { try { - String ourPublicKey = TextSecurePreferences.getLocalNumber(getContext()); - Set secondaryDevicePublicKeys = LokiDeviceLinkUtilities.INSTANCE.getSlaveHexEncodedPublicKeys(ourPublicKey).get(); - List devices = Stream.of(secondaryDevicePublicKeys).map(this::mapToDevice).toList(); + String userPublicKey = TextSecurePreferences.getLocalNumber(getContext()); + Set slaveDevicePublicKeys = MultiDeviceProtocol.shared.getSlaveDevices(userPublicKey); + List devices = Stream.of(slaveDevicePublicKeys).map(this::mapToDevice).toList(); Collections.sort(devices, new DeviceComparator()); return devices; } catch (Exception e) { diff --git a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index 28b147da98..b74af10069 100644 --- a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation; import org.thoughtcrime.securesms.loki.protocol.MultiDeviceOpenGroupUpdateJob; -import org.thoughtcrime.securesms.loki.PushMessageSyncSendJob; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; import org.thoughtcrime.securesms.push.MessageSenderEventListener; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; @@ -112,7 +111,6 @@ import network.loki.messenger.BuildConfig; MultiDeviceStickerPackOperationJob.class, MultiDeviceStickerPackSyncJob.class, LinkPreviewRepository.class, - PushMessageSyncSendJob.class, MultiDeviceOpenGroupUpdateJob.class}) public class SignalCommunicationModule { @@ -154,6 +152,7 @@ public class SignalCommunicationModule { Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()), Optional.of(new MessageSenderEventListener(context)), TextSecurePreferences.getLocalNumber(context), + TextSecurePreferences.getMasterHexEncodedPublicKey(context), DatabaseFactory.getLokiAPIDatabase(context), DatabaseFactory.getLokiThreadDatabase(context), DatabaseFactory.getLokiMessageDatabase(context), diff --git a/src/org/thoughtcrime/securesms/jobs/JobManagerFactories.java b/src/org/thoughtcrime/securesms/jobs/JobManagerFactories.java index 1da2302b74..a366bafe8c 100644 --- a/src/org/thoughtcrime/securesms/jobs/JobManagerFactories.java +++ b/src/org/thoughtcrime/securesms/jobs/JobManagerFactories.java @@ -15,7 +15,6 @@ import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraint; import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver; import org.thoughtcrime.securesms.loki.protocol.MultiDeviceOpenGroupUpdateJob; import org.thoughtcrime.securesms.loki.protocol.PushEphemeralMessageSendJob; -import org.thoughtcrime.securesms.loki.PushMessageSyncSendJob; import java.util.Arrays; import java.util.HashMap; @@ -71,8 +70,7 @@ public final class JobManagerFactories { put(TrimThreadJob.KEY, new TrimThreadJob.Factory()); put(TypingSendJob.KEY, new TypingSendJob.Factory()); put(UpdateApkJob.KEY, new UpdateApkJob.Factory()); - put(PushMessageSyncSendJob.KEY, new PushMessageSyncSendJob.Factory()); - put(PushEphemeralMessageSendJob.KEY, new PushEphemeralMessageSendJob.Factory()); + put(PushEphemeralMessageSendJob.KEY, new PushEphemeralMessageSendJob.Factory()); put(MultiDeviceOpenGroupUpdateJob.KEY, new MultiDeviceOpenGroupUpdateJob.Factory()); }}; } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index ffbce85a1c..922b3c520e 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -331,7 +331,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } // Loki - Handle friend request message if needed - FriendRequestProtocol.handleFriendRequestMessageIfNeeded(content); + FriendRequestProtocol.handleFriendRequestMessageIfNeeded(context, content.getSender(), content); } } else if (content.getSyncMessage().isPresent()) { TextSecurePreferences.setMultiDevice(context, true); @@ -803,8 +803,13 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); } - // Loki - Store message server ID if needed - updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); + // Loki - Store message open group server ID if needed + if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) { + long messageID = insertResult.get().getMessageId(); + long messageServerID = messageServerIDOrNull.get(); + LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context); + lokiMessageDatabase.setServerID(messageID, messageServerID); + } // Loki - Update mapping of message ID to original thread ID if (insertResult.isPresent()) { @@ -978,7 +983,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MentionsManager.shared.cache(textMessage.getSender().serialize(), result.getThreadId()); // Loki - Store message server ID - updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); + if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) { + long messageID = insertResult.get().getMessageId(); + long messageServerID = messageServerIDOrNull.get(); + LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context); + lokiMessageDatabase.setServerID(messageID, messageServerID); + } // Loki - Update mapping of message to original thread ID if (result.getMessageId() > -1) { @@ -1073,19 +1083,16 @@ public class PushDecryptJob extends BaseJob implements InjectableType { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); if (!smsMessageId.isPresent()) { - SmsMessageRecord lastMessage = getLastMessage(sender); - if (lastMessage == null || !SmsDatabase.Types.isFailedDecryptType(lastMessage.getType())) { - Optional insertResult = insertPlaceholder(sender, senderDevice, timestamp); + Optional insertResult = insertPlaceholder(sender, senderDevice, timestamp); - if (insertResult.isPresent()) { - smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); - } + if (insertResult.isPresent()) { + smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId()); + MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsDecryptFailed(smsMessageId.get()); } - triggerSessionRestorePrompt(sender); + SessionManagementProtocol.triggerSessionRestorationUI(context, sender); } private void handleNoSessionMessage(@NonNull String sender, int senderDevice, long timestamp, @@ -1094,19 +1101,16 @@ public class PushDecryptJob extends BaseJob implements InjectableType { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); if (!smsMessageId.isPresent()) { - SmsMessageRecord lastMessage = getLastMessage(sender); - if (lastMessage == null || !SmsDatabase.Types.isNoRemoteSessionType(lastMessage.getType())) { - Optional insertResult = insertPlaceholder(sender, senderDevice, timestamp); + Optional insertResult = insertPlaceholder(sender, senderDevice, timestamp); - if (insertResult.isPresent()) { - smsDatabase.markAsNoSession(insertResult.get().getMessageId()); - MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); - } + if (insertResult.isPresent()) { + smsDatabase.markAsNoSession(insertResult.get().getMessageId()); + MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); } } else { smsDatabase.markAsNoSession(smsMessageId.get()); } - triggerSessionRestorePrompt(sender); + SessionManagementProtocol.triggerSessionRestorationUI(context, sender); } private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp, @@ -1160,7 +1164,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { String url = content.senderProfilePictureURL.or(""); ApplicationContext.getInstance(context).getJobManager().add(new RetrieveProfileAvatarJob(recipient, url)); - SessionMetaProtocol.handleProfileKeyUpdateIfNeeded(content, message); + SessionMetaProtocol.handleProfileKeyUpdateIfNeeded(context, content); } } diff --git a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index 49d26d0122..8a05b8736b 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -32,8 +32,9 @@ import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.database.model.ThreadRecord import org.thoughtcrime.securesms.loki.dialogs.PNModeBottomSheet -import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol +import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation +import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.show import org.thoughtcrime.securesms.loki.views.ConversationView @@ -43,6 +44,11 @@ import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.notifications.MessageNotifier import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.signalservice.loki.protocol.friendrequests.FriendRequestProtocol +import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager +import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol +import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionManagementProtocol +import org.whispersystems.signalservice.loki.protocol.syncmessages.SyncMessagesProtocol import kotlin.math.abs class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListener, SeedReminderViewDelegate, NewConversationButtonSetViewDelegate { @@ -143,13 +149,21 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe val adapter = recyclerView.adapter as HomeAdapter adapter.typingThreadIDs = threadIDs ?: setOf() }) - // Set up public chats and RSS feeds if needed - if (TextSecurePreferences.getLocalNumber(this) != null) { + // Set up remaining components if needed + val userPublicKey = TextSecurePreferences.getLocalNumber(this) + if (userPublicKey != null) { val application = ApplicationContext.getInstance(this) - application.createDefaultPublicChatsIfNeeded() - application.createRSSFeedsIfNeeded() + val apiDB = DatabaseFactory.getLokiAPIDatabase(this) + val threadDB = DatabaseFactory.getLokiThreadDatabase(this) + val userDB = DatabaseFactory.getLokiUserDatabase(this) + val sessionResetImpl = LokiSessionResetImplementation(this) + FriendRequestProtocol.configureIfNeeded(apiDB, userPublicKey) + MentionsManager.configureIfNeeded(userPublicKey, threadDB, userDB) + SessionMetaProtocol.configureIfNeeded(apiDB, userPublicKey) + org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.configureIfNeeded(apiDB) + SessionManagementProtocol.configureIfNeeded(sessionResetImpl, threadDB, application) + SyncMessagesProtocol.configureIfNeeded(apiDB, userPublicKey) application.lokiPublicChatManager.startPollersIfNeeded() - application.startRSSFeedPollersIfNeeded() } } diff --git a/src/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt index 266fafa960..763c3cf6ba 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt @@ -12,7 +12,6 @@ import kotlinx.android.synthetic.main.activity_pn_mode.* import network.loki.messenger.R import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity -import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo import org.thoughtcrime.securesms.loki.utilities.show import org.thoughtcrime.securesms.util.TextSecurePreferences @@ -92,13 +91,6 @@ class PNModeActivity : BaseActionBarActivity() { val application = ApplicationContext.getInstance(this) application.setUpStorageAPIIfNeeded() application.setUpP2PAPIIfNeeded() - val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI - if (publicChatAPI != null) { - // TODO: This won't be necessary anymore when we don't auto-join the Loki Public Chat anymore - application.createDefaultPublicChatsIfNeeded() - val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers() - servers.forEach { publicChatAPI.setDisplayName(displayName, it) } - } application.registerForFCMIfNeeded(true) val intent = Intent(this, HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK diff --git a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt index afd72105b7..b1b9ef5652 100644 --- a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.Handler import android.util.Log import nl.komponents.kovenant.Promise +import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.then import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.crypto.IdentityKeyUtil @@ -11,6 +12,7 @@ import org.thoughtcrime.securesms.database.Address import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobs.PushDecryptJob import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob +import org.thoughtcrime.securesms.loki.utilities.successBackground import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.libsignal.util.guava.Optional @@ -21,12 +23,11 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage import org.whispersystems.signalservice.api.push.SignalServiceAddress import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI -import org.whispersystems.signalservice.loki.protocol.multidevice.LokiDeviceLinkUtilities import org.whispersystems.signalservice.loki.api.opengroups.LokiPublicChat import org.whispersystems.signalservice.loki.api.opengroups.LokiPublicChatAPI import org.whispersystems.signalservice.loki.api.opengroups.LokiPublicChatMessage +import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus -import org.whispersystems.signalservice.loki.utilities.successBackground import java.security.MessageDigest import java.util.* @@ -157,7 +158,7 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki fun pollForNewMessages() { fun processIncomingMessage(message: LokiPublicChatMessage) { // If the sender of the current message is not a slave device, set the display name in the database - val masterHexEncodedPublicKey = LokiDeviceLinkUtilities.getMasterHexEncodedPublicKey(message.hexEncodedPublicKey).get() + val masterHexEncodedPublicKey = MultiDeviceProtocol.shared.getMasterDevice(message.hexEncodedPublicKey) if (masterHexEncodedPublicKey == null) { val senderDisplayName = "${message.displayName} (...${message.hexEncodedPublicKey.takeLast(8)})" DatabaseFactory.getLokiUserDatabase(context).setServerDisplayName(group.id, message.hexEncodedPublicKey, senderDisplayName) @@ -216,16 +217,13 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki } } } - var userDevices = setOf() + val userDevices = MultiDeviceProtocol.shared.getAllLinkedDevices(userHexEncodedPublicKey) var uniqueDevices = setOf() val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize() - val database = DatabaseFactory.getLokiAPIDatabase(context) - LokiFileServerAPI.configure(false, userHexEncodedPublicKey, userPrivateKey, database) + val apiDB = DatabaseFactory.getLokiAPIDatabase(context) + LokiFileServerAPI.configure(false, userHexEncodedPublicKey, userPrivateKey, apiDB) // Kovenant propagates a context to chained promises, so LokiPublicChatAPI.sharedContext should be used for all of the below - LokiDeviceLinkUtilities.getAllLinkedDeviceHexEncodedPublicKeys(userHexEncodedPublicKey).bind(LokiPublicChatAPI.sharedContext) { devices -> - userDevices = devices - api.getMessages(group.channel, group.server) - }.bind(LokiPublicChatAPI.sharedContext) { messages -> + api.getMessages(group.channel, group.server).bind(LokiPublicChatAPI.sharedContext) { messages -> if (messages.isNotEmpty()) { if (messages.count() == 1) { Log.d("Loki", "Fetched 1 new message.") @@ -243,7 +241,7 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki }.successBackground { val newDisplayNameUpdatees = uniqueDevices.mapNotNull { // This will return null if the current device is a master device - LokiDeviceLinkUtilities.getMasterHexEncodedPublicKey(it).get() + MultiDeviceProtocol.shared.getMasterDevice(it) }.toSet() // Fetch the display names of the master devices displayNameUpdatees = displayNameUpdatees.union(newDisplayNameUpdatees) diff --git a/src/org/thoughtcrime/securesms/loki/protocol/FriendRequestProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/FriendRequestProtocol.kt index 36dbddf019..a322f32efc 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/FriendRequestProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/FriendRequestProtocol.kt @@ -125,6 +125,7 @@ object FriendRequestProtocol { return false } + @JvmStatic fun getLastMessageID(context: Context, threadID: Long): Long? { val db = DatabaseFactory.getSmsDatabase(context) val messageCount = db.getMessageCountForThread(threadID) diff --git a/src/org/thoughtcrime/securesms/loki/protocol/SessionManagementProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/SessionManagementProtocol.kt index aed9bf0955..4c162db344 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/SessionManagementProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/SessionManagementProtocol.kt @@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.libsignal.loki.LokiSessionResetStatus import org.whispersystems.signalservice.api.messages.SignalServiceContent +import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus object SessionManagementProtocol { @@ -94,7 +95,11 @@ object SessionManagementProtocol { } @JvmStatic - private fun isSessionRequest(content: SignalServiceContent): Boolean { - return content.dataMessage.isPresent && content.dataMessage.get().isSessionRequest + fun triggerSessionRestorationUI(context: Context, publicKey: String) { + val masterDevicePublicKey = MultiDeviceProtocol.shared.getMasterDevice(publicKey) ?: publicKey + val masterDeviceAsRecipient = recipient(context, masterDevicePublicKey) + if (masterDeviceAsRecipient.isGroupRecipient) { return } + val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(masterDeviceAsRecipient) + DatabaseFactory.getLokiThreadDatabase(context).addSessionRestoreDevice(threadID, publicKey) } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/shelved/LokiRSSFeedPoller.kt b/src/org/thoughtcrime/securesms/loki/shelved/LokiRSSFeedPoller.kt index c983f49525..bfce10b4c3 100644 --- a/src/org/thoughtcrime/securesms/loki/shelved/LokiRSSFeedPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/shelved/LokiRSSFeedPoller.kt @@ -8,6 +8,7 @@ import com.prof.rssparser.engine.XMLParser import kotlinx.coroutines.Job import kotlinx.coroutines.Runnable import org.thoughtcrime.securesms.jobs.PushDecryptJob +import org.thoughtcrime.securesms.loki.utilities.successBackground import org.whispersystems.libsignal.util.guava.Optional import org.whispersystems.signalservice.api.messages.SignalServiceContent import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage @@ -15,7 +16,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup import org.whispersystems.signalservice.api.push.SignalServiceAddress import org.whispersystems.signalservice.loki.api.rssfeeds.LokiRSSFeed import org.whispersystems.signalservice.loki.api.rssfeeds.LokiRSSFeedProxy -import org.whispersystems.signalservice.loki.utilities.successBackground import java.text.SimpleDateFormat import java.util.regex.Pattern diff --git a/src/org/thoughtcrime/securesms/loki/utilities/PromiseUtilities.kt b/src/org/thoughtcrime/securesms/loki/utilities/PromiseUtilities.kt new file mode 100644 index 0000000000..0184f2f4e1 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/utilities/PromiseUtilities.kt @@ -0,0 +1,15 @@ +package org.thoughtcrime.securesms.loki.utilities + +import android.util.Log +import nl.komponents.kovenant.Promise + +fun Promise.successBackground(callback: (value: V) -> Unit): Promise { + Thread { + try { + callback(get()) + } catch (e: Exception) { + Log.d("Loki", "Failed to execute task in background: ${e.message}.") + } + }.start() + return this +} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 9382520aea..759ab268ea 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -49,7 +49,6 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.MultiDeviceUtilities; import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.recipients.Recipient; @@ -60,8 +59,6 @@ import org.thoughtcrime.securesms.util.SpanUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder; import org.whispersystems.signalservice.internal.util.Util; -import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus; -import org.whispersystems.signalservice.loki.utilities.PromiseUtil; import java.util.HashSet; import java.util.List; @@ -74,7 +71,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import me.leolin.shortcutbadger.ShortcutBadger; import network.loki.messenger.R; -import nl.komponents.kovenant.Promise; /** * Handles posting system notifications for new messages.