feat: add sending community block flags and preference options

This commit is contained in:
0x330a 2023-08-14 17:16:29 +10:00
parent ea6cb1af1c
commit 31ccc09c4a
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
8 changed files with 71 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.preference.Preference
import dagger.hilt.android.AndroidEntryPoint
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
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.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat
import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.service.KeyCachingService
import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.areNotificationsEnabled
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.IntentUtils
import java.util.prefs.PreferenceChangeEvent
import java.util.prefs.PreferenceChangeListener
import javax.inject.Inject
@AndroidEntryPoint
class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
@Inject lateinit var configFactory: ConfigFactory
override fun onCreate(paramBundle: Bundle?) {
super.onCreate(paramBundle)
findPreference<Preference>(TextSecurePreferences.SCREEN_LOCK)!!
@ -30,6 +40,19 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
.onPreferenceChangeListener = TypingIndicatorsToggleListener()
findPreference<Preference>(TextSecurePreferences.CALL_NOTIFICATIONS_ENABLED)!!
.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()
}

View File

@ -627,6 +627,9 @@
<string name="preferences_notifications__priority">Priority</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__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 -->
<!-- **************************************** -->

View File

@ -20,6 +20,16 @@
</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">
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"

View File

@ -95,4 +95,25 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getNtsPriority(JNIEnv *
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
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});
}

View File

@ -126,6 +126,8 @@ class UserProfile(pointer: Long) : ConfigBase(pointer) {
external fun setPic(userPic: UserPic)
external fun setNtsPriority(priority: Int)
external fun getNtsPriority(): Int
external fun getBlocksCommunityMessageRequests(): Boolean
external fun setBlocksCommunityMessageRequests(blocks: Boolean)
}
class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {

View File

@ -25,7 +25,8 @@ class VisibleMessage(
var profile: Profile? = null,
var openGroupInvitation: OpenGroupInvitation? = null,
var reaction: Reaction? = null,
var hasMention: Boolean = false
var hasMention: Boolean = false,
var blocksMessageRequests: Boolean = false
) : Message() {
override val isSelfSendValid: Boolean = true
@ -141,6 +142,8 @@ class VisibleMessage(
return null
}
}
// Community blocked message requests flag
dataMessage.blocksCommunityMessageRequests = blocksMessageRequests
// Sync target
if (syncTarget != null) {
dataMessage.syncTarget = syncTarget

View File

@ -241,9 +241,15 @@ object MessageSender {
private fun sendToOpenGroupDestination(destination: Destination, message: Message): Promise<Unit, Exception> {
val deferred = deferred<Unit, Exception>()
val storage = MessagingModuleConfiguration.shared.storage
val configFactory = MessagingModuleConfiguration.shared.configFactory
if (message.sentTimestamp == null) {
message.sentTimestamp = SnodeAPI.nowWithOffset
}
configFactory.user?.let { user ->
if (message is VisibleMessage) {
message.blocksMessageRequests = user.getBlocksCommunityMessageRequests()
}
}
val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!
var serverCapabilities = listOf<String>()
var blindedPublicKey: ByteArray? = null

View File

@ -287,6 +287,8 @@ interface TextSecurePreferences {
const val OCEAN_DARK = "ocean.dark"
const val OCEAN_LIGHT = "ocean.light"
const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS"
@JvmStatic
fun getLastConfigurationSyncTime(context: Context): Long {
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)