mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-24 08:45:31 +00:00
ios: show voice message button based on preference (#1416)
This commit is contained in:
@@ -34,7 +34,6 @@ struct ComposeState {
|
||||
var preview: ComposePreview
|
||||
var contextItem: ComposeContextItem
|
||||
var voiceMessageRecordingState: VoiceMessageRecordingState
|
||||
var voiceMessageAllowed: Bool
|
||||
var inProgress = false
|
||||
var disabled = false
|
||||
var useLinkPreviews: Bool = UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS)
|
||||
@@ -43,14 +42,12 @@ struct ComposeState {
|
||||
message: String = "",
|
||||
preview: ComposePreview = .noPreview,
|
||||
contextItem: ComposeContextItem = .noContextItem,
|
||||
voiceMessageRecordingState: VoiceMessageRecordingState = .noRecording,
|
||||
voiceMessageAllowed: Bool = true // TODO based on preference
|
||||
voiceMessageRecordingState: VoiceMessageRecordingState = .noRecording
|
||||
) {
|
||||
self.message = message
|
||||
self.preview = preview
|
||||
self.contextItem = contextItem
|
||||
self.voiceMessageRecordingState = voiceMessageRecordingState
|
||||
self.voiceMessageAllowed = voiceMessageAllowed
|
||||
}
|
||||
|
||||
init(editingItem: ChatItem) {
|
||||
@@ -63,7 +60,6 @@ struct ComposeState {
|
||||
} else {
|
||||
self.voiceMessageRecordingState = .noRecording
|
||||
}
|
||||
self.voiceMessageAllowed = false
|
||||
}
|
||||
|
||||
func copy(
|
||||
@@ -125,6 +121,13 @@ struct ComposeState {
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
|
||||
var voicePreview: Bool {
|
||||
switch preview {
|
||||
case .voicePreview: return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func chatItemPreview(chatItem: ChatItem) -> ComposePreview {
|
||||
@@ -148,7 +151,7 @@ func chatItemPreview(chatItem: ChatItem) -> ComposePreview {
|
||||
|
||||
struct ComposeView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
let chat: Chat
|
||||
@ObservedObject var chat: Chat
|
||||
@Binding var composeState: ComposeState
|
||||
@FocusState.Binding var keyboardVisible: Bool
|
||||
|
||||
@@ -193,6 +196,7 @@ struct ComposeView: View {
|
||||
sendMessage()
|
||||
resetLinkPreview()
|
||||
},
|
||||
voiceMessageAllowed: chat.chatInfo.voiceMessageAllowed,
|
||||
startVoiceMessageRecording: {
|
||||
Task {
|
||||
await startVoiceMessageRecording()
|
||||
|
||||
@@ -12,6 +12,7 @@ import SimpleXChat
|
||||
struct SendMessageView: View {
|
||||
@Binding var composeState: ComposeState
|
||||
var sendMessage: () -> Void
|
||||
var voiceMessageAllowed: Bool = true
|
||||
var startVoiceMessageRecording: (() -> Void)? = nil
|
||||
var finishVoiceMessageRecording: (() -> Void)? = nil
|
||||
@State private var longPressingVMR = false
|
||||
@@ -63,7 +64,7 @@ struct SendMessageView: View {
|
||||
.padding([.bottom, .trailing], 3)
|
||||
} else {
|
||||
let vmrs = composeState.voiceMessageRecordingState
|
||||
if composeState.voiceMessageAllowed,
|
||||
if voiceMessageAllowed,
|
||||
composeState.message.isEmpty,
|
||||
!composeState.editing,
|
||||
(composeState.noPreview && vmrs == .noRecording)
|
||||
@@ -90,7 +91,11 @@ struct SendMessageView: View {
|
||||
.resizable()
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
.disabled(!composeState.sendEnabled || composeState.disabled)
|
||||
.disabled(
|
||||
!composeState.sendEnabled ||
|
||||
composeState.disabled ||
|
||||
(!voiceMessageAllowed && composeState.voicePreview)
|
||||
)
|
||||
.frame(width: 29, height: 29)
|
||||
.padding([.bottom, .trailing], 4)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ struct TerminalView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@AppStorage(DEFAULT_PERFORM_LA) private var prefPerformLA = false
|
||||
@AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false
|
||||
@State var composeState: ComposeState = ComposeState(voiceMessageAllowed: false)
|
||||
@State var composeState: ComposeState = ComposeState()
|
||||
@FocusState private var keyboardVisible: Bool
|
||||
@State var authorized = !UserDefaults.standard.bool(forKey: DEFAULT_PERFORM_LA)
|
||||
|
||||
@@ -86,6 +86,7 @@ struct TerminalView: View {
|
||||
SendMessageView(
|
||||
composeState: $composeState,
|
||||
sendMessage: sendMessage,
|
||||
voiceMessageAllowed: false,
|
||||
keyboardVisible: $keyboardVisible
|
||||
)
|
||||
.padding(.horizontal, 12)
|
||||
@@ -120,7 +121,7 @@ struct TerminalView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
composeState = ComposeState(voiceMessageAllowed: false)
|
||||
composeState = ComposeState()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -452,6 +452,10 @@ public func toGroupPreferences(_ fullPreferences: FullGroupPreferences) -> Group
|
||||
public struct GroupPreference: Codable, Equatable {
|
||||
public var enable: GroupFeatureEnabled
|
||||
|
||||
public var on: Bool {
|
||||
enable == .on
|
||||
}
|
||||
|
||||
public init(enable: GroupFeatureEnabled) {
|
||||
self.enable = enable
|
||||
}
|
||||
@@ -608,11 +612,17 @@ public enum ChatInfo: Identifiable, Decodable, NamedChat {
|
||||
}
|
||||
|
||||
public var contact: Contact? {
|
||||
get {
|
||||
switch self {
|
||||
case let .direct(contact): return contact
|
||||
default: return nil
|
||||
}
|
||||
switch self {
|
||||
case let .direct(contact): return contact
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var voiceMessageAllowed: Bool {
|
||||
switch self {
|
||||
case let .direct(contact): return contact.mergedPreferences.voice.enabled.forUser
|
||||
case let .group(groupInfo): return groupInfo.fullGroupPreferences.voice.on
|
||||
default: return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user