This commit is contained in:
andrew 2023-08-06 22:22:39 +09:30
parent a27f81db30
commit bcf925c132
31 changed files with 176 additions and 204 deletions

View File

@ -4,7 +4,7 @@
<application tools:node="merge">
<service
android:name="org.thoughtcrime.securesms.notifications.HuaweiPushNotificationService"
android:name="org.thoughtcrime.securesms.notifications.HuaweiPushService"
android:enabled="true"
android:exported="false">
<intent-filter>

View File

@ -1,52 +0,0 @@
package org.thoughtcrime.securesms.notifications
import android.content.Context
import android.util.Log
import com.huawei.hmf.tasks.Tasks
import com.huawei.hms.aaid.HmsInstanceId
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.session.libsession.utilities.TextSecurePreferences
import javax.inject.Inject
import javax.inject.Singleton
private val TAG = HuaweiPushManager::class.java.name
@Singleton
class HuaweiPushManager @Inject constructor(
@ApplicationContext private val context: Context,
private val genericPushManager: GenericPushManager
): PushManager {
private var huaweiPushInstanceIdJob: Job? = null
@Synchronized
override fun refresh(force: Boolean) {
Log.d(TAG, "refresh() called with: force = $force")
val huaweiPushInstanceIdJob = huaweiPushInstanceIdJob
huaweiPushInstanceIdJob?.apply {
if (force) cancel() else if (isActive) return
}
val appId = "107205081"
val tokenScope = "HCM"
val hmsInstanceId = HmsInstanceId.getInstance(context)
Log.d(TAG, "hmsInstanceId: $hmsInstanceId")
// genericPushManager.refresh(TextSecurePreferences.getFCMToken(context), force)
MainScope().launch(Dispatchers.IO) {
Log.d(TAG, "hmInstanceId getting token...")
val token = hmsInstanceId.getToken(appId, tokenScope)
Log.d(TAG, "refresh() hmsInstanceId => huawei token: $token")
//
//// genericPushManager.refresh(token, force)
}
}
}

View File

@ -1,16 +1,13 @@
package org.thoughtcrime.securesms.notifications
import android.content.Context
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
abstract class HuaweiBindingModule {
@Binds
abstract fun bindPushManager(pushManager: HuaweiPushManager): PushManager
abstract fun bindTokenFetcher(tokenFetcher: HuaweiTokenFetcher): TokenFetcher
}

View File

@ -10,18 +10,17 @@ import org.session.libsignal.utilities.Log
import java.lang.Exception
import javax.inject.Inject
private val TAG = HuaweiPushNotificationService::class.java.simpleName
private val TAG = HuaweiPushService::class.java.simpleName
@AndroidEntryPoint
class HuaweiPushNotificationService: HmsMessageService() {
class HuaweiPushService: HmsMessageService() {
init {
Log.d(TAG, "init Huawei Service")
}
@Inject lateinit var pushManager: PushManager
@Inject lateinit var genericPushManager: GenericPushManager
@Inject lateinit var pushHandler: PushHandler
@Inject lateinit var pushRegistry: PushRegistry
@Inject lateinit var pushReceiver: PushReceiver
override fun onCreate() {
Log.d(TAG, "onCreate Huawei Service")
@ -30,7 +29,7 @@ class HuaweiPushNotificationService: HmsMessageService() {
override fun onMessageReceived(message: RemoteMessage?) {
Log.d(TAG, "onMessageReceived: $message.")
pushHandler.onPush(message?.data?.let(Base64::decode))
pushReceiver.onPush(message?.data?.let(Base64::decode))
}
override fun onMessageSent(p0: String?) {
@ -57,12 +56,12 @@ class HuaweiPushNotificationService: HmsMessageService() {
override fun onNewToken(token: String?, bundle: Bundle?) {
Log.d(TAG, "New HCM token: $token.")
TextSecurePreferences.setFCMToken(this, token)
TextSecurePreferences.setPushToken(this, token)
genericPushManager.refresh(token, true)
pushRegistry.refresh(token, true)
}
override fun onDeletedMessages() {
pushManager.refresh(true)
pushRegistry.refresh(true)
}
}

View File

@ -0,0 +1,27 @@
package org.thoughtcrime.securesms.notifications
import android.content.Context
import com.huawei.hms.aaid.HmsInstanceId
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class HuaweiTokenFetcher @Inject constructor(
@ApplicationContext private val context: Context
): TokenFetcher {
override fun fetch(): Job {
val hmsInstanceId = HmsInstanceId.getInstance(context)
return MainScope().launch(Dispatchers.IO) {
val appId = "107205081"
val tokenScope = "HCM"
// getToken returns an empty string, but triggers the service to initialize.
hmsInstanceId.getToken(appId, tokenScope)
}
}
}

View File

@ -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() {

View File

@ -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)

View File

@ -8,5 +8,5 @@ import org.thoughtcrime.securesms.notifications.PushManager
@EntryPoint
@InstallIn(SingletonComponent::class)
interface PushComponent {
fun providePushManager(): PushManager
}

View File

@ -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)

View File

@ -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()

View File

@ -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()
}

View File

@ -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>?) {

View File

@ -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()
}

View File

@ -0,0 +1,7 @@
package org.thoughtcrime.securesms.notifications
import kotlinx.coroutines.Job
interface TokenFetcher {
fun fetch(): Job
}

View File

@ -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)

View File

@ -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;
});

