diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index a1abcd66ad..e623f38c9e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -111,6 +111,7 @@ import java.util.concurrent.Executors; import javax.inject.Inject; +import dagger.Lazy; import dagger.hilt.EntryPoints; import dagger.hilt.android.HiltAndroidApp; import kotlin.Deprecated; @@ -133,7 +134,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO private static final String TAG = ApplicationContext.class.getSimpleName(); - public MessageNotifier messageNotifier = null; public Poller poller = null; public Broadcaster broadcaster = null; private WindowDebouncer conversationListDebouncer; @@ -164,7 +164,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO @Inject TypingStatusRepository typingStatusRepository; @Inject TypingStatusSender typingStatusSender; @Inject ReadReceiptManager readReceiptManager; - + @Inject Lazy messageNotifierLazy; + @Inject LokiAPIDatabase apiDB; + @Inject EmojiSearchDatabase emojiSearchDb; private volatile boolean isAppVisible; @@ -180,14 +182,21 @@ public class ApplicationContext extends Application implements DefaultLifecycleO return (ApplicationContext) context.getApplicationContext(); } + @Deprecated(message = "Use proper DI to inject this component") public TextSecurePreferences getPrefs() { return EntryPoints.get(getApplicationContext(), AppComponent.class).getPrefs(); } + @Deprecated(message = "Use proper DI to inject this component") public DatabaseComponent getDatabaseComponent() { return EntryPoints.get(getApplicationContext(), DatabaseComponent.class); } + @Deprecated(message = "Use proper DI to inject this component") + public MessageNotifier getMessageNotifier() { + return messageNotifierLazy.get(); + } + public Handler getConversationListNotificationHandler() { if (this.conversationListHandlerThread == null) { conversationListHandlerThread = new HandlerThread("ConversationListHandler"); @@ -248,13 +257,11 @@ public class ApplicationContext extends Application implements DefaultLifecycleO NotificationChannels.create(this); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); AppContext.INSTANCE.configureKovenant(); - messageNotifier = new OptimizedMessageNotifier(new DefaultMessageNotifier()); broadcaster = new Broadcaster(this); - LokiAPIDatabase apiDB = getDatabaseComponent().lokiAPIDatabase(); boolean useTestNet = textSecurePreferences.getEnvironment() == Environment.TEST_NET; SnodeModule.Companion.configure(apiDB, broadcaster, useTestNet); initializePeriodicTasks(); - SSKEnvironment.Companion.configure(typingStatusRepository, readReceiptManager, profileManager, messageNotifier, expiringMessageManager); + SSKEnvironment.Companion.configure(typingStatusRepository, readReceiptManager, profileManager, getMessageNotifier(), expiringMessageManager); initializeWebRtc(); initializeBlobProvider(); resubmitProfilePictureIfNeeded(); @@ -319,7 +326,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO isAppVisible = false; Log.i(TAG, "App is no longer visible."); KeyCachingService.onAppBackgrounded(this); - messageNotifier.setVisibleThread(-1); + getMessageNotifier().setVisibleThread(-1); if (poller != null) { poller.stopIfNeeded(); } @@ -452,7 +459,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO private void loadEmojiSearchIndexIfNeeded() { Executors.newSingleThreadExecutor().execute(() -> { - EmojiSearchDatabase emojiSearchDb = getDatabaseComponent().emojiSearchDatabase(); if (emojiSearchDb.query("face", 1).isEmpty()) { try (InputStream inputStream = getAssets().open("emoji/emoji_search_index.json")) { List searchIndex = Arrays.asList(JsonUtil.fromJson(inputStream, EmojiSearchData[].class)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/app/src/main/java/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index 31d146c45f..8682579b2c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -49,7 +49,7 @@ public class DatabaseUpgradeActivity extends BaseActivity { new AsyncTask() { @Override protected Void doInBackground(Void... params) { - ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).getMessageNotifier().updateNotification(context); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index b6ac1f2808..f8c0ea81ae 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -14,9 +14,9 @@ import network.loki.messenger.libsession_util.util.GroupDisplayInfo import network.loki.messenger.libsession_util.util.GroupInfo import network.loki.messenger.libsession_util.util.UserPic import org.session.libsession.avatars.AvatarHelper +import org.session.libsession.database.MessageDataProvider import org.session.libsession.database.StorageProtocol import org.session.libsession.messaging.BlindedIdMapping -import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.calls.CallMessageType import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.jobs.AttachmentUploadJob @@ -49,11 +49,12 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview +import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel import org.session.libsession.messaging.utilities.SodiumUtilities import org.session.libsession.messaging.utilities.UpdateMessageData import org.session.libsession.snode.OnionRequestAPI -import org.session.libsession.snode.SnodeAPI +import org.session.libsession.snode.SnodeClock import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address.Companion.fromSerialized import org.session.libsession.utilities.GroupRecord @@ -113,6 +114,12 @@ open class Storage @Inject constructor( private val lokiThreadDatabase: LokiThreadDatabase, private val sessionContactDatabase: SessionContactDatabase, private val expirationConfigurationDatabase: ExpirationConfigurationDatabase, + private val profileManager: SSKEnvironment.ProfileManagerProtocol, + private val notificationManager: MessageNotifier, + private val messageDataProvider: MessageDataProvider, + private val messageExpirationManager: SSKEnvironment.MessageExpirationManagerProtocol, + private val clock: SnodeClock, + private val preferences: TextSecurePreferences, ) : Database(context, helper), StorageProtocol, ThreadDatabase.ConversationThreadUpdateListener { init { @@ -133,7 +140,7 @@ open class Storage @Inject constructor( val legacyGroup = configs.userGroups.getOrConstructLegacyGroupInfo(accountId) configs.userGroups.set(legacyGroup) val newVolatileParams = configs.convoInfoVolatile.getOrConstructLegacyGroup(accountId).copy( - lastRead = SnodeAPI.nowWithOffset, + lastRead = clock.currentTimeMills(), ) configs.convoInfoVolatile.set(newVolatileParams) } @@ -210,7 +217,7 @@ open class Storage @Inject constructor( } override fun getUserPublicKey(): String? { - return TextSecurePreferences.getLocalNumber(context) + return preferences.getLocalNumber() } override fun getUserX25519KeyPair(): ECKeyPair { @@ -291,18 +298,16 @@ open class Storage @Inject constructor( } override fun deleteMessagesByHash(threadId: Long, hashes: List) { - val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider val info = lokiMessageDatabase.getSendersForHashes(threadId, hashes.toSet()) // TODO: no idea if we need to server delete this for ((serverHash, sender, messageIdToDelete, isSms) in info) { messageDataProvider.updateMessageAsDeleted(messageIdToDelete, isSms) if (!messageDataProvider.isOutgoingMessage(messageIdToDelete)) { - SSKEnvironment.shared.notificationManager.updateNotification(context) + notificationManager.updateNotification(context) } } } override fun deleteMessagesByUser(threadId: Long, userSessionId: String) { - val messageDataProvider = MessagingModuleConfiguration.shared.messageDataProvider val userMessages = mmsSmsDatabase.getUserMessages(threadId, userSessionId) val (mmsMessages, smsMessages) = userMessages.partition { it.isMms } if (mmsMessages.isNotEmpty()) { @@ -684,7 +689,7 @@ open class Storage @Inject constructor( // message timestamp and as such we cannot use that to identify the local message. override fun markAsSentToCommunity(threadId: Long, messageID: Long) { val database = mmsSmsDatabase - val message = database.getLastSentMessageRecordFromSender(threadId, TextSecurePreferences.getLocalNumber(context)) + val message = database.getLastSentMessageRecordFromSender(threadId, preferences.getLocalNumber()) // Ensure we can find the local message.. if (message == null) { @@ -749,7 +754,7 @@ open class Storage @Inject constructor( // modifies the message timestamp and as such we cannot use that to identify the local message. override fun markUnidentifiedInCommunity(threadId: Long, messageId: Long) { val database = mmsSmsDatabase - val message = database.getLastSentMessageRecordFromSender(threadId, TextSecurePreferences.getLocalNumber(context)) + val message = database.getLastSentMessageRecordFromSender(threadId, preferences.getLocalNumber()) // Check to ensure the message exists if (message == null) { @@ -1023,7 +1028,7 @@ open class Storage @Inject constructor( } override fun insertGroupInfoChange(message: GroupUpdated, closedGroup: AccountId): Long? { - val sentTimestamp = message.sentTimestamp ?: SnodeAPI.nowWithOffset + val sentTimestamp = message.sentTimestamp ?: clock.currentTimeMills() val senderPublicKey = message.sender val groupName = configFactory.withGroupConfigs(closedGroup) { it.groupInfo.getName() } @@ -1033,7 +1038,7 @@ open class Storage @Inject constructor( } override fun insertGroupInfoLeaving(closedGroup: AccountId): Long? { - val sentTimestamp = SnodeAPI.nowWithOffset + val sentTimestamp = clock.currentTimeMills() val senderPublicKey = getUserPublicKey() ?: return null val updateData = UpdateMessageData.buildGroupLeaveUpdate(UpdateMessageData.Kind.GroupLeaving) @@ -1211,7 +1216,7 @@ open class Storage @Inject constructor( sessionContactDatabase.setContact(contact) val address = fromSerialized(contact.accountID) if (!getRecipientApproved(address)) return - val recipientHash = SSKEnvironment.shared.profileManager.contactUpdatedInternal(contact) + val recipientHash = profileManager.contactUpdatedInternal(contact) val recipient = Recipient.from(context, address, false) setRecipientHash(recipient, recipientHash) } @@ -1234,7 +1239,6 @@ open class Storage @Inject constructor( val id = AccountId(contact.id) id.prefix?.isBlinded() == false || mappingDb.getBlindedIdMapping(contact.id).none { it.accountId != null } } - val profileManager = SSKEnvironment.shared.profileManager moreContacts.forEach { contact -> val address = fromSerialized(contact.id) val recipient = Recipient.from(context, address, false) @@ -1510,8 +1514,7 @@ open class Storage @Inject constructor( ) database.insertSecureDecryptedMessageInbox(mediaMessage, threadId, runThreadUpdate = true) - - SSKEnvironment.shared.messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode) + messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode) } /** @@ -1543,7 +1546,6 @@ open class Storage @Inject constructor( val threadId = getOrCreateThreadIdFor(sender.address) val profile = response.profile if (profile != null) { - val profileManager = SSKEnvironment.shared.profileManager val name = profile.displayName!! if (name.isNotEmpty()) { profileManager.setName(context, sender, name) @@ -1629,7 +1631,7 @@ open class Storage @Inject constructor( val mmsDb = mmsDatabase val message = IncomingMediaMessage( fromSerialized(userPublicKey), - SnodeAPI.nowWithOffset, + clock.currentTimeMills(), -1, 0, 0, @@ -1684,7 +1686,7 @@ open class Storage @Inject constructor( val expireStartedAt = if (expiryMode is ExpiryMode.AfterSend) sentTimestamp else 0 val callMessage = IncomingTextMessage.fromCallInfo(callMessageType, address, Optional.absent(), sentTimestamp, expiresInMillis, expireStartedAt) database.insertCallMessage(callMessage) - SSKEnvironment.shared.messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode) + messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode) } override fun conversationHasOutgoing(userPublicKey: String): Boolean { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index bd38a59a51..bb0436f3df 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -768,7 +768,7 @@ public class ThreadDatabase extends Database { if (mmsSmsDatabase.getConversationCount(threadId) <= 0 && !force) return false; List messages = setRead(threadId, lastSeenTime); MarkReadReceiver.process(context, messages); - ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, threadId); + ApplicationContext.getInstance(context).getMessageNotifier().updateNotification(context, threadId); return setLastSeen(threadId, lastSeenTime); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/AppModule.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/AppModule.kt index ba899527d2..a06cd9404f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/AppModule.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/AppModule.kt @@ -9,17 +9,16 @@ import dagger.hilt.EntryPoint import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import org.session.libsession.database.StorageProtocol import org.session.libsession.messaging.groups.GroupManagerV2 +import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier import org.session.libsession.utilities.AppTextSecurePreferences import org.session.libsession.utilities.ConfigFactoryProtocol import org.session.libsession.utilities.SSKEnvironment import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.Toaster -import org.session.libsignal.database.LokiAPIDatabaseProtocol -import org.thoughtcrime.securesms.database.LokiAPIDatabase -import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.groups.GroupManagerV2Impl +import org.thoughtcrime.securesms.notifications.DefaultMessageNotifier +import org.thoughtcrime.securesms.notifications.OptimizedMessageNotifier import org.thoughtcrime.securesms.repository.ConversationRepository import org.thoughtcrime.securesms.repository.DefaultConversationRepository import org.thoughtcrime.securesms.sskenvironment.ProfileManager @@ -27,7 +26,18 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) -abstract class AppModule { +class AppModule { + + @Provides + @Singleton + fun provideMessageNotifier(): MessageNotifier { + return OptimizedMessageNotifier(DefaultMessageNotifier()) + } +} + +@Module +@InstallIn(SingletonComponent::class) +abstract class AppBindings { @Binds abstract fun bindTextSecurePreferences(preferences: AppTextSecurePreferences): TextSecurePreferences diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index be6eac3db7..f48bc02174 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -35,6 +35,7 @@ import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.session.libsession.messaging.groups.GroupManagerV2 import org.session.libsession.messaging.jobs.JobQueue +import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier import org.session.libsession.snode.SnodeClock import org.session.libsession.utilities.Address import org.session.libsession.utilities.ProfilePictureModifiedEvent @@ -103,6 +104,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), @Inject lateinit var lokiThreadDatabase: LokiThreadDatabase @Inject lateinit var sessionJobDatabase: SessionJobDatabase @Inject lateinit var clock: SnodeClock + @Inject lateinit var messageNotifier: MessageNotifier private val globalSearchViewModel by viewModels() private val homeViewModel by viewModels() @@ -354,7 +356,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), override fun onResume() { super.onResume() - ApplicationContext.getInstance(this).messageNotifier.setHomeScreenVisible(true) + messageNotifier.setHomeScreenVisible(true) if (textSecurePreferences.getLocalNumber() == null) { return; } // This can be the case after a secondary device is auto-cleared IdentityKeyUtil.checkUpdate(this) binding.profileButton.recycle() // clear cached image before update tje profilePictureView diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java index 88f92ecb48..2d22a13532 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java @@ -68,7 +68,7 @@ public class AndroidAutoHeardReceiver extends BroadcastReceiver { messageIdsCollection.addAll(messageIds); } - ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).getMessageNotifier().updateNotification(context); MarkReadReceiver.process(context, messageIdsCollection); return null; diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java index 0bfa2b0899..91f0941479 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java @@ -109,7 +109,7 @@ public class AndroidAutoReplyReceiver extends BroadcastReceiver { List messageIds = DatabaseComponent.get(context).threadDatabase().setRead(replyThreadId, true); - ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); + ApplicationContext.getInstance(context).getMessageNotifier().updateNotification(context); MarkReadReceiver.process(context, messageIds); return null; diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java index 8db5f810b4..7fb29b9bd7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DeleteNotificationReceiver.java @@ -17,7 +17,7 @@ public class DeleteNotificationReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) { - ApplicationContext.getInstance(context).messageNotifier.clearReminder(context); + ApplicationContext.getInstance(context).getMessageNotifier().clearReminder(context); final long[] ids = intent.getLongArrayExtra(EXTRA_IDS); final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS); diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java index cf0e04ddf4..c1391b9a8f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java @@ -31,11 +31,11 @@ import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage; import org.session.libsession.messaging.messages.signal.OutgoingTextMessage; import org.session.libsession.messaging.messages.visible.VisibleMessage; import org.session.libsession.messaging.sending_receiving.MessageSender; -import org.session.libsession.snode.SnodeAPI; +import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier; +import org.session.libsession.snode.SnodeClock; import org.session.libsession.utilities.Address; import org.session.libsession.utilities.recipients.Recipient; import org.session.libsignal.utilities.Log; -import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.MarkedMessageInfo; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase; @@ -70,6 +70,10 @@ public class RemoteReplyReceiver extends BroadcastReceiver { SmsDatabase smsDatabase; @Inject Storage storage; + @Inject + MessageNotifier messageNotifier; + @Inject + SnodeClock clock; @SuppressLint("StaticFieldLeak") @Override @@ -94,7 +98,7 @@ public class RemoteReplyReceiver extends BroadcastReceiver { Recipient recipient = Recipient.from(context, address, false); long threadId = threadDatabase.getOrCreateThreadIdFor(recipient); VisibleMessage message = new VisibleMessage(); - message.setSentTimestamp(SnodeAPI.getNowWithOffset()); + message.setSentTimestamp(clock.currentTimeMills()); message.setText(responseText.toString()); ExpirationConfiguration config = storage.getExpirationConfiguration(threadId); ExpiryMode expiryMode = config == null ? null : config.getExpiryMode(); @@ -124,7 +128,7 @@ public class RemoteReplyReceiver extends BroadcastReceiver { List messageIds = threadDatabase.setRead(threadId, true); - ApplicationContext.getInstance(context).messageNotifier.updateNotification(context); + messageNotifier.updateNotification(context); MarkReadReceiver.process(context, messageIds); return null; diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.kt b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.kt index 61114b3125..207bb2d30a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.service import android.content.Context +import dagger.Lazy import dagger.hilt.android.qualifiers.ApplicationContext import network.loki.messenger.libsession_util.util.ExpiryMode import network.loki.messenger.libsession_util.util.ExpiryMode.AfterSend @@ -13,7 +14,7 @@ import org.session.libsession.utilities.Address.Companion.fromSerialized import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.GroupUtil.doubleEncodeGroupID import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol -import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocalNumber +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.recipients.Recipient import org.session.libsignal.messages.SignalServiceGroup import org.session.libsignal.utilities.Hex @@ -41,7 +42,8 @@ class ExpiringMessageManager @Inject constructor( private val mmsDatabase: MmsDatabase, private val mmsSmsDatabase: MmsSmsDatabase, private val clock: SnodeClock, - private val storage: Storage, + private val storage: Lazy, + private val preferences: TextSecurePreferences, ) : MessageExpirationManagerProtocol { private val expiringMessageReferences = TreeSet() private val executor: Executor = Executors.newSingleThreadExecutor() @@ -97,7 +99,7 @@ class ExpiringMessageManager @Inject constructor( } recipient = Recipient.from(context, groupAddress, false) } - val threadId = storage.getThreadId(recipient) ?: return + val threadId = storage.get().getThreadId(recipient) ?: return val mediaMessage = IncomingMediaMessage( address, sentTimestamp!!, -1, expiresInMillis, expireStartedAt, true, @@ -137,7 +139,7 @@ class ExpiringMessageManager @Inject constructor( val address = fromSerialized(serializedAddress) val recipient = Recipient.from(context, address, false) - message.threadID = storage.getOrCreateThreadIdFor(address) + message.threadID = storage.get().getOrCreateThreadIdFor(address) val timerUpdateMessage = OutgoingExpirationUpdateMessage( recipient, sentTimestamp!!, @@ -161,7 +163,7 @@ class ExpiringMessageManager @Inject constructor( override fun insertExpirationTimerMessage(message: ExpirationTimerUpdate) { val expiryMode: ExpiryMode = message.expiryMode - val userPublicKey = getLocalNumber(context) + val userPublicKey = preferences.getLocalNumber() val senderPublicKey = message.sender val sentTimestamp = message.sentTimestamp ?: 0 val expireStartedAt = if ((expiryMode is AfterSend || message.isSenderSelf) && !message.isGroup) sentTimestamp else 0 diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java index 9d95ac5d49..a3f9d0d97f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -127,7 +127,7 @@ public class KeyCachingService extends Service { @Override protected Void doInBackground(Void... params) { if (!DatabaseUpgradeActivity.isUpdate(KeyCachingService.this)) { - ApplicationContext.getInstance(KeyCachingService.this).messageNotifier.updateNotification(KeyCachingService.this); + ApplicationContext.getInstance(KeyCachingService.this).getMessageNotifier().updateNotification(KeyCachingService.this); } return null; } @@ -193,7 +193,7 @@ public class KeyCachingService extends Service { new AsyncTask() { @Override protected Void doInBackground(Void... params) { - ApplicationContext.getInstance(KeyCachingService.this).messageNotifier.updateNotification(KeyCachingService.this); + ApplicationContext.getInstance(KeyCachingService.this).getMessageNotifier().updateNotification(KeyCachingService.this); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt index b11a05c5fe..b9f778c49e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.sskenvironment import android.content.Context +import dagger.Lazy import network.loki.messenger.libsession_util.util.UserPic import org.session.libsession.database.StorageProtocol import org.session.libsession.messaging.contacts.Contact @@ -21,7 +22,7 @@ import javax.inject.Singleton @Singleton class ProfileManager @Inject constructor( private val configFactory: ConfigFactoryProtocol, - private val storage: StorageProtocol, + private val storage: Lazy, private val contactDatabase: SessionContactDatabase, private val recipientDatabase: RecipientDatabase, private val jobDatabase: SessionJobDatabase, @@ -33,7 +34,7 @@ class ProfileManager @Inject constructor( val accountID = recipient.address.serialize() var contact = contactDatabase.getContactWithAccountID(accountID) if (contact == null) contact = Contact(accountID) - contact.threadID = storage.getThreadId(recipient.address) + contact.threadID = storage.get().getThreadId(recipient.address) if (contact.nickname != nickname) { contact.nickname = nickname contactDatabase.setContact(contact) @@ -47,7 +48,7 @@ class ProfileManager @Inject constructor( val accountID = recipient.address.serialize() var contact = contactDatabase.getContactWithAccountID(accountID) if (contact == null) contact = Contact(accountID) - contact.threadID = storage.getThreadId(recipient.address) + contact.threadID = storage.get().getThreadId(recipient.address) if (contact.name != name) { contact.name = name contactDatabase.setContact(contact) @@ -69,7 +70,7 @@ class ProfileManager @Inject constructor( (it.value as? RetrieveProfileAvatarJob)?.recipientAddress == recipient.address } val resolved = recipient.resolve() - storage.setProfilePicture( + storage.get().setProfilePicture( recipient = resolved, newProfileKey = profileKey, newProfilePicture = profilePictureURL @@ -77,7 +78,7 @@ class ProfileManager @Inject constructor( val accountID = recipient.address.serialize() var contact = contactDatabase.getContactWithAccountID(accountID) if (contact == null) contact = Contact(accountID) - contact.threadID = storage.getThreadId(recipient.address) + contact.threadID = storage.get().getThreadId(recipient.address) if (!contact.profilePictureEncryptionKey.contentEquals(profileKey) || contact.profilePictureURL != profilePictureURL) { contact.profilePictureEncryptionKey = profileKey contact.profilePictureURL = profilePictureURL diff --git a/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt b/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt index ac25cab2fa..9a9d85be48 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt @@ -28,6 +28,7 @@ class MessagingModuleConfiguration( companion object { @JvmStatic + @Deprecated("Use properly DI components instead") val shared: MessagingModuleConfiguration get() = context.getSystemService(MESSAGING_MODULE_SERVICE) as MessagingModuleConfiguration 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 a048cc124f..bb461e79e6 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeModule.kt @@ -8,6 +8,7 @@ class SnodeModule( ) { companion object { + @Deprecated("Use properly DI components instead") lateinit var shared: SnodeModule val isInitialized: Boolean get() = Companion::shared.isInitialized