Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import org.session.libsession.utilities.DecodedAudio
import org.session.libsession.utilities.InputStreamMediaDataSource
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.UploadResult
import org.thoughtcrime.securesms.preferences.MessagingPreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.session.libsignal.messages.SignalServiceAttachmentStream
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.api.http.HttpBody
Expand All @@ -43,7 +45,8 @@ class AttachmentUploadJob @AssistedInject constructor(
private val messageSendJobFactory: MessageSendJob.Factory,
private val threadDatabase: ThreadDatabase,
private val attachmentProcessor: AttachmentProcessor,
private val preferences: TextSecurePreferences,
private val textSecurePreferences: TextSecurePreferences,
private val preferenceStorage: PreferenceStorage,
private val messageSender: MessageSender,
private val serverApiExecutor: ServerApiExecutor,
private val fileUploadApiFactory: FileUploadApi.Factory,
Expand Down Expand Up @@ -99,7 +102,7 @@ class AttachmentUploadJob @AssistedInject constructor(
}
handleSuccess(dispatcherName, attachment, keyAndResult.first, keyAndResult.second)
} else {
val fileServer = preferences.alternativeFileServer ?: FileServerApis.DEFAULT_FILE_SERVER
val fileServer = preferenceStorage[MessagingPreferences.ALTERNATIVE_FILE_SERVER] ?: FileServerApis.DEFAULT_FILE_SERVER
val keyAndResult = upload(
attachment = attachment,
encrypt = true
Expand Down Expand Up @@ -147,7 +150,7 @@ class AttachmentUploadJob @AssistedInject constructor(
val deterministicallyEncrypted: Boolean

when {
encrypt && preferences.forcesDeterministicAttachmentEncryption -> {
encrypt && preferenceStorage[MessagingPreferences.FORCES_DETERMINISTIC_ATTACHMENT_ENCRYPTION] -> {
deterministicallyEncrypted = true
val result = attachmentProcessor.encryptDeterministically(
plaintext = input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.utilities.Data
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.preferences.MessagingPreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.database.Storage
import org.thoughtcrime.securesms.database.ThreadDatabase

Expand All @@ -18,6 +19,7 @@ class TrimThreadJob @AssistedInject constructor(
private val storage: StorageProtocol,
@param:ApplicationContext private val context: Context,
threadDatabase: ThreadDatabase,
private val preferenceStorage: PreferenceStorage
) : Job {
override var delegate: JobDelegate? = null
override var id: String? = null
Expand All @@ -36,7 +38,7 @@ class TrimThreadJob @AssistedInject constructor(
val communityAddress: Address.Community? = threadDatabase.getRecipientForThreadId(threadId) as? Address.Community

override suspend fun execute(dispatcherName: String) {
val trimmingEnabled = TextSecurePreferences.isThreadLengthTrimmingEnabled(context)
val trimmingEnabled = preferenceStorage[MessagingPreferences.THREAD_TRIM_ENABLED]
val messageCount = storage.getMessageCount(threadId)
if (trimmingEnabled && messageCount >= THREAD_LENGTH_TRIGGER_SIZE) {
val oldestMessageTime = System.currentTimeMillis() - TRIM_TIME_LIMIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import org.session.libsession.messaging.open_groups.OpenGroupApi
import org.session.libsession.network.SnodeClock
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.preferences.ProPreferences
import org.session.libsession.utilities.withGroupConfigs
import org.session.libsession.utilities.withUserConfigs
import org.session.libsignal.exceptions.NonRetryableException
Expand All @@ -42,7 +43,7 @@ class MessageParser @Inject constructor(
private val configFactory: ConfigFactoryProtocol,
private val storage: StorageProtocol,
private val snodeClock: SnodeClock,
private val prefs: TextSecurePreferences,
private val preferenceStorage: PreferenceStorage,
private val proBackendConfig: Provider<ProBackendConfig>,
) {

Expand Down Expand Up @@ -143,7 +144,7 @@ class MessageParser @Inject constructor(
message.isSenderSelf = isSenderSelf

// Only process pro features post pro launch
if (prefs.forcePostPro()) {
if (preferenceStorage[ProPreferences.FORCE_POST_PRO]) {
if (pro?.status == ProProof.STATUS_VALID) {
(message as? VisibleMessage)?.proFeatures = buildSet {
addAll(pro.proMessageFeatures.asSequence())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import org.session.libsession.utilities.Address.Companion.toAddress
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.GroupUtil.doubleEncodeGroupID
import org.session.libsession.utilities.SSKEnvironment
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.preferences.PrivacyPreferences
import org.session.libsession.utilities.UserConfigType
import org.session.libsession.utilities.recipients.MessageType
import org.session.libsession.utilities.recipients.Recipient
Expand Down Expand Up @@ -69,7 +70,7 @@ class ReceivedMessageProcessor @Inject constructor(
private val threadDatabase: ThreadDatabase,
private val readReceiptManager: Provider<ReadReceiptManager>,
private val typingIndicators: Provider<SSKEnvironment.TypingIndicatorsProtocol>,
private val prefs: TextSecurePreferences,
private val preferenceStorage: PreferenceStorage,
private val groupMessageHandler: Provider<GroupMessageHandler>,
private val messageExpirationManager: Provider<SSKEnvironment.MessageExpirationManagerProtocol>,
private val messageDataProvider: MessageDataProvider,
Expand Down Expand Up @@ -377,7 +378,7 @@ class ReceivedMessageProcessor @Inject constructor(

private fun showTypingIndicatorIfNeeded(senderPublicKey: String) {
// We don't want to show other people's indicators if the toggle is off
if (!prefs.isTypingIndicatorsEnabled()) return
if (!preferenceStorage[PrivacyPreferences.TYPING_INDICATORS]) return

val address = Address.fromSerialized(senderPublicKey)
val threadID = storage.getThreadId(address) ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import org.session.libsession.network.model.PathStatus
import org.session.libsession.network.snode.SnodeDirectory
import org.session.libsession.network.snode.SnodePathStorage
import org.session.libsession.network.snode.SnodePoolStorage
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.preferences.SystemPreferences
import org.session.libsignal.crypto.secureRandom
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Snode
Expand All @@ -44,7 +45,7 @@ open class PathManager @Inject constructor(
private val directory: SnodeDirectory,
private val storage: SnodePathStorage,
private val snodePoolStorage: SnodePoolStorage,
private val prefs: TextSecurePreferences,
private val preferenceStorage: PreferenceStorage,
private val snodeApiExecutor: Provider<SnodeApiExecutor>,
private val getInfoApi: Provider<GetInfoApi>,
) {
Expand Down Expand Up @@ -129,12 +130,12 @@ open class PathManager @Inject constructor(

private fun rotatePathsIfStale() {
val now = System.currentTimeMillis()
val last = prefs.getLastPathRotation()
val last = preferenceStorage[SystemPreferences.LAST_PATH_ROTATION]

// if we have never done a path rotation, mark now as the starting time
// so we can rotate on the next tick
if (last == 0L){
prefs.setLastPathRotation(now)
preferenceStorage[SystemPreferences.LAST_PATH_ROTATION] = now
return
}

Expand Down Expand Up @@ -187,7 +188,7 @@ open class PathManager @Inject constructor(
// Phase 1: decide + build candidates under lock
val candidates: List<Path> = buildMutex.withLock {
val now = System.currentTimeMillis()
val last = prefs.getLastPathRotation()
val last = preferenceStorage[SystemPreferences.LAST_PATH_ROTATION]
if (now - last < PATH_ROTATE_INTERVAL_MS) return@withLock emptyList()

val current = _paths.value
Expand Down Expand Up @@ -258,7 +259,7 @@ open class PathManager @Inject constructor(

val committed = sanitizePaths(working.take(targetPathCount))
_paths.value = committed
prefs.setLastPathRotation(System.currentTimeMillis())
preferenceStorage[SystemPreferences.LAST_PATH_ROTATION] = System.currentTimeMillis()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.session.libsession.utilities.Environment
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.preferences.SystemPreferences
import org.session.libsignal.crypto.secureRandom
import org.session.libsignal.crypto.shuffledSequence
import org.session.libsignal.utilities.Log
Expand All @@ -41,7 +43,8 @@ import javax.inject.Singleton
@Singleton
class SnodeDirectory @Inject constructor(
private val storage: SnodePoolStorage,
private val prefs: TextSecurePreferences,
private val textSecurePreferences: TextSecurePreferences,
private val preferenceStorage: PreferenceStorage,
private val httpExecutor: Provider<HttpApiExecutor>,
private val snodeAPiExecutor: Provider<SnodeApiExecutor>,
private val listSnodeApi: Provider<ListSnodeApi>,
Expand Down Expand Up @@ -83,10 +86,11 @@ class SnodeDirectory @Inject constructor(
// Refresh state (non-blocking trigger + real exclusion inside mutex)
@Volatile private var snodePoolRefreshing = false

val seedNodePool: Set<HttpUrl> get() = when (prefs.getEnvironment()) {
val seedNodePool: Set<HttpUrl> get() = when (textSecurePreferences.getEnvironment()) {
Environment.DEV_NET -> DEV_NET_SEED_NODES
Environment.TEST_NET -> TEST_NET_SEED_NODES
Environment.MAIN_NET -> MAIN_NET_SEED_NODES
else -> MAIN_NET_SEED_NODES
}

override fun onPostAppStarted() {
Expand All @@ -105,7 +109,7 @@ class SnodeDirectory @Inject constructor(

private fun persistSnodePool(newPool: List<Snode>) {
storage.setSnodePool(newPool)
prefs.setLastSnodePoolRefresh(System.currentTimeMillis())
preferenceStorage[SystemPreferences.LAST_SNODE_POOL_REFRESH] = System.currentTimeMillis()
}

/**
Expand All @@ -126,9 +130,9 @@ class SnodeDirectory @Inject constructor(
if (current.size >= minCount) {
// ensure we set the refresh timestamp in case we are starting the app
// with already cached snodes - set the timestamp to stale to enforce a refresh soon
if (prefs.getLastSnodePoolRefresh() == 0L) {
if (preferenceStorage[SystemPreferences.LAST_SNODE_POOL_REFRESH] == 0L) {
// Force a refresh on next opportunity
prefs.setLastSnodePoolRefresh(System.currentTimeMillis() - POOL_REFRESH_INTERVAL_MS - 1)
preferenceStorage[SystemPreferences.LAST_SNODE_POOL_REFRESH] = System.currentTimeMillis() - POOL_REFRESH_INTERVAL_MS - 1
}

return current
Expand Down Expand Up @@ -272,7 +276,7 @@ class SnodeDirectory @Inject constructor(
*/
fun refreshPoolIfStaleAsync() {
// Don’t refresh until we’ve successfully seeded at least once
val last = prefs.getLastSnodePoolRefresh()
val last = preferenceStorage[SystemPreferences.LAST_SNODE_POOL_REFRESH]
if (last == 0L) return

val now = System.currentTimeMillis()
Expand Down Expand Up @@ -304,7 +308,7 @@ class SnodeDirectory @Inject constructor(

poolWriteMutex.withLock {
// Re-check staleness INSIDE the lock to avoid “double refresh” races
val last = prefs.getLastSnodePoolRefresh()
val last = preferenceStorage[SystemPreferences.LAST_SNODE_POOL_REFRESH]
if (last == 0L) return// still not seeded
val now = System.currentTimeMillis()
if (now >= last && now - last < POOL_REFRESH_INTERVAL_MS) return
Expand Down
Loading
Loading