View File

@ -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)

View File

@ -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

View File

@ -4,7 +4,7 @@
<application tools:node="merge">
<service
android:name="org.thoughtcrime.securesms.notifications.FirebasePushNotificationService"
android:name="org.thoughtcrime.securesms.notifications.FirebasePushService"
android:enabled="true"
android:exported="false">
<intent-filter>

View File

@ -1,16 +0,0 @@
@file:JvmName("FcmUtils")
package org.thoughtcrime.securesms.notifications
import com.google.android.gms.tasks.Task
import com.google.android.gms.tasks.Tasks
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.iid.InstanceIdResult
import kotlinx.coroutines.*
fun getFcmInstanceId(body: (Task<InstanceIdResult>)->Unit): Job = MainScope().launch(Dispatchers.IO) {
val task = FirebaseInstanceId.getInstance().instanceId
Tasks.await(task)
if (!isActive) return@launch // don't 'complete' task if we were canceled
body(task)
}

View File

@ -1,37 +0,0 @@
package org.thoughtcrime.securesms.notifications
import kotlinx.coroutines.Job
import org.session.libsignal.utilities.Log
import javax.inject.Inject
import javax.inject.Singleton
private const val TAG = "FirebasePushManager"
@Singleton
class FirebasePushManager @Inject constructor(
private val genericPushManager: GenericPushManager
): PushManager {
private var firebaseInstanceIdJob: Job? = null
@Synchronized
override fun refresh(force: Boolean) {
Log.d(TAG, "refresh() called with: force = $force")
firebaseInstanceIdJob?.apply {
when {
force -> cancel()
isActive -> return
}
}
firebaseInstanceIdJob = getFcmInstanceId { task ->
when {
task.isSuccessful -> try { task.result?.token?.let {
genericPushManager.refresh(it, force).get()
} } catch(e: Exception) { Log.e(TAG, "refresh() failed", e) }
else -> Log.w(TAG, "getFcmInstanceId failed." + task.exception)
}
}
}
}

View File

@ -9,5 +9,5 @@ import dagger.hilt.components.SingletonComponent
@InstallIn(SingletonComponent::class)
abstract class FirebaseBindingModule {
@Binds
abstract fun bindPushManager(firebasePushManager: FirebasePushManager): PushManager
abstract fun bindTokenFetcher(tokenFetcher: FirebaseTokenFetcher): TokenFetcher
}

View File

