mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-06 04:22:14 +00:00
Cleanup
This commit is contained in:
@@ -76,7 +76,7 @@ import org.thoughtcrime.securesms.notifications.BackgroundPollWorker;
|
||||
import org.thoughtcrime.securesms.notifications.DefaultMessageNotifier;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.notifications.OptimizedMessageNotifier;
|
||||
import org.thoughtcrime.securesms.notifications.PushManager;
|
||||
import org.thoughtcrime.securesms.notifications.PushRegistry;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
@@ -146,7 +146,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
@Inject Device device;
|
||||
@Inject MessageDataProvider messageDataProvider;
|
||||
@Inject TextSecurePreferences textSecurePreferences;
|
||||
@Inject PushManager pushManager;
|
||||
@Inject PushRegistry pushRegistry;
|
||||
@Inject ConfigFactory configFactory;
|
||||
CallMessageProcessor callMessageProcessor;
|
||||
MessagingModuleConfiguration messagingModuleConfiguration;
|
||||
@@ -429,7 +429,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
private static class ProviderInitializationException extends RuntimeException { }
|
||||
|
||||
public void registerForPnIfNeeded(final Boolean force) {
|
||||
pushManager.refresh(force);
|
||||
pushRegistry.refresh(force);
|
||||
}
|
||||
|
||||
private void setUpPollingIfNeeded() {
|
||||
|
||||
@@ -50,7 +50,7 @@ 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.PushManagerV1
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1
|
||||
import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2
|
||||
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel
|
||||
import org.session.libsession.messaging.utilities.SessionId
|
||||
@@ -591,7 +591,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
val expireTimer = group.disappearingTimer
|
||||
setExpirationTimer(groupId, expireTimer.toInt())
|
||||
// Notify the PN server
|
||||
PushManagerV1.subscribeGroup(group.sessionId, publicKey = localUserPublicKey)
|
||||
PushRegistryV1.subscribeGroup(group.sessionId, publicKey = localUserPublicKey)
|
||||
// Notify the user
|
||||
val threadID = getOrCreateThreadIdFor(Address.fromSerialized(groupId))
|
||||
threadDb.setDate(threadID, formationTimestamp)
|
||||
|
||||
@@ -8,5 +8,5 @@ import org.thoughtcrime.securesms.notifications.PushManager
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface PushComponent {
|
||||
fun providePushManager(): PushManager
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.groups
|
||||
import android.content.Context
|
||||
import network.loki.messenger.libsession_util.ConfigBase
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1
|
||||
import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.GroupRecord
|
||||
@@ -24,7 +24,7 @@ object ClosedGroupManager {
|
||||
storage.removeAllClosedGroupEncryptionKeyPairs(groupPublicKey)
|
||||
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
||||
// Notify the PN server
|
||||
PushManagerV1.unsubscribeGroup(closedGroupPublicKey = groupPublicKey, publicKey = userPublicKey)
|
||||
PushRegistryV1.unsubscribeGroup(closedGroupPublicKey = groupPublicKey, publicKey = userPublicKey)
|
||||
// Stop polling
|
||||
ClosedGroupPollerV2.shared.stopPolling(groupPublicKey)
|
||||
storage.cancelPendingMessageSendJobs(threadId)
|
||||
|
||||
@@ -67,7 +67,7 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel
|
||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.notifications.PushManager
|
||||
import org.thoughtcrime.securesms.notifications.PushRegistry
|
||||
import org.thoughtcrime.securesms.onboarding.SeedActivity
|
||||
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
||||
import org.thoughtcrime.securesms.permissions.Permissions
|
||||
@@ -107,7 +107,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
@Inject lateinit var groupDatabase: GroupDatabase
|
||||
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
||||
@Inject lateinit var configFactory: ConfigFactory
|
||||
@Inject lateinit var pushManager: PushManager
|
||||
@Inject lateinit var pushRegistry: PushRegistry
|
||||
|
||||
private val globalSearchViewModel by viewModels<GlobalSearchViewModel>()
|
||||
private val homeViewModel by viewModels<HomeViewModel>()
|
||||
@@ -232,7 +232,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
||||
// update things based on TextSecurePrefs (profile info etc)
|
||||
// Set up remaining components if needed
|
||||
pushManager.refresh(false)
|
||||
pushRegistry.refresh(false)
|
||||
if (textSecurePreferences.getLocalNumber() != null) {
|
||||
OpenGroupManager.startPolling()
|
||||
JobQueue.shared.resumePendingJobs()
|
||||
|
||||
@@ -21,8 +21,8 @@ class ExpiryManager(
|
||||
}
|
||||
|
||||
private var time
|
||||
get() = TextSecurePreferences.getLastFCMUploadTime(context)
|
||||
set(value) = TextSecurePreferences.setLastFCMUploadTime(context, value)
|
||||
get() = TextSecurePreferences.getPushRegisterTime(context)
|
||||
set(value) = TextSecurePreferences.setPushRegisterTime(context, value)
|
||||
|
||||
private fun currentTime() = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.inject.Inject
|
||||
|
||||
private const val TAG = "PushHandler"
|
||||
|
||||
class PushHandler @Inject constructor(@ApplicationContext val context: Context) {
|
||||
class PushReceiver @Inject constructor(@ApplicationContext val context: Context) {
|
||||
private val sodium = LazySodiumAndroid(SodiumAndroid())
|
||||
|
||||
fun onPush(dataMap: Map<String, String>?) {
|
||||
@@ -2,22 +2,24 @@ package org.thoughtcrime.securesms.notifications
|
||||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Job
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class FcmTokenManager @Inject constructor(
|
||||
class PushTokenManager @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val tokenFetcher: TokenFetcher
|
||||
) {
|
||||
private val expiryManager = ExpiryManager(context)
|
||||
|
||||
val isUsingFCM get() = TextSecurePreferences.isPushEnabled(context)
|
||||
val isPushEnabled get() = TextSecurePreferences.isPushEnabled(context)
|
||||
|
||||
var fcmToken
|
||||
get() = TextSecurePreferences.getFCMToken(context)
|
||||
get() = TextSecurePreferences.getPushToken(context)
|
||||
set(value) {
|
||||
TextSecurePreferences.setFCMToken(context, value)
|
||||
TextSecurePreferences.setPushToken(context, value)
|
||||
if (value != null) markTime() else clearTime()
|
||||
}
|
||||
|
||||
@@ -28,4 +30,5 @@ class FcmTokenManager @Inject constructor(
|
||||
private fun isExpired() = expiryManager.isExpired()
|
||||
|
||||
fun isInvalid(): Boolean = fcmToken == null || isExpired()
|
||||
fun fetchToken(): Job = tokenFetcher.fetch()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.thoughtcrime.securesms.notifications
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
interface TokenFetcher {
|
||||
fun fetch(): Job
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||
import org.thoughtcrime.securesms.home.HomeActivity
|
||||
import org.thoughtcrime.securesms.notifications.PushManager
|
||||
import org.thoughtcrime.securesms.notifications.PushRegistry
|
||||
import org.thoughtcrime.securesms.showSessionDialog
|
||||
import org.thoughtcrime.securesms.util.GlowViewUtilities
|
||||
import org.thoughtcrime.securesms.util.PNModeView
|
||||
@@ -34,7 +35,7 @@ import javax.inject.Inject
|
||||
@AndroidEntryPoint
|
||||
class PNModeActivity : BaseActionBarActivity() {
|
||||
|
||||
@Inject lateinit var pushManager: PushManager
|
||||
@Inject lateinit var pushRegistry: PushRegistry
|
||||
|
||||
private lateinit var binding: ActivityPnModeBinding
|
||||
private var selectedOptionView: PNModeView? = null
|
||||
@@ -168,7 +169,7 @@ class PNModeActivity : BaseActionBarActivity() {
|
||||
TextSecurePreferences.setPushEnabled(this, (selectedOptionView == binding.fcmOptionView))
|
||||
val application = ApplicationContext.getInstance(this)
|
||||
application.startPollingIfNeeded()
|
||||
pushManager.refresh(true)
|
||||
pushRegistry.refresh(true)
|
||||
val intent = Intent(this, HomeActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
intent.putExtra(HomeActivity.FROM_ONBOARDING, true)
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.notifications.PushManager;
|
||||
import org.thoughtcrime.securesms.notifications.PushRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName();
|
||||
|
||||
@Inject
|
||||
PushManager pushManager;
|
||||
PushRegistry pushRegistry;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
@@ -49,7 +49,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
this.findPreference(fcmKey)
|
||||
.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
TextSecurePreferences.setPushEnabled(getContext(), (boolean) newValue);
|
||||
pushManager.refresh(true);
|
||||
pushRegistry.refresh(true);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ package org.thoughtcrime.securesms.notifications
|
||||
import android.content.Context
|
||||
import com.goterl.lazysodium.utils.KeyPair
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Job
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushManagerV1
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.PushRegistryV1
|
||||
import org.session.libsession.utilities.Device
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.utilities.Log
|
||||
@@ -18,12 +19,25 @@ import javax.inject.Singleton
|
||||
private const val TAG = "GenericPushManager"
|
||||
|
||||
@Singleton
|
||||
class GenericPushManager @Inject constructor(
|
||||
class PushRegistry @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val device: Device,
|
||||
private val tokenManager: FcmTokenManager,
|
||||
private val pushManagerV2: PushManagerV2,
|
||||
private val tokenManager: PushTokenManager,
|
||||
private val pushRegistryV2: PushRegistryV2,
|
||||
) {
|
||||
|
||||
private var firebaseInstanceIdJob: Job? = null
|
||||
|
||||
fun refresh(force: Boolean) {
|
||||
Log.d(TAG, "refresh() called with: force = $force")
|
||||
|
||||
firebaseInstanceIdJob?.apply {
|
||||
if (force) cancel() else if (isActive) return
|
||||
}
|
||||
|
||||
firebaseInstanceIdJob = tokenManager.fetchToken()
|
||||
}
|
||||
|
||||
fun refresh(token: String?, force: Boolean): Promise<*, Exception> {
|
||||
Log.d(TAG, "refresh($token, $force) called")
|
||||
|
||||
@@ -32,7 +46,7 @@ class GenericPushManager @Inject constructor(
|
||||
val userEdKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return emptyPromise()
|
||||
|
||||
return when {
|
||||
tokenManager.isUsingFCM -> register(force, token, userPublicKey, userEdKey)
|
||||
tokenManager.isPushEnabled -> register(force, token, userPublicKey, userEdKey)
|
||||
tokenManager.requiresUnregister -> unregister(token, userPublicKey, userEdKey)
|
||||
else -> emptyPromise()
|
||||
}
|
||||
@@ -68,7 +82,7 @@ class GenericPushManager @Inject constructor(
|
||||
"register() called with: token = $token, publicKey = $publicKey, userEd25519Key = $userEd25519Key, namespaces = $namespaces"
|
||||
)
|
||||
|
||||
val v1 = PushManagerV1.register(
|
||||
val v1 = PushRegistryV1.register(
|
||||
device = device,
|
||||
token = token,
|
||||
publicKey = publicKey
|
||||
@@ -76,7 +90,7 @@ class GenericPushManager @Inject constructor(
|
||||
Log.e(TAG, "register v1 failed", it)
|
||||
}
|
||||
|
||||
val v2 = pushManagerV2.register(
|
||||
val v2 = pushRegistryV2.register(
|
||||
device, token, publicKey, userEd25519Key, namespaces
|
||||
) fail {
|
||||
Log.e(TAG, "register v2 failed", it)
|
||||
@@ -92,7 +106,7 @@ class GenericPushManager @Inject constructor(
|
||||
token: String,
|
||||
userPublicKey: String,
|
||||
userEdKey: KeyPair
|
||||
): Promise<*, Exception> = PushManagerV1.unregister() and pushManagerV2.unregister(
|
||||
): Promise<*, Exception> = PushRegistryV1.unregister() and pushRegistryV2.unregister(
|
||||
device, token, userPublicKey, userEdKey
|
||||
) fail {
|
||||
Log.e(TAG, "unregisterBoth failed", it)
|
||||
@@ -28,7 +28,7 @@ private const val TAG = "PushManagerV2"
|
||||
private const val maxRetryCount = 4
|
||||
|
||||
@Singleton
|
||||
class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
||||
class PushRegistryV2 @Inject constructor(private val pushReceiver: PushReceiver) {
|
||||
private val sodium = LazySodiumAndroid(SodiumAndroid())
|
||||
|
||||
fun register(
|
||||
@@ -38,7 +38,7 @@ class PushManagerV2 @Inject constructor(private val pushHandler: PushHandler) {
|
||||
userEd25519Key: KeyPair,
|
||||
namespaces: List<Int>
|
||||
): Promise<SubscriptionResponse, Exception> {
|
||||
val pnKey = pushHandler.getOrCreateNotificationKey()
|
||||
val pnKey = pushReceiver.getOrCreateNotificationKey()
|
||||
|
||||
val timestamp = SnodeAPI.nowWithOffset / 1000 // get timestamp in ms -> s
|
||||
// if we want to support passing namespace list, here is the place to do it
|
||||
Reference in New Issue
Block a user