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 @@ -21,7 +21,6 @@ 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.session.libsession.utilities.withGroupConfigs
import org.session.libsession.utilities.withUserConfigs
import org.session.libsignal.exceptions.NonRetryableException
Expand All @@ -30,6 +29,8 @@ import org.session.libsignal.utilities.Base64
import org.session.libsignal.utilities.Hex
import org.session.libsignal.utilities.IdPrefix
import org.session.protos.SessionProtos
import org.thoughtcrime.securesms.preferences.CommunicationPreferenceKeys
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.pro.ProBackendConfig
import java.util.concurrent.TimeUnit
import javax.inject.Inject
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 prefs: 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 (prefs[CommunicationPreferenceKeys.FORCE_POST_PRO]) {
if (pro?.status == ProProof.STATUS_VALID) {
(message as? VisibleMessage)?.proFeatures = buildSet {
addAll(pro.proMessageFeatures.asSequence())
Expand Down Expand Up @@ -304,4 +305,4 @@ class MessageParser @Inject constructor(
currentUserBlindedIDs = currentUserBlindedIDs,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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.MessageExpirationManagerProtocol
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.TypingIndicatorsProtocol
import org.session.libsession.utilities.UserConfigType
import org.session.libsession.utilities.recipients.MessageType
Expand All @@ -54,6 +53,8 @@ import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.database.model.MessageId
import org.thoughtcrime.securesms.database.model.ReactionRecord
import org.thoughtcrime.securesms.dependencies.ManagerScope
import org.thoughtcrime.securesms.preferences.CommunicationPreferenceKeys
import org.thoughtcrime.securesms.preferences.PreferenceStorage
import org.thoughtcrime.securesms.sskenvironment.ReadReceiptManager
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.locks.ReentrantLock
Expand All @@ -70,7 +71,7 @@ class ReceivedMessageProcessor @Inject constructor(
private val threadDatabase: ThreadDatabase,
private val readReceiptManager: Provider<ReadReceiptManager>,
private val typingIndicators: Provider<TypingIndicatorsProtocol>,
private val prefs: TextSecurePreferences,
private val prefs: PreferenceStorage,
private val groupMessageHandler: Provider<GroupMessageHandler>,
private val messageExpirationManager: Provider<MessageExpirationManagerProtocol>,
private val messageDataProvider: MessageDataProvider,
Expand Down Expand Up @@ -378,7 +379,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 (!prefs[CommunicationPreferenceKeys.TYPING_INDICATORS]) return

val address = Address.fromSerialized(senderPublicKey)
val threadID = storage.getThreadId(address) ?: return
Expand Down Expand Up @@ -632,4 +633,4 @@ class ReceivedMessageProcessor @Inject constructor(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ import androidx.core.content.edit
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.serialization.json.Json
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
import network.loki.messenger.libsession_util.protocol.ProFeature
import network.loki.messenger.libsession_util.protocol.ProMessageFeature
import network.loki.messenger.libsession_util.protocol.ProProfileFeature
import network.loki.messenger.libsession_util.util.toBitSet
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.file_server.FileServer
import org.session.libsession.utilities.TextSecurePreferences.Companion.AUTOPLAY_AUDIO_MESSAGES
Expand All @@ -43,7 +34,6 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.FORCED_S
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_CHECKED_DOZE_WHITELIST
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_COPIED_DONATION_URL
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_DONATED
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_HIDDEN_MESSAGE_REQUESTS
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_SEEN_PRO_EXPIRED
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAS_SEEN_PRO_EXPIRING
import org.session.libsession.utilities.TextSecurePreferences.Companion.HAVE_SHOWN_A_NOTIFICATION_ABOUT_TOKEN_PAGE
Expand All @@ -60,18 +50,11 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.SEEN_DON
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_ACCENT_COLOR
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE
import org.session.libsession.utilities.TextSecurePreferences.Companion.SEND_WITH_ENTER
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_CURRENT_USER_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_INCOMING_MESSAGE_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_OTHER_USERS_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_POST_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_NOTIFICATION
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_WARNING
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOW_DONATION_CTA_FROM_POSITIVE_REVIEW
import org.session.libsession.utilities.TextSecurePreferences.Companion._events
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.debugmenu.DebugMenuViewModel
import org.thoughtcrime.securesms.pro.toProMessageFeatures
import org.thoughtcrime.securesms.pro.toProProfileFeatures
import java.io.IOException
import java.time.ZonedDateTime
import javax.inject.Inject
Expand Down Expand Up @@ -166,21 +149,10 @@ interface TextSecurePreferences {
fun setLastOpenDate()
fun hasSeenLinkPreviewSuggestionDialog(): Boolean
fun setHasSeenLinkPreviewSuggestionDialog()
fun hasHiddenMessageRequests(): Boolean
fun setHasHiddenMessageRequests(hidden: Boolean)
fun forceCurrentUserAsPro(): Boolean
fun setForceCurrentUserAsPro(isPro: Boolean)
fun forceOtherUsersAsPro(): Boolean
fun setForceOtherUsersAsPro(isPro: Boolean)
fun forceIncomingMessagesAsPro(): Boolean
fun setForceIncomingMessagesAsPro(isPro: Boolean)
fun forcePostPro(): Boolean
fun setForcePostPro(postPro: Boolean)
fun hasSeenProExpiring(): Boolean
fun setHasSeenProExpiring()
fun hasSeenProExpired(): Boolean
fun setHasSeenProExpired()
fun watchPostProStatus(): StateFlow<Boolean>
fun setShownCallWarning(): Boolean
fun setShownCallNotification(): Boolean
fun setCallNotificationsEnabled(enabled : Boolean)
Expand Down Expand Up @@ -213,18 +185,6 @@ interface TextSecurePreferences {
fun forcedShortTTL(): Boolean
fun setForcedShortTTL(value: Boolean)

fun getDebugMessageFeatures(): Set<ProFeature>
fun setDebugMessageFeatures(features: Set<ProFeature>)

fun getDebugSubscriptionType(): DebugMenuViewModel.DebugSubscriptionStatus?
fun setDebugSubscriptionType(status: DebugMenuViewModel.DebugSubscriptionStatus?)
fun getDebugProPlanStatus(): DebugMenuViewModel.DebugProPlanStatus?
fun setDebugProPlanStatus(status: DebugMenuViewModel.DebugProPlanStatus?)
fun getDebugForceNoBilling(): Boolean
fun setDebugForceNoBilling(hasBilling: Boolean)
fun getDebugIsWithinQuickRefund(): Boolean
fun setDebugIsWithinQuickRefund(isWithin: Boolean)

fun setSubscriptionProvider(provider: String)
fun getSubscriptionProvider(): String?

Expand Down Expand Up @@ -326,11 +286,6 @@ interface TextSecurePreferences {
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
const val PROFILE_PIC_EXPIRY = "profile_pic_expiry"
const val LAST_OPEN_DATE = "pref_last_open_date"
const val HAS_HIDDEN_MESSAGE_REQUESTS = "pref_message_requests_hidden"
const val SET_FORCE_CURRENT_USER_PRO = "pref_force_current_user_pro"
const val SET_FORCE_OTHER_USERS_PRO = "pref_force_other_users_pro"
const val SET_FORCE_INCOMING_MESSAGE_PRO = "pref_force_incoming_message_pro"
const val SET_FORCE_POST_PRO = "pref_force_post_pro"
const val HAS_SEEN_PRO_EXPIRING = "has_seen_pro_expiring"
const val HAS_SEEN_PRO_EXPIRED = "has_seen_pro_expired"
const val CALL_NOTIFICATIONS_ENABLED = "pref_call_notifications_enabled"
Expand Down Expand Up @@ -393,13 +348,6 @@ interface TextSecurePreferences {

const val IN_APP_REVIEW_STATE = "in_app_review_state"

const val DEBUG_PRO_MESSAGE_FEATURES = "debug_pro_message_features"
const val DEBUG_PRO_PROFILE_FEATURES = "debug_pro_profile_features"
const val DEBUG_SUBSCRIPTION_STATUS = "debug_subscription_status"
const val DEBUG_PRO_PLAN_STATUS = "debug_pro_plan_status"
const val DEBUG_FORCE_NO_BILLING = "debug_pro_has_billing"
const val DEBUG_WITHIN_QUICK_REFUND = "debug_within_quick_refund"

const val SUBSCRIPTION_PROVIDER = "session_subscription_provider"
const val DEBUG_AVATAR_REUPLOAD = "debug_avatar_reupload"

Expand Down Expand Up @@ -610,12 +558,6 @@ interface TextSecurePreferences {
return getLongPreference(context, PROFILE_PIC_EXPIRY, 0)
}

@JvmStatic
fun removeHasHiddenMessageRequests(context: Context) {
removePreference(context, HAS_HIDDEN_MESSAGE_REQUESTS)
_events.tryEmit(HAS_HIDDEN_MESSAGE_REQUESTS)
}

@JvmStatic
fun isCallNotificationsEnabled(context: Context): Boolean {
return getBooleanPreference(context, CALL_NOTIFICATIONS_ENABLED, false)
Expand Down Expand Up @@ -660,7 +602,6 @@ class AppTextSecurePreferences @Inject constructor(
@param:ApplicationContext private val context: Context,
private val json: Json,
): TextSecurePreferences {
private val postProLaunchState = MutableStateFlow(getBooleanPreference(SET_FORCE_POST_PRO, if (BuildConfig.BUILD_TYPE != "release") true else false))
private val hiddenPasswordState = MutableStateFlow(getBooleanPreference(HIDE_PASSWORD, false))

override var migratedToGroupV2Config: Boolean
Expand Down Expand Up @@ -1144,50 +1085,6 @@ class AppTextSecurePreferences @Inject constructor(
return previousValue != setValue
}

override fun hasHiddenMessageRequests(): Boolean {
return getBooleanPreference(HAS_HIDDEN_MESSAGE_REQUESTS, false)
}

override fun setHasHiddenMessageRequests(hidden: Boolean) {
setBooleanPreference(HAS_HIDDEN_MESSAGE_REQUESTS, hidden)
_events.tryEmit(HAS_HIDDEN_MESSAGE_REQUESTS)
}
override fun forceCurrentUserAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_CURRENT_USER_PRO, false)
}

override fun setForceCurrentUserAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_CURRENT_USER_PRO, isPro)
_events.tryEmit(SET_FORCE_CURRENT_USER_PRO)
}

override fun forceOtherUsersAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_OTHER_USERS_PRO, false)
}

override fun setForceOtherUsersAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_OTHER_USERS_PRO, isPro)
_events.tryEmit(SET_FORCE_OTHER_USERS_PRO)
}

override fun forceIncomingMessagesAsPro(): Boolean {
return getBooleanPreference(SET_FORCE_INCOMING_MESSAGE_PRO, false)
}

override fun setForceIncomingMessagesAsPro(isPro: Boolean) {
setBooleanPreference(SET_FORCE_INCOMING_MESSAGE_PRO, isPro)
}

override fun forcePostPro(): Boolean {
return postProLaunchState.value
}

override fun setForcePostPro(postPro: Boolean) {
setBooleanPreference(SET_FORCE_POST_PRO, postPro)
postProLaunchState.update { postPro }
_events.tryEmit(SET_FORCE_POST_PRO)
}

override fun hasSeenProExpiring(): Boolean {
return getBooleanPreference(HAS_SEEN_PRO_EXPIRING, false)
}
Expand All @@ -1204,10 +1101,6 @@ class AppTextSecurePreferences @Inject constructor(
setBooleanPreference(HAS_SEEN_PRO_EXPIRED, true)
}

override fun watchPostProStatus(): StateFlow<Boolean> {
return postProLaunchState
}

override fun getFingerprintKeyGenerated(): Boolean {
return getBooleanPreference(TextSecurePreferences.FINGERPRINT_KEY_GENERATED, false)
}
Expand Down Expand Up @@ -1312,7 +1205,6 @@ class AppTextSecurePreferences @Inject constructor(
*/
override fun clearAll() {
pushEnabled.update { false }
postProLaunchState.update { false }
hiddenPasswordState.update { false }

getDefaultSharedPreferences(context).edit(commit = true) { clear() }
Expand Down Expand Up @@ -1378,58 +1270,6 @@ class AppTextSecurePreferences @Inject constructor(
setStringPreference(TextSecurePreferences.DEPRECATING_START_TIME_OVERRIDE, value.toString())
}
}
override fun getDebugMessageFeatures(): Set<ProFeature> {
return buildSet {
getLongPreference(TextSecurePreferences.DEBUG_PRO_MESSAGE_FEATURES, 0L).toProMessageFeatures(this)
getLongPreference(TextSecurePreferences.DEBUG_PRO_PROFILE_FEATURES, 0L).toProProfileFeatures(this)
}
}

override fun setDebugMessageFeatures(features: Set<ProFeature>) {
setLongPreference(TextSecurePreferences.DEBUG_PRO_MESSAGE_FEATURES, features.filterIsInstance<ProMessageFeature>().toBitSet().rawValue)
setLongPreference(TextSecurePreferences.DEBUG_PRO_PROFILE_FEATURES, features.filterIsInstance<ProProfileFeature>().toBitSet().rawValue)
}

override fun getDebugSubscriptionType(): DebugMenuViewModel.DebugSubscriptionStatus? {
return getStringPreference(TextSecurePreferences.DEBUG_SUBSCRIPTION_STATUS, null)?.let {
DebugMenuViewModel.DebugSubscriptionStatus.valueOf(it)
}
}

override fun setDebugSubscriptionType(status: DebugMenuViewModel.DebugSubscriptionStatus?) {
setStringPreference(TextSecurePreferences.DEBUG_SUBSCRIPTION_STATUS, status?.name)
_events.tryEmit(TextSecurePreferences.DEBUG_SUBSCRIPTION_STATUS)
}

override fun getDebugProPlanStatus(): DebugMenuViewModel.DebugProPlanStatus? {
return getStringPreference(TextSecurePreferences.DEBUG_PRO_PLAN_STATUS, null)?.let {
DebugMenuViewModel.DebugProPlanStatus.valueOf(it)
}
}

override fun setDebugProPlanStatus(status: DebugMenuViewModel.DebugProPlanStatus?) {
setStringPreference(TextSecurePreferences.DEBUG_PRO_PLAN_STATUS, status?.name)
_events.tryEmit(TextSecurePreferences.DEBUG_PRO_PLAN_STATUS)
}

override fun getDebugForceNoBilling(): Boolean {
return getBooleanPreference(TextSecurePreferences.DEBUG_FORCE_NO_BILLING, false)
}

override fun setDebugForceNoBilling(hasBilling: Boolean) {
setBooleanPreference(TextSecurePreferences.DEBUG_FORCE_NO_BILLING, hasBilling)
_events.tryEmit(TextSecurePreferences.DEBUG_FORCE_NO_BILLING)
}

override fun getDebugIsWithinQuickRefund(): Boolean {
return getBooleanPreference(TextSecurePreferences.DEBUG_WITHIN_QUICK_REFUND, false)
}

override fun setDebugIsWithinQuickRefund(isWithin: Boolean) {
setBooleanPreference(TextSecurePreferences.DEBUG_WITHIN_QUICK_REFUND, isWithin)
_events.tryEmit(TextSecurePreferences.DEBUG_FORCE_NO_BILLING)
}

override fun getSubscriptionProvider(): String? {
return getStringPreference(TextSecurePreferences.SUBSCRIPTION_PROVIDER, null)
}
Expand Down Expand Up @@ -1548,23 +1388,3 @@ class AppTextSecurePreferences @Inject constructor(
_events.tryEmit(key)
}
}

fun TextSecurePreferences.observeBooleanKey(
key: String,
default: Boolean
): Flow<Boolean> =
TextSecurePreferences.events
.filter { it == key }
.onStart { emit(key) } // trigger initial read
.map { getBooleanPreference(key, default) }
.distinctUntilChanged()

fun TextSecurePreferences.observeStringKey(
key: String,
default: String?
): Flow<String?> =
TextSecurePreferences.events
.filter { it == key }
.onStart { emit(key) }
.map { getStringPreference(key, default) }
.distinctUntilChanged()
Loading