@ -9,26 +9,25 @@ import javax.inject.Inject
private const val TAG = "FirebasePushNotificationService"
@AndroidEntryPoint
class FirebasePushNotificationService : FirebaseMessagingService() {
class FirebasePushService : FirebaseMessagingService() {
@Inject lateinit var pushManager: PushManager
@Inject lateinit var pushHandler: PushHandler
@Inject lateinit var prefs: TextSecurePreferences
@Inject lateinit var pushReceiver: PushReceiver
@Inject lateinit var pushRegistry: PushRegistry
override fun onNewToken(token: String) {
super.onNewToken(token)
TextSecurePreferences.getLocalNumber(this) ?: return
if (TextSecurePreferences.getFCMToken(this) != token) {
pushManager.refresh(true)
}
if (token == prefs.getPushToken()) return
pushRegistry.refresh(token, true)
}
override fun onMessageReceived(message: RemoteMessage) {
Log.d(TAG, "Received a push notification.")
pushHandler.onPush(message.data)
pushReceiver.onPush(message.data)
}
override fun onDeletedMessages() {
Log.d(TAG, "Called onDeletedMessages.")
pushManager.refresh(true)
pushRegistry.refresh(true)
}
}

View File

@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.notifications
import com.google.android.gms.tasks.Task
import com.google.android.gms.tasks.Tasks
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.iid.InstanceIdResult
import dagger.Lazy
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.session.libsignal.utilities.Log
import javax.inject.Inject
import javax.inject.Singleton
private val TAG = FirebaseTokenFetcher::class.java.name
@Singleton
class FirebaseTokenFetcher @Inject constructor(
private val pushRegistry: Lazy<PushRegistry>,
): TokenFetcher {
override fun fetch(): Job = MainScope().launch(Dispatchers.IO) {
FirebaseInstanceId.getInstance().instanceId
.also(Tasks::await)
.also { if (!isActive) return@launch } // don't 'complete' task if we were canceled
.process()
}
private fun Task<InstanceIdResult>.process() {
when {
isSuccessful -> try {
result?.token?.let {
pushRegistry.get().refresh(it, force = true).get()
}
} catch (e: Exception) {
onFail(e)
}
else -> exception?.let(::onFail)
}
}
private fun onFail(e: Exception) = Log.e(TAG, "fetch failed", e)
}

View File

@ -1,10 +0,0 @@
package org.thoughtcrime.securesms.notifications
import org.session.libsignal.utilities.Log
class NoOpPushManager: PushManager {
override fun refresh(force: Boolean) {
Log.d("NoOpPushManager", "Push notifications not supported, not registering for push notifications")
}
}

View File

@ -9,7 +9,5 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class NoOpPushModule {
@Provides
@Singleton
fun provideNoOpManager(): PushManager = NoOpPushManager()
}

View File

@ -8,7 +8,7 @@ import nl.komponents.kovenant.deferred
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
import org.session.libsession.messaging.sending_receiving.MessageSender.Error
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.snode.SnodeAPI
import org.session.libsession.utilities.Address
@ -94,7 +94,7 @@ fun MessageSender.create(
// Add the group to the config now that it was successfully created
storage.createInitialConfigGroup(groupPublicKey, name, GroupUtil.createConfigMemberMap(members, admins), sentTime, encryptionKeyPair)
// Notify the PN server
PushManagerV1.register(device = device, publicKey = userPublicKey)
PushRegistryV1.register(device = device, publicKey = userPublicKey)
// Start polling
ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
// Fulfill the promise

View File

@ -23,7 +23,7 @@ import org.session.libsession.messaging.open_groups.OpenGroupApi
import org.session.libsession.messaging.sending_receiving.attachments.PointerAttachment
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
@ -556,7 +556,7 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
// Set expiration timer
storage.setExpirationTimer(groupID, expireTimer)
// Notify the PN server
PushManagerV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey)
PushRegistryV1.register(device = MessagingModuleConfiguration.shared.device, publicKey = userPublicKey)
// Notify the user
if (userPublicKey == sender && !groupExists) {
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
@ -869,7 +869,7 @@ fun MessageReceiver.disableLocalGroupAndUnsubscribe(groupPublicKey: String, grou
storage.setActive(groupID, false)
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
// Notify the PN server
PushManagerV1.unsubscribeGroup(groupPublicKey, publicKey = userPublicKey)
PushRegistryV1.unsubscribeGroup(groupPublicKey, publicKey = userPublicKey)
// Stop polling
ClosedGroupPollerV2.shared.stopPolling(groupPublicKey)

View File

@ -18,8 +18,8 @@ import org.session.libsignal.utilities.retryIfNeeded
import org.session.libsignal.utilities.sideEffect
@SuppressLint("StaticFieldLeak")
object PushManagerV1 {
private const val TAG = "PushManagerV1"
object PushRegistryV1 {
private val TAG = PushRegistryV1::class.java.name
val context = MessagingModuleConfiguration.shared.context
private const val maxRetryCount = 4
@ -29,7 +29,7 @@ object PushManagerV1 {
fun register(
device: Device,
isUsingFCM: Boolean = TextSecurePreferences.isPushEnabled(context),
token: String? = TextSecurePreferences.getFCMToken(context),
token: String? = TextSecurePreferences.getPushToken(context),
publicKey: String? = TextSecurePreferences.getLocalNumber(context),
legacyGroupPublicKeys: Collection<String> = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
): Promise<*, Exception> = when {
@ -84,7 +84,7 @@ object PushManagerV1 {
fun unregister(): Promise<*, Exception> {
Log.d(TAG, "unregisterV1 requested")
val token = TextSecurePreferences.getFCMToken(context) ?: emptyPromise()
val token = TextSecurePreferences.getPushToken(context) ?: emptyPromise()
return retryIfNeeded(maxRetryCount) {
val parameters = mapOf("token" to token)

View File

@ -252,7 +252,7 @@ interface TextSecurePreferences {
const val GIF_METADATA_WARNING = "has_seen_gif_metadata_warning"
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
const val IS_PUSH_ENABLED = "pref_is_using_fcm"
const val FCM_TOKEN = "pref_fcm_token_2"
const val PUSH_TOKEN = "pref_fcm_token_2"
const val PUSH_REGISTER_TIME = "pref_last_fcm_token_upload_time_2"
const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
@ -319,20 +319,20 @@ interface TextSecurePreferences {
}
@JvmStatic
fun getFCMToken(context: Context): String? {
return getStringPreference(context, FCM_TOKEN, "")
fun getPushToken(context: Context): String? {
return getStringPreference(context, PUSH_TOKEN, "")
}
@JvmStatic
fun setFCMToken(context: Context, value: String?) {
setStringPreference(context, FCM_TOKEN, value)
fun setPushToken(context: Context, value: String?) {
setStringPreference(context, PUSH_TOKEN, value)
}
fun getLastFCMUploadTime(context: Context): Long {
fun getPushRegisterTime(context: Context): Long {
return getLongPreference(context, PUSH_REGISTER_TIME, 0)
}
fun setLastFCMUploadTime(context: Context, value: Long) {
fun setPushRegisterTime(context: Context, value: Long) {
setLongPreference(context, PUSH_REGISTER_TIME, value)
}
@ -1041,11 +1041,11 @@ class AppTextSecurePreferences @Inject constructor(
}
override fun getPushToken(): String? {
return getStringPreference(TextSecurePreferences.FCM_TOKEN, "")
return getStringPreference(TextSecurePreferences.PUSH_TOKEN, "")
}
override fun setPushToken(value: String) {
setStringPreference(TextSecurePreferences.FCM_TOKEN, value)
setStringPreference(TextSecurePreferences.PUSH_TOKEN, value)
}
override fun getPushRegisterTime(): Long {

View File

@ -15,7 +15,7 @@ object ExternalStorageUtil {
@Throws(NoExternalStorageException::class)
fun getDir(context: Context, type: String?): File {
return context.getExternalFilesDir(type)
?: throw NoExternalStorageException("External storage dir is currently unavailable: $type")
?: throw NoExternalStorageException("External storage dir is currently unavailable: $type")
}
@Throws(NoExternalStorageException::class)
@ -73,10 +73,7 @@ object ExternalStorageUtil {
}
@JvmStatic
fun getCleanFileName(fileName: String?): String? {
var fileName = fileName ?: return null
fileName = fileName.replace('\u202D', '\uFFFD')
fileName = fileName.replace('\u202E', '\uFFFD')
return fileName
}
}
fun getCleanFileName(fileName: String?): String? =
fileName?.replace('\u202D', '\uFFFD')
?.replace('\u202E', '\uFFFD')
}