android: simplify logic for allowing voice messages on alert; fix non exhaustive when in SendMsgView (#1484)

This commit is contained in:
JRoberts
2022-12-03 16:19:13 +04:00
committed by GitHub
parent 48d24d3582
commit 01a86336c0
3 changed files with 14 additions and 19 deletions

View File

@@ -1983,6 +1983,11 @@ data class ContactUserPreferences(
val fullDelete: ContactUserPreference,
val voice: ContactUserPreference,
) {
fun toPreferences(): ChatPreferences = ChatPreferences(
fullDelete = fullDelete.userPreference.pref,
voice = voice.userPreference.pref
)
companion object {
val sampleData = ContactUserPreferences(
fullDelete = ContactUserPreference(

View File

@@ -457,9 +457,8 @@ fun ComposeView(
fun allowVoiceToContact() {
val contact = (chat.chatInfo as ChatInfo.Direct?)?.contact ?: return
val featuresAllowed = contactUserPrefsToFeaturesAllowed(contact.mergedPreferences)
val prefs = contact.mergedPreferences.toPreferences().copy(voice = ChatPreference(allow = FeatureAllowed.YES))
withApi {
val prefs = contactFeaturesAllowedToPrefs(featuresAllowed).copy(voice = ChatPreference(FeatureAllowed.YES))
val toContact = chatModel.controller.apiSetContactPrefs(contact.contactId, prefs)
if (toContact != null) {
chatModel.updateContact(toContact)
@@ -576,13 +575,7 @@ fun ComposeView(
.clip(CircleShape)
)
}
val allowedVoiceByPrefs = remember(chat.chatInfo) {
when (chat.chatInfo) {
is ChatInfo.Direct -> chat.chatInfo.contact.mergedPreferences.voice.enabled.forUser
is ChatInfo.Group -> chat.chatInfo.groupInfo.fullGroupPreferences.voice.enable == GroupFeatureEnabled.ON
else -> false
}
}
val allowedVoiceByPrefs = remember(chat.chatInfo) { chat.chatInfo.voiceMessageAllowed }
val needToAllowVoiceToContact = remember(chat.chatInfo) {
when (chat.chatInfo) {
is ChatInfo.Direct -> with(chat.chatInfo.contact.mergedPreferences.voice) {

View File

@@ -237,16 +237,13 @@ private fun NativeKeyboard(
var showKeyboard by remember { mutableStateOf(false) }
LaunchedEffect(cs.contextItem) {
when (cs.contextItem) {
is ComposeContextItem.QuotedItem -> {
delay(100)
showKeyboard = true
}
is ComposeContextItem.EditingItem -> {
// Keyboard will not show up if we try to show it too fast
delay(300)
showKeyboard = true
}
if (cs.contextItem is ComposeContextItem.QuotedItem) {
delay(100)
showKeyboard = true
} else if (cs.contextItem is ComposeContextItem.EditingItem) {
// Keyboard will not show up if we try to show it too fast
delay(300)
showKeyboard = true
}
}