feat: add sending community block flags and preference options
This commit is contained in:
parent
ea6cb1af1c
commit
31ccc09c4a
|
@ -8,6 +8,7 @@ import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import network.loki.messenger.BuildConfig
|
import network.loki.messenger.BuildConfig
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
|
@ -15,13 +16,22 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.isPasswo
|
||||||
import org.session.libsession.utilities.TextSecurePreferences.Companion.setScreenLockEnabled
|
import org.session.libsession.utilities.TextSecurePreferences.Companion.setScreenLockEnabled
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
|
import org.thoughtcrime.securesms.dependencies.ConfigFactory
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions
|
import org.thoughtcrime.securesms.permissions.Permissions
|
||||||
import org.thoughtcrime.securesms.service.KeyCachingService
|
import org.thoughtcrime.securesms.service.KeyCachingService
|
||||||
import org.thoughtcrime.securesms.showSessionDialog
|
import org.thoughtcrime.securesms.showSessionDialog
|
||||||
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.areNotificationsEnabled
|
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.areNotificationsEnabled
|
||||||
|
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
||||||
import org.thoughtcrime.securesms.util.IntentUtils
|
import org.thoughtcrime.securesms.util.IntentUtils
|
||||||
|
import java.util.prefs.PreferenceChangeEvent
|
||||||
|
import java.util.prefs.PreferenceChangeListener
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
|
class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
|
||||||
|
|
||||||
|
@Inject lateinit var configFactory: ConfigFactory
|
||||||
|
|
||||||
override fun onCreate(paramBundle: Bundle?) {
|
override fun onCreate(paramBundle: Bundle?) {
|
||||||
super.onCreate(paramBundle)
|
super.onCreate(paramBundle)
|
||||||
findPreference<Preference>(TextSecurePreferences.SCREEN_LOCK)!!
|
findPreference<Preference>(TextSecurePreferences.SCREEN_LOCK)!!
|
||||||
|
@ -30,6 +40,19 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
|
||||||
.onPreferenceChangeListener = TypingIndicatorsToggleListener()
|
.onPreferenceChangeListener = TypingIndicatorsToggleListener()
|
||||||
findPreference<Preference>(TextSecurePreferences.CALL_NOTIFICATIONS_ENABLED)!!
|
findPreference<Preference>(TextSecurePreferences.CALL_NOTIFICATIONS_ENABLED)!!
|
||||||
.onPreferenceChangeListener = CallToggleListener(this) { setCall(it) }
|
.onPreferenceChangeListener = CallToggleListener(this) { setCall(it) }
|
||||||
|
val allowMessageRequestPref = findPreference<Preference>(TextSecurePreferences.ALLOW_MESSAGE_REQUESTS)!!
|
||||||
|
configFactory.user?.let { user ->
|
||||||
|
allowMessageRequestPref.setDefaultValue(!user.getBlocksCommunityMessageRequests())
|
||||||
|
allowMessageRequestPref
|
||||||
|
.onPreferenceChangeListener =
|
||||||
|
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
|
user.setBlocksCommunityMessageRequests(!(newValue as Boolean))
|
||||||
|
ConfigurationMessageUtilities.syncConfigurationIfNeeded(requireContext())
|
||||||
|
return@OnPreferenceChangeListener true
|
||||||
|
}
|
||||||
|
} ?: run {
|
||||||
|
allowMessageRequestPref.isVisible = false
|
||||||
|
}
|
||||||
initializeVisibility()
|
initializeVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -627,6 +627,9 @@
|
||||||
<string name="preferences_notifications__priority">Priority</string>
|
<string name="preferences_notifications__priority">Priority</string>
|
||||||
<string name="preferences_app_protection__screenshot_notifications">Screenshot Notifications</string>
|
<string name="preferences_app_protection__screenshot_notifications">Screenshot Notifications</string>
|
||||||
<string name="preferences_app_protected__screenshot_notifications_summary">Receive a notification when a contact takes a screenshot of a one-to-one chat.</string>
|
<string name="preferences_app_protected__screenshot_notifications_summary">Receive a notification when a contact takes a screenshot of a one-to-one chat.</string>
|
||||||
|
<string name="preferences__message_requests_category">Message Requests</string>
|
||||||
|
<string name="preferences__message_requests_title">Community Message Requests</string>
|
||||||
|
<string name="preferences__message_requests_summary">Allow message requests from Community conversations</string>
|
||||||
<!-- **************************************** -->
|
<!-- **************************************** -->
|
||||||
<!-- menus -->
|
<!-- menus -->
|
||||||
<!-- **************************************** -->
|
<!-- **************************************** -->
|
||||||
|
|
|
@ -20,6 +20,16 @@
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/preferences__message_requests_category">
|
||||||
|
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
|
android:persistent="false"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="libsession.BLOCK_MESSAGE_REQUESTS"
|
||||||
|
android:title="@string/preferences__message_requests_title"
|
||||||
|
android:summary="@string/preferences__message_requests_summary"
|
||||||
|
/>
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/preferences__read_receipts">
|
<PreferenceCategory android:title="@string/preferences__read_receipts">
|
||||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
|
|
|
@ -95,4 +95,25 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getNtsPriority(JNIEnv *
|
||||||
std::lock_guard lock{util::util_mutex_};
|
std::lock_guard lock{util::util_mutex_};
|
||||||
auto profile = ptrToProfile(env, thiz);
|
auto profile = ptrToProfile(env, thiz);
|
||||||
return profile->get_nts_priority();
|
return profile->get_nts_priority();
|
||||||
|
}
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_UserProfile_getBlocksCommunityMessageRequests(
|
||||||
|
JNIEnv *env, jobject thiz) {
|
||||||
|
std::lock_guard lock{util::util_mutex_};
|
||||||
|
auto profile = ptrToProfile(env, thiz);
|
||||||
|
auto blinded_msg_requests = profile->get_blinded_msgreqs();
|
||||||
|
if (blinded_msg_requests.has_value()) {
|
||||||
|
return *blinded_msg_requests;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_UserProfile_setBlocksCommunityMessageRequests(
|
||||||
|
JNIEnv *env, jobject thiz, jboolean blocks) {
|
||||||
|
std::lock_guard lock{util::util_mutex_};
|
||||||
|
auto profile = ptrToProfile(env, thiz);
|
||||||
|
profile->set_blinded_msgreqs(std::optional{(bool)blocks});
|
||||||
}
|
}
|
|
@ -126,6 +126,8 @@ class UserProfile(pointer: Long) : ConfigBase(pointer) {
|
||||||
external fun setPic(userPic: UserPic)
|
external fun setPic(userPic: UserPic)
|
||||||
external fun setNtsPriority(priority: Int)
|
external fun setNtsPriority(priority: Int)
|
||||||
external fun getNtsPriority(): Int
|
external fun getNtsPriority(): Int
|
||||||
|
external fun getBlocksCommunityMessageRequests(): Boolean
|
||||||
|
external fun setBlocksCommunityMessageRequests(blocks: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {
|
class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {
|
||||||
|
|
|
@ -25,7 +25,8 @@ class VisibleMessage(
|
||||||
var profile: Profile? = null,
|
var profile: Profile? = null,
|
||||||
var openGroupInvitation: OpenGroupInvitation? = null,
|
var openGroupInvitation: OpenGroupInvitation? = null,
|
||||||
var reaction: Reaction? = null,
|
var reaction: Reaction? = null,
|
||||||
var hasMention: Boolean = false
|
var hasMention: Boolean = false,
|
||||||
|
var blocksMessageRequests: Boolean = false
|
||||||
) : Message() {
|
) : Message() {
|
||||||
|
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
@ -141,6 +142,8 @@ class VisibleMessage(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Community blocked message requests flag
|
||||||
|
dataMessage.blocksCommunityMessageRequests = blocksMessageRequests
|
||||||
// Sync target
|
// Sync target
|
||||||
if (syncTarget != null) {
|
if (syncTarget != null) {
|
||||||
dataMessage.syncTarget = syncTarget
|
dataMessage.syncTarget = syncTarget
|
||||||
|
|
|
@ -241,9 +241,15 @@ object MessageSender {
|
||||||
private fun sendToOpenGroupDestination(destination: Destination, message: Message): Promise<Unit, Exception> {
|
private fun sendToOpenGroupDestination(destination: Destination, message: Message): Promise<Unit, Exception> {
|
||||||
val deferred = deferred<Unit, Exception>()
|
val deferred = deferred<Unit, Exception>()
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
|
val configFactory = MessagingModuleConfiguration.shared.configFactory
|
||||||
if (message.sentTimestamp == null) {
|
if (message.sentTimestamp == null) {
|
||||||
message.sentTimestamp = SnodeAPI.nowWithOffset
|
message.sentTimestamp = SnodeAPI.nowWithOffset
|
||||||
}
|
}
|
||||||
|
configFactory.user?.let { user ->
|
||||||
|
if (message is VisibleMessage) {
|
||||||
|
message.blocksMessageRequests = user.getBlocksCommunityMessageRequests()
|
||||||
|
}
|
||||||
|
}
|
||||||
val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!
|
val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!
|
||||||
var serverCapabilities = listOf<String>()
|
var serverCapabilities = listOf<String>()
|
||||||
var blindedPublicKey: ByteArray? = null
|
var blindedPublicKey: ByteArray? = null
|
||||||
|
|
|
@ -287,6 +287,8 @@ interface TextSecurePreferences {
|
||||||
const val OCEAN_DARK = "ocean.dark"
|
const val OCEAN_DARK = "ocean.dark"
|
||||||
const val OCEAN_LIGHT = "ocean.light"
|
const val OCEAN_LIGHT = "ocean.light"
|
||||||
|
|
||||||
|
const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getLastConfigurationSyncTime(context: Context): Long {
|
fun getLastConfigurationSyncTime(context: Context): Long {
|
||||||
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)
|
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)
|
||||||
|
|
Loading…
Reference in New Issue