mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 12:19:54 +00:00
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap * fix voice recording * fix video, accepting calls from chat, preference toggles in chat * WIP message and meta * handle links in attributed strings * custom attribute for links to prevent race conditions with default tap handler
This commit is contained in:
parent
5f56f61c36
commit
4b42a19ccb
28 changed files with 461 additions and 420 deletions
|
@ -1413,22 +1413,6 @@ enum NotificationsMode: String, Decodable, SelectableItem {
|
|||
static var values: [NotificationsMode] = [.instant, .periodic, .off]
|
||||
}
|
||||
|
||||
enum PrivacyChatListOpenLinksMode: String, CaseIterable, Codable, RawRepresentable, Identifiable {
|
||||
case yes
|
||||
case no
|
||||
case ask
|
||||
|
||||
var id: Self { self }
|
||||
|
||||
var text: LocalizedStringKey {
|
||||
switch self {
|
||||
case .yes: return "Yes"
|
||||
case .no: return "No"
|
||||
case .ask: return "Ask"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RemoteCtrlInfo: Decodable {
|
||||
var remoteCtrlId: Int64
|
||||
var ctrlDeviceName: String
|
||||
|
@ -1941,7 +1925,6 @@ struct AppSettings: Codable, Equatable {
|
|||
var privacyAskToApproveRelays: Bool? = nil
|
||||
var privacyAcceptImages: Bool? = nil
|
||||
var privacyLinkPreviews: Bool? = nil
|
||||
var privacyChatListOpenLinks: PrivacyChatListOpenLinksMode? = nil
|
||||
var privacyShowChatPreviews: Bool? = nil
|
||||
var privacySaveLastDraft: Bool? = nil
|
||||
var privacyProtectScreen: Bool? = nil
|
||||
|
@ -1977,7 +1960,6 @@ struct AppSettings: Codable, Equatable {
|
|||
if privacyAskToApproveRelays != def.privacyAskToApproveRelays { empty.privacyAskToApproveRelays = privacyAskToApproveRelays }
|
||||
if privacyAcceptImages != def.privacyAcceptImages { empty.privacyAcceptImages = privacyAcceptImages }
|
||||
if privacyLinkPreviews != def.privacyLinkPreviews { empty.privacyLinkPreviews = privacyLinkPreviews }
|
||||
if privacyChatListOpenLinks != def.privacyChatListOpenLinks { empty.privacyChatListOpenLinks = privacyChatListOpenLinks }
|
||||
if privacyShowChatPreviews != def.privacyShowChatPreviews { empty.privacyShowChatPreviews = privacyShowChatPreviews }
|
||||
if privacySaveLastDraft != def.privacySaveLastDraft { empty.privacySaveLastDraft = privacySaveLastDraft }
|
||||
if privacyProtectScreen != def.privacyProtectScreen { empty.privacyProtectScreen = privacyProtectScreen }
|
||||
|
@ -2014,7 +1996,6 @@ struct AppSettings: Codable, Equatable {
|
|||
privacyAskToApproveRelays: true,
|
||||
privacyAcceptImages: true,
|
||||
privacyLinkPreviews: true,
|
||||
privacyChatListOpenLinks: .ask,
|
||||
privacyShowChatPreviews: true,
|
||||
privacySaveLastDraft: true,
|
||||
privacyProtectScreen: false,
|
||||
|
|
|
@ -60,16 +60,16 @@ struct CICallItemView: View {
|
|||
|
||||
@ViewBuilder private func acceptCallButton() -> some View {
|
||||
if case let .direct(contact) = chat.chatInfo {
|
||||
Button {
|
||||
if let invitation = m.callInvitations[contact.id] {
|
||||
CallController.shared.answerCall(invitation: invitation)
|
||||
logger.debug("acceptCallButton call answered")
|
||||
} else {
|
||||
AlertManager.shared.showAlertMsg(title: "Call already ended!")
|
||||
}
|
||||
} label: {
|
||||
Label("Answer call", systemImage: "phone.arrow.down.left")
|
||||
}
|
||||
Label("Answer call", systemImage: "phone.arrow.down.left")
|
||||
.foregroundColor(theme.colors.primary)
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
if let invitation = m.callInvitations[contact.id] {
|
||||
CallController.shared.answerCall(invitation: invitation)
|
||||
logger.debug("acceptCallButton call answered")
|
||||
} else {
|
||||
AlertManager.shared.showAlertMsg(title: "Call already ended!")
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Image(systemName: "phone.arrow.down.left").foregroundColor(theme.colors.secondary)
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ struct CIFeaturePreferenceView: View {
|
|||
allowed != .no && ct.allowsFeature(feature) && !ct.userAllowsFeature(feature) {
|
||||
let setParam = feature == .timedMessages && ct.mergedPreferences.timedMessages.userPreference.preference.ttl == nil
|
||||
featurePreferenceView(acceptText: setParam ? "Set 1 day" : "Accept")
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
allowFeatureToContact(ct, feature, param: setParam ? 86400 : nil)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
featurePreferenceView()
|
||||
}
|
||||
|
|
|
@ -19,42 +19,42 @@ struct CIFileView: View {
|
|||
var body: some View {
|
||||
if smallViewSize != nil {
|
||||
fileIndicator()
|
||||
.onTapGesture(perform: fileAction)
|
||||
.simultaneousGesture(TapGesture().onEnded(fileAction))
|
||||
} else {
|
||||
let metaReserve = edited
|
||||
? " "
|
||||
: " "
|
||||
Button(action: fileAction) {
|
||||
HStack(alignment: .bottom, spacing: 6) {
|
||||
fileIndicator()
|
||||
.padding(.top, 5)
|
||||
.padding(.bottom, 3)
|
||||
if let file = file {
|
||||
let prettyFileSize = ByteCountFormatter.string(fromByteCount: file.fileSize, countStyle: .binary)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(file.fileName)
|
||||
.lineLimit(1)
|
||||
.multilineTextAlignment(.leading)
|
||||
.foregroundColor(theme.colors.onBackground)
|
||||
Text(prettyFileSize + metaReserve)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
.multilineTextAlignment(.leading)
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
}
|
||||
} else {
|
||||
Text(metaReserve)
|
||||
HStack(alignment: .bottom, spacing: 6) {
|
||||
fileIndicator()
|
||||
.padding(.top, 5)
|
||||
.padding(.bottom, 3)
|
||||
if let file = file {
|
||||
let prettyFileSize = ByteCountFormatter.string(fromByteCount: file.fileSize, countStyle: .binary)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(file.fileName)
|
||||
.lineLimit(1)
|
||||
.multilineTextAlignment(.leading)
|
||||
.foregroundColor(theme.colors.onBackground)
|
||||
Text(prettyFileSize + metaReserve)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
.multilineTextAlignment(.leading)
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
}
|
||||
} else {
|
||||
Text(metaReserve)
|
||||
}
|
||||
.padding(.top, 4)
|
||||
.padding(.bottom, 6)
|
||||
.padding(.leading, 10)
|
||||
.padding(.trailing, 12)
|
||||
}
|
||||
.padding(.top, 4)
|
||||
.padding(.bottom, 6)
|
||||
.padding(.leading, 10)
|
||||
.padding(.trailing, 12)
|
||||
.simultaneousGesture(TapGesture().onEnded(fileAction))
|
||||
.disabled(!itemInteractive)
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
private var itemInteractive: Bool {
|
||||
if let file = file {
|
||||
switch (file.fileStatus) {
|
||||
|
|
|
@ -84,12 +84,12 @@ struct CIGroupInvitationView: View {
|
|||
}
|
||||
|
||||
if action {
|
||||
v.onTapGesture {
|
||||
v.simultaneousGesture(TapGesture().onEnded {
|
||||
inProgress = true
|
||||
joinGroup(groupInvitation.groupId) {
|
||||
await MainActor.run { inProgress = false }
|
||||
}
|
||||
}
|
||||
})
|
||||
.disabled(inProgress)
|
||||
} else {
|
||||
v
|
||||
|
|
|
@ -31,7 +31,7 @@ struct CIImageView: View {
|
|||
.if(!smallView) { view in
|
||||
view.modifier(PrivacyBlur(blurred: $blurred))
|
||||
}
|
||||
.onTapGesture { showFullScreenImage = true }
|
||||
.simultaneousGesture(TapGesture().onEnded { showFullScreenImage = true })
|
||||
.onChange(of: m.activeCallViewIsCollapsed) { _ in
|
||||
showFullScreenImage = false
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ struct CIImageView: View {
|
|||
imageView(preview).modifier(PrivacyBlur(blurred: $blurred))
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
if let file = file {
|
||||
switch file.fileStatus {
|
||||
case .rcvInvitation, .rcvAborted:
|
||||
|
@ -80,7 +80,7 @@ struct CIImageView: View {
|
|||
default: ()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
|
|
|
@ -24,7 +24,7 @@ struct CIInvalidJSONView: View {
|
|||
.padding(.vertical, 6)
|
||||
.background(Color(uiColor: .tertiarySystemGroupedBackground))
|
||||
.textSelection(.disabled)
|
||||
.onTapGesture { showJSON = true }
|
||||
.simultaneousGesture(TapGesture().onEnded { showJSON = true })
|
||||
.appSheet(isPresented: $showJSON) {
|
||||
invalidJSONView(dataToString(json))
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ struct CIInvalidJSONView: View {
|
|||
|
||||
func invalidJSONView(_ json: String) -> some View {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
Button {
|
||||
Button { // this is used in the sheet, Button works here
|
||||
showShareSheet(items: [json])
|
||||
} label: {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
|
|
|
@ -38,9 +38,31 @@ struct CILinkView: View {
|
|||
.padding(.horizontal, 12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
openBrowserAlert(uri: linkPreview.uri)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func openBrowserAlert(uri: URL) {
|
||||
showAlert(
|
||||
NSLocalizedString("Open in browser?", comment: "alert title"),
|
||||
message: uri.absoluteString,
|
||||
actions: {[
|
||||
UIAlertAction(
|
||||
title: NSLocalizedString("Cancel", comment: "alert action"),
|
||||
style: .default,
|
||||
handler: { _ in }
|
||||
),
|
||||
UIAlertAction(
|
||||
title: NSLocalizedString("Open", comment: "alert action"),
|
||||
style: .default,
|
||||
handler: { _ in UIApplication.shared.open(uri) }
|
||||
)
|
||||
]}
|
||||
)
|
||||
}
|
||||
|
||||
struct LargeLinkPreview_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let preview = LinkPreview(
|
||||
|
|
|
@ -20,11 +20,11 @@ struct CIMemberCreatedContactView: View {
|
|||
case let .groupRcv(groupMember):
|
||||
if let contactId = groupMember.memberContactId {
|
||||
memberCreatedContactView(openText: "Open")
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
ItemsModel.shared.loadOpenChat("@\(contactId)") {
|
||||
dismissAllSheets(animated: true)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
memberCreatedContactView()
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ struct CIMetaView: View {
|
|||
@Environment(\.showTimestamp) var showTimestamp: Bool
|
||||
var chatItem: ChatItem
|
||||
var metaColor: Color
|
||||
var paleMetaColor = Color(UIColor.tertiaryLabel)
|
||||
var paleMetaColor = Color(uiColor: .tertiaryLabel)
|
||||
var showStatus = true
|
||||
var showEdited = true
|
||||
var invertedMaterial = false
|
||||
|
@ -152,11 +152,13 @@ func ciMetaText(
|
|||
return r.font(.caption)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
private func statusIconText(_ icon: String, _ color: Color?) -> Text {
|
||||
colored(Text(Image(systemName: icon)), color)
|
||||
}
|
||||
|
||||
// Applying `foregroundColor(nil)` breaks `.invertedForegroundStyle` modifier
|
||||
@inline(__always)
|
||||
private func colored(_ t: Text, _ color: Color?) -> Text {
|
||||
if let color {
|
||||
t.foregroundColor(color)
|
||||
|
|
|
@ -133,7 +133,7 @@ struct CIRcvDecryptionError: View {
|
|||
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary)
|
||||
.padding(.horizontal, 12)
|
||||
}
|
||||
.onTapGesture(perform: { onClick() })
|
||||
.simultaneousGesture(TapGesture().onEnded(onClick))
|
||||
.padding(.vertical, 6)
|
||||
.textSelection(.disabled)
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ struct CIRcvDecryptionError: View {
|
|||
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary)
|
||||
.padding(.horizontal, 12)
|
||||
}
|
||||
.onTapGesture(perform: { onClick() })
|
||||
.simultaneousGesture(TapGesture().onEnded(onClick))
|
||||
.padding(.vertical, 6)
|
||||
.textSelection(.disabled)
|
||||
}
|
||||
|
|
|
@ -47,57 +47,57 @@ struct CIVideoView: View {
|
|||
let file = chatItem.file
|
||||
ZStack(alignment: smallView ? .topLeading : .center) {
|
||||
ZStack(alignment: .topLeading) {
|
||||
if let file = file, let preview = preview, let decrypted = urlDecrypted, smallView {
|
||||
smallVideoView(decrypted, file, preview)
|
||||
} else if let file = file, let preview = preview, let player = player, let decrypted = urlDecrypted {
|
||||
videoView(player, decrypted, file, preview, duration)
|
||||
} else if let file = file, let defaultPreview = preview, file.loaded && urlDecrypted == nil, smallView {
|
||||
smallVideoViewEncrypted(file, defaultPreview)
|
||||
} else if let file = file, let defaultPreview = preview, file.loaded && urlDecrypted == nil {
|
||||
videoViewEncrypted(file, defaultPreview, duration)
|
||||
} else if let preview, let file {
|
||||
Group { if smallView { smallViewImageView(preview, file) } else { imageView(preview) } }
|
||||
.onTapGesture {
|
||||
switch file.fileStatus {
|
||||
case .rcvInvitation, .rcvAborted:
|
||||
receiveFileIfValidSize(file: file, receiveFile: receiveFile)
|
||||
case .rcvAccepted:
|
||||
switch file.fileProtocol {
|
||||
case .xftp:
|
||||
AlertManager.shared.showAlertMsg(
|
||||
title: "Waiting for video",
|
||||
message: "Video will be received when your contact completes uploading it."
|
||||
)
|
||||
case .smp:
|
||||
AlertManager.shared.showAlertMsg(
|
||||
title: "Waiting for video",
|
||||
message: "Video will be received when your contact is online, please wait or check later!"
|
||||
)
|
||||
case .local: ()
|
||||
}
|
||||
case .rcvTransfer: () // ?
|
||||
case .rcvComplete: () // ?
|
||||
case .rcvCancelled: () // TODO
|
||||
default: ()
|
||||
}
|
||||
if let file, let preview {
|
||||
if let urlDecrypted {
|
||||
if smallView {
|
||||
smallVideoView(urlDecrypted, file, preview)
|
||||
} else if let player {
|
||||
videoView(player, urlDecrypted, file, preview, duration)
|
||||
}
|
||||
} else if file.loaded {
|
||||
if smallView {
|
||||
smallVideoViewEncrypted(file, preview)
|
||||
} else {
|
||||
videoViewEncrypted(file, preview, duration)
|
||||
}
|
||||
} else {
|
||||
Group { if smallView { smallViewImageView(preview, file) } else { imageView(preview) } }
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
switch file.fileStatus {
|
||||
case .rcvInvitation, .rcvAborted:
|
||||
receiveFileIfValidSize(file: file, receiveFile: receiveFile)
|
||||
case .rcvAccepted:
|
||||
switch file.fileProtocol {
|
||||
case .xftp:
|
||||
AlertManager.shared.showAlertMsg(
|
||||
title: "Waiting for video",
|
||||
message: "Video will be received when your contact completes uploading it."
|
||||
)
|
||||
case .smp:
|
||||
AlertManager.shared.showAlertMsg(
|
||||
title: "Waiting for video",
|
||||
message: "Video will be received when your contact is online, please wait or check later!"
|
||||
)
|
||||
case .local: ()
|
||||
}
|
||||
case .rcvTransfer: () // ?
|
||||
case .rcvComplete: () // ?
|
||||
case .rcvCancelled: () // TODO
|
||||
default: ()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
if !smallView {
|
||||
durationProgress()
|
||||
}
|
||||
}
|
||||
if !blurred, let file, showDownloadButton(file.fileStatus) {
|
||||
if !smallView {
|
||||
Button {
|
||||
receiveFileIfValidSize(file: file, receiveFile: receiveFile)
|
||||
} label: {
|
||||
playPauseIcon("play.fill")
|
||||
}
|
||||
} else if !file.showStatusIconInSmallView {
|
||||
if !smallView || !file.showStatusIconInSmallView {
|
||||
playPauseIcon("play.fill")
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
receiveFileIfValidSize(file: file, receiveFile: receiveFile)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,27 +151,26 @@ struct CIVideoView: View {
|
|||
ZStack(alignment: .center) {
|
||||
let canBePlayed = !chatItem.chatDir.sent || file.fileStatus == CIFileStatus.sndComplete || (file.fileStatus == .sndStored && file.fileProtocol == .local)
|
||||
imageView(defaultPreview)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
decrypt(file: file) {
|
||||
showFullScreenPlayer = urlDecrypted != nil
|
||||
}
|
||||
}
|
||||
})
|
||||
.onChange(of: m.activeCallViewIsCollapsed) { _ in
|
||||
showFullScreenPlayer = false
|
||||
}
|
||||
if !blurred {
|
||||
if !decryptionInProgress {
|
||||
Button {
|
||||
decrypt(file: file) {
|
||||
if urlDecrypted != nil {
|
||||
videoPlaying = true
|
||||
player?.play()
|
||||
playPauseIcon(canBePlayed ? "play.fill" : "play.slash")
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
decrypt(file: file) {
|
||||
if urlDecrypted != nil {
|
||||
videoPlaying = true
|
||||
player?.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
playPauseIcon(canBePlayed ? "play.fill" : "play.slash")
|
||||
}
|
||||
.disabled(!canBePlayed)
|
||||
})
|
||||
.disabled(!canBePlayed)
|
||||
} else {
|
||||
videoDecryptionProgress()
|
||||
}
|
||||
|
@ -194,7 +193,7 @@ struct CIVideoView: View {
|
|||
}
|
||||
}
|
||||
.modifier(PrivacyBlur(enabled: !videoPlaying, blurred: $blurred))
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
switch player.timeControlStatus {
|
||||
case .playing:
|
||||
player.pause()
|
||||
|
@ -205,18 +204,17 @@ struct CIVideoView: View {
|
|||
}
|
||||
default: ()
|
||||
}
|
||||
}
|
||||
})
|
||||
.onChange(of: m.activeCallViewIsCollapsed) { _ in
|
||||
showFullScreenPlayer = false
|
||||
}
|
||||
if !videoPlaying && !blurred {
|
||||
Button {
|
||||
m.stopPreviousRecPlay = url
|
||||
player.play()
|
||||
} label: {
|
||||
playPauseIcon(canBePlayed ? "play.fill" : "play.slash")
|
||||
}
|
||||
.disabled(!canBePlayed)
|
||||
playPauseIcon(canBePlayed ? "play.fill" : "play.slash")
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
m.stopPreviousRecPlay = url
|
||||
player.play()
|
||||
})
|
||||
.disabled(!canBePlayed)
|
||||
}
|
||||
}
|
||||
fileStatusIcon()
|
||||
|
@ -235,7 +233,7 @@ struct CIVideoView: View {
|
|||
return ZStack(alignment: .topLeading) {
|
||||
let canBePlayed = !chatItem.chatDir.sent || file.fileStatus == CIFileStatus.sndComplete || (file.fileStatus == .sndStored && file.fileProtocol == .local)
|
||||
smallViewImageView(preview, file)
|
||||
.onTapGesture {
|
||||
.onTapGesture { // this is shown in chat list, where onTapGesture works
|
||||
decrypt(file: file) {
|
||||
showFullScreenPlayer = urlDecrypted != nil
|
||||
}
|
||||
|
@ -256,7 +254,7 @@ struct CIVideoView: View {
|
|||
private func smallVideoView(_ url: URL, _ file: CIFile, _ preview: UIImage) -> some View {
|
||||
return ZStack(alignment: .topLeading) {
|
||||
smallViewImageView(preview, file)
|
||||
.onTapGesture {
|
||||
.onTapGesture { // this is shown in chat list, where onTapGesture works
|
||||
showFullScreenPlayer = true
|
||||
}
|
||||
.onChange(of: m.activeCallViewIsCollapsed) { _ in
|
||||
|
@ -354,14 +352,14 @@ struct CIVideoView: View {
|
|||
case .sndCancelled: fileIcon("xmark", 10, 13)
|
||||
case let .sndError(sndFileError):
|
||||
fileIcon("xmark", 10, 13)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(sndFileError)
|
||||
}
|
||||
})
|
||||
case let .sndWarning(sndFileError):
|
||||
fileIcon("exclamationmark.triangle.fill", 10, 13)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(sndFileError, temporary: true)
|
||||
}
|
||||
})
|
||||
case .rcvInvitation: fileIcon("arrow.down", 10, 13)
|
||||
case .rcvAccepted: fileIcon("ellipsis", 14, 11)
|
||||
case let .rcvTransfer(rcvProgress, rcvTotal):
|
||||
|
@ -375,14 +373,14 @@ struct CIVideoView: View {
|
|||
case .rcvCancelled: fileIcon("xmark", 10, 13)
|
||||
case let .rcvError(rcvFileError):
|
||||
fileIcon("xmark", 10, 13)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(rcvFileError)
|
||||
}
|
||||
})
|
||||
case let .rcvWarning(rcvFileError):
|
||||
fileIcon("exclamationmark.triangle.fill", 10, 13)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(rcvFileError, temporary: true)
|
||||
}
|
||||
})
|
||||
case .invalid: fileIcon("questionmark", 10, 13)
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +427,7 @@ struct CIVideoView: View {
|
|||
Color.black.edgesIgnoringSafeArea(.all)
|
||||
VideoPlayer(player: fullPlayer)
|
||||
.overlay(alignment: .topLeading, content: {
|
||||
Button(action: { showFullScreenPlayer = false },
|
||||
Button(action: { showFullScreenPlayer = false }, // this is used in full screen player, Button works here
|
||||
label: {
|
||||
Image(systemName: "multiply")
|
||||
.resizable()
|
||||
|
|
|
@ -168,14 +168,14 @@ struct VoiceMessagePlayer: View {
|
|||
case .sndCancelled: playbackButton()
|
||||
case let .sndError(sndFileError):
|
||||
fileStatusIcon("multiply", 14)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(sndFileError)
|
||||
}
|
||||
})
|
||||
case let .sndWarning(sndFileError):
|
||||
fileStatusIcon("exclamationmark.triangle.fill", 16)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(sndFileError, temporary: true)
|
||||
}
|
||||
})
|
||||
case .rcvInvitation: downloadButton(recordingFile, "play.fill")
|
||||
case .rcvAccepted: loadingIcon()
|
||||
case .rcvTransfer: loadingIcon()
|
||||
|
@ -184,14 +184,14 @@ struct VoiceMessagePlayer: View {
|
|||
case .rcvCancelled: playPauseIcon("play.fill", Color(uiColor: .tertiaryLabel))
|
||||
case let .rcvError(rcvFileError):
|
||||
fileStatusIcon("multiply", 14)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(rcvFileError)
|
||||
}
|
||||
})
|
||||
case let .rcvWarning(rcvFileError):
|
||||
fileStatusIcon("exclamationmark.triangle.fill", 16)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
showFileErrorAlert(rcvFileError, temporary: true)
|
||||
}
|
||||
})
|
||||
case .invalid: playPauseIcon("play.fill", Color(uiColor: .tertiaryLabel))
|
||||
}
|
||||
} else {
|
||||
|
@ -255,59 +255,29 @@ struct VoiceMessagePlayer: View {
|
|||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func playbackButton() -> some View {
|
||||
if sizeMultiplier != 1 {
|
||||
switch playbackState {
|
||||
case .noPlayback:
|
||||
playPauseIcon("play.fill", theme.colors.primary)
|
||||
.onTapGesture {
|
||||
if let recordingSource = getLoadedFileSource(recordingFile) {
|
||||
startPlayback(recordingSource)
|
||||
}
|
||||
}
|
||||
case .playing:
|
||||
playPauseIcon("pause.fill", theme.colors.primary)
|
||||
.onTapGesture {
|
||||
audioPlayer?.pause()
|
||||
playbackState = .paused
|
||||
notifyStateChange()
|
||||
}
|
||||
case .paused:
|
||||
playPauseIcon("play.fill", theme.colors.primary)
|
||||
.onTapGesture {
|
||||
audioPlayer?.play()
|
||||
playbackState = .playing
|
||||
notifyStateChange()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch playbackState {
|
||||
case .noPlayback:
|
||||
Button {
|
||||
private func playbackButton() -> some View {
|
||||
let icon = switch playbackState {
|
||||
case .noPlayback: "play.fill"
|
||||
case .playing: "pause.fill"
|
||||
case .paused: "play.fill"
|
||||
}
|
||||
return playPauseIcon(icon, theme.colors.primary)
|
||||
.simultaneousGesture(TapGesture().onEnded { _ in
|
||||
switch playbackState {
|
||||
case .noPlayback:
|
||||
if let recordingSource = getLoadedFileSource(recordingFile) {
|
||||
startPlayback(recordingSource)
|
||||
}
|
||||
} label: {
|
||||
playPauseIcon("play.fill", theme.colors.primary)
|
||||
}
|
||||
case .playing:
|
||||
Button {
|
||||
case .playing:
|
||||
audioPlayer?.pause()
|
||||
playbackState = .paused
|
||||
notifyStateChange()
|
||||
} label: {
|
||||
playPauseIcon("pause.fill", theme.colors.primary)
|
||||
}
|
||||
case .paused:
|
||||
Button {
|
||||
case .paused:
|
||||
audioPlayer?.play()
|
||||
playbackState = .playing
|
||||
notifyStateChange()
|
||||
} label: {
|
||||
playPauseIcon("play.fill", theme.colors.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private func playPauseIcon(_ image: String, _ color: Color/* = .accentColor*/) -> some View {
|
||||
|
@ -329,28 +299,14 @@ struct VoiceMessagePlayer: View {
|
|||
}
|
||||
|
||||
private func downloadButton(_ recordingFile: CIFile, _ icon: String) -> some View {
|
||||
Group {
|
||||
if sizeMultiplier != 1 {
|
||||
playPauseIcon(icon, theme.colors.primary)
|
||||
.onTapGesture {
|
||||
Task {
|
||||
if let user = chatModel.currentUser {
|
||||
await receiveFile(user: user, fileId: recordingFile.fileId)
|
||||
}
|
||||
}
|
||||
playPauseIcon(icon, theme.colors.primary)
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
Task {
|
||||
if let user = chatModel.currentUser {
|
||||
await receiveFile(user: user, fileId: recordingFile.fileId)
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
Task {
|
||||
if let user = chatModel.currentUser {
|
||||
await receiveFile(user: user, fileId: recordingFile.fileId)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
playPauseIcon(icon, theme.colors.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func notifyStateChange() {
|
||||
|
@ -430,6 +386,7 @@ struct VoiceMessagePlayer: View {
|
|||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func voiceMessageSizeBasedOnSquareSize(_ squareSize: CGFloat) -> CGFloat {
|
||||
let squareToCircleRatio = 0.935
|
||||
return squareSize + squareSize * (1 - squareToCircleRatio)
|
||||
|
@ -446,10 +403,12 @@ class VoiceItemState {
|
|||
self.playbackTime = playbackTime
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
static func id(_ chat: Chat, _ chatItem: ChatItem) -> String {
|
||||
"\(chat.id) \(chatItem.id)"
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
static func id(_ chatInfo: ChatInfo, _ chatItem: ChatItem) -> String {
|
||||
"\(chatInfo.id) \(chatItem.id)"
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ struct FramedItemView: View {
|
|||
@State private var useWhiteMetaColor: Bool = false
|
||||
@State var showFullScreenImage = false
|
||||
@Binding var allowMenu: Bool
|
||||
@State private var showSecrets = false
|
||||
@State private var showQuoteSecrets = false
|
||||
@State private var showFullscreenGallery: Bool = false
|
||||
|
||||
var body: some View {
|
||||
|
@ -57,7 +55,7 @@ struct FramedItemView: View {
|
|||
|
||||
if let qi = chatItem.quotedItem {
|
||||
ciQuoteView(qi)
|
||||
.onTapGesture {
|
||||
.simultaneousGesture(TapGesture().onEnded {
|
||||
if let ci = ItemsModel.shared.reversedChatItems.first(where: { $0.id == qi.itemId }) {
|
||||
withAnimation {
|
||||
scrollToItemId(ci.id)
|
||||
|
@ -67,7 +65,7 @@ struct FramedItemView: View {
|
|||
} else {
|
||||
showQuotedItemDoesNotExistAlert()
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if let itemForwarded = chatItem.meta.itemForwarded {
|
||||
framedItemHeader(icon: "arrowshape.turn.up.forward", caption: Text(itemForwarded.text(chat.chatInfo.chatType)).italic(), pad: true)
|
||||
}
|
||||
|
@ -94,14 +92,14 @@ struct FramedItemView: View {
|
|||
.onPreferenceChange(DetermineWidth.Key.self) { msgWidth = $0 }
|
||||
|
||||
if let (title, text) = chatItem.meta.itemStatus.statusInfo {
|
||||
v.onTapGesture {
|
||||
v.simultaneousGesture(TapGesture().onEnded {
|
||||
AlertManager.shared.showAlert(
|
||||
Alert(
|
||||
title: Text(title),
|
||||
message: Text(text)
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
v
|
||||
}
|
||||
|
@ -159,7 +157,7 @@ struct FramedItemView: View {
|
|||
case let .file(text):
|
||||
ciFileView(chatItem, text)
|
||||
case let .report(text, reason):
|
||||
ciMsgContentView(chatItem, Text(text.isEmpty ? reason.text : "\(reason.text): ").italic().foregroundColor(.red))
|
||||
ciMsgContentView(chatItem, txtPrefix: reason.attrString)
|
||||
case let .link(_, preview):
|
||||
CILinkView(linkPreview: preview)
|
||||
ciMsgContentView(chatItem)
|
||||
|
@ -270,14 +268,12 @@ struct FramedItemView: View {
|
|||
.padding(.top, 6)
|
||||
.padding(.horizontal, 12)
|
||||
}
|
||||
|
||||
|
||||
@inline(__always)
|
||||
private func ciQuotedMsgTextView(_ qi: CIQuote, lines: Int) -> some View {
|
||||
toggleSecrets(qi.formattedText, $showQuoteSecrets,
|
||||
MsgContentView(chat: chat, text: qi.text, formattedText: qi.formattedText, showSecrets: showQuoteSecrets)
|
||||
.lineLimit(lines)
|
||||
.font(.subheadline)
|
||||
.padding(.bottom, 6)
|
||||
)
|
||||
MsgContentView(chat: chat, text: qi.text, formattedText: qi.formattedText, textStyle: .subheadline)
|
||||
.lineLimit(lines)
|
||||
.padding(.bottom, 6)
|
||||
}
|
||||
|
||||
private func ciQuoteIconView(_ image: String) -> some View {
|
||||
|
@ -297,21 +293,21 @@ struct FramedItemView: View {
|
|||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func ciMsgContentView(_ ci: ChatItem, _ txtPrefix: Text? = nil) -> some View {
|
||||
@ViewBuilder private func ciMsgContentView(_ ci: ChatItem, txtPrefix: NSAttributedString? = nil) -> some View {
|
||||
let text = ci.meta.isLive ? ci.content.msgContent?.text ?? ci.text : ci.text
|
||||
let rtl = isRightToLeft(text)
|
||||
let ft = text == "" ? [] : ci.formattedText
|
||||
let v = toggleSecrets(ft, $showSecrets, MsgContentView(
|
||||
let v = MsgContentView(
|
||||
chat: chat,
|
||||
text: text,
|
||||
formattedText: ft,
|
||||
textStyle: .body,
|
||||
meta: ci.meta,
|
||||
mentions: ci.mentions,
|
||||
userMemberId: chat.chatInfo.groupInfo?.membership.memberId,
|
||||
rightToLeft: rtl,
|
||||
showSecrets: showSecrets,
|
||||
prefix: txtPrefix
|
||||
))
|
||||
)
|
||||
.multilineTextAlignment(rtl ? .trailing : .leading)
|
||||
.padding(.vertical, 6)
|
||||
.padding(.horizontal, 12)
|
||||
|
@ -351,14 +347,6 @@ struct FramedItemView: View {
|
|||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func toggleSecrets<V: View>(_ ft: [FormattedText]?, _ showSecrets: Binding<Bool>, _ v: V) -> some View {
|
||||
if let ft = ft, ft.contains(where: { $0.isSecret }) {
|
||||
v.onTapGesture { showSecrets.wrappedValue.toggle() }
|
||||
} else {
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
func isRightToLeft(_ s: String) -> Bool {
|
||||
if let lang = CFStringTokenizerCopyBestStringLanguage(s as CFString, CFRange(location: 0, length: min(s.count, 80))) {
|
||||
return NSLocale.characterDirection(forLanguage: lang as String) == .rightToLeft
|
||||
|
|
|
@ -126,7 +126,7 @@ struct FullScreenMediaView: View {
|
|||
.scaledToFit()
|
||||
}
|
||||
}
|
||||
.onTapGesture { showView = false }
|
||||
.onTapGesture { showView = false } // this is used in full screen view, onTapGesture works
|
||||
}
|
||||
|
||||
private func videoView( _ player: AVPlayer, _ url: URL) -> some View {
|
||||
|
|
|
@ -71,7 +71,7 @@ struct CIMsgError: View {
|
|||
.padding(.vertical, 6)
|
||||
.background { chatItemFrameColor(chatItem, theme).modifier(ChatTailPadding()) }
|
||||
.textSelection(.disabled)
|
||||
.onTapGesture(perform: onTap)
|
||||
.simultaneousGesture(TapGesture().onEnded(onTap))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,17 +11,16 @@ import SimpleXChat
|
|||
|
||||
let uiLinkColor = UIColor(red: 0, green: 0.533, blue: 1, alpha: 1)
|
||||
|
||||
private let noTyping = Text(verbatim: " ")
|
||||
|
||||
private let typingIndicators: [Text] = [
|
||||
(typing(.black) + typing() + typing()),
|
||||
(typing(.bold) + typing(.black) + typing()),
|
||||
(typing() + typing(.bold) + typing(.black)),
|
||||
(typing() + typing() + typing(.bold))
|
||||
]
|
||||
|
||||
private func typing(_ w: Font.Weight = .light) -> Text {
|
||||
Text(verbatim: ".").fontWeight(w)
|
||||
private func typing(_ theme: AppTheme, _ descr: UIFontDescriptor, _ ws: [UIFont.Weight]) -> NSMutableAttributedString {
|
||||
let res = NSMutableAttributedString()
|
||||
for w in ws {
|
||||
res.append(NSAttributedString(string: ".", attributes: [
|
||||
.font: UIFont.monospacedSystemFont(ofSize: descr.pointSize, weight: w),
|
||||
.kern: -2 as NSNumber,
|
||||
.foregroundColor: UIColor(theme.colors.secondary)
|
||||
]))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
struct MsgContentView: View {
|
||||
|
@ -30,34 +29,55 @@ struct MsgContentView: View {
|
|||
@EnvironmentObject var theme: AppTheme
|
||||
var text: String
|
||||
var formattedText: [FormattedText]? = nil
|
||||
var textStyle: UIFont.TextStyle
|
||||
var sender: String? = nil
|
||||
var meta: CIMeta? = nil
|
||||
var mentions: [String: CIMention]? = nil
|
||||
var userMemberId: String? = nil
|
||||
var rightToLeft = false
|
||||
var showSecrets: Bool
|
||||
var prefix: Text? = nil
|
||||
var prefix: NSAttributedString? = nil
|
||||
@State private var showSecrets: Set<Int> = []
|
||||
@State private var typingIdx = 0
|
||||
@State private var timer: Timer?
|
||||
@State private var typingIndicators: [NSAttributedString] = []
|
||||
@State private var noTyping = NSAttributedString(string: " ")
|
||||
@State private var phase: CGFloat = 0
|
||||
|
||||
@AppStorage(DEFAULT_SHOW_SENT_VIA_RPOXY) private var showSentViaProxy = false
|
||||
|
||||
var body: some View {
|
||||
let v = msgContentView()
|
||||
if meta?.isLive == true {
|
||||
msgContentView()
|
||||
.onAppear { switchTyping() }
|
||||
v.onAppear {
|
||||
let descr = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
|
||||
noTyping = NSAttributedString(string: " ", attributes: [
|
||||
.font: UIFont.monospacedSystemFont(ofSize: descr.pointSize, weight: .regular),
|
||||
.kern: -2 as NSNumber,
|
||||
.foregroundColor: UIColor(theme.colors.secondary)
|
||||
])
|
||||
switchTyping()
|
||||
}
|
||||
.onDisappear(perform: stopTyping)
|
||||
.onChange(of: meta?.isLive, perform: switchTyping)
|
||||
.onChange(of: meta?.recent, perform: switchTyping)
|
||||
} else {
|
||||
msgContentView()
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
private func switchTyping(_: Bool? = nil) {
|
||||
if let meta = meta, meta.isLive && meta.recent {
|
||||
if typingIndicators.isEmpty {
|
||||
let descr = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
|
||||
typingIndicators = [
|
||||
typing(theme, descr, [.black, .light, .light]),
|
||||
typing(theme, descr, [.bold, .black, .light]),
|
||||
typing(theme, descr, [.light, .bold, .black]),
|
||||
typing(theme, descr, [.light, .light, .bold])
|
||||
]
|
||||
}
|
||||
timer = timer ?? Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { _ in
|
||||
typingIdx = (typingIdx + 1) % typingIndicators.count
|
||||
typingIdx = typingIdx + 1
|
||||
}
|
||||
} else {
|
||||
stopTyping()
|
||||
|
@ -67,119 +87,221 @@ struct MsgContentView: View {
|
|||
private func stopTyping() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
typingIdx = 0
|
||||
}
|
||||
|
||||
private func msgContentView() -> Text {
|
||||
var v = messageText(text, formattedText, sender, mentions: mentions, userMemberId: userMemberId, showSecrets: showSecrets, secondaryColor: theme.colors.secondary, prefix: prefix)
|
||||
@inline(__always)
|
||||
private func msgContentView() -> some View {
|
||||
let s = messageText(text, formattedText, textStyle: textStyle, sender: sender, mentions: mentions, userMemberId: userMemberId, showSecrets: showSecrets, secondaryColor: theme.colors.secondary, prefix: prefix)
|
||||
let t: Text
|
||||
if let mt = meta {
|
||||
if mt.isLive {
|
||||
v = v + typingIndicator(mt.recent)
|
||||
s.append(typingIndicator(mt.recent))
|
||||
}
|
||||
v = v + reserveSpaceForMeta(mt)
|
||||
t = Text(AttributedString(s)) + reserveSpaceForMeta(mt)
|
||||
} else {
|
||||
t = Text(AttributedString(s))
|
||||
}
|
||||
return v
|
||||
return t.overlay(handleTextLinks(s, showSecrets: $showSecrets))
|
||||
}
|
||||
|
||||
private func typingIndicator(_ recent: Bool) -> Text {
|
||||
return (recent ? typingIndicators[typingIdx] : noTyping)
|
||||
.font(.body.monospaced())
|
||||
.kerning(-2)
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
@inline(__always)
|
||||
private func typingIndicator(_ recent: Bool) -> NSAttributedString {
|
||||
recent && !typingIndicators.isEmpty
|
||||
? typingIndicators[typingIdx % 4]
|
||||
: noTyping
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
private func reserveSpaceForMeta(_ mt: CIMeta) -> Text {
|
||||
(rightToLeft ? textNewLine : Text(verbatim: " ")) + ciMetaText(mt, chatTTL: chat.chatInfo.timedMessagesTTL, encrypted: nil, colorMode: .transparent, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
|
||||
}
|
||||
}
|
||||
|
||||
func messageText(_ text: String, _ formattedText: [FormattedText]?, _ sender: String?, icon: String? = nil, preview: Bool = false, mentions: [String: CIMention]?, userMemberId: String?, showSecrets: Bool, secondaryColor: Color, prefix: Text? = nil) -> Text {
|
||||
let s = text
|
||||
var res: Text
|
||||
|
||||
if let ft = formattedText, ft.count > 0 && ft.count <= 200 {
|
||||
res = formatText(ft[0], preview, showSecret: showSecrets, mentions: mentions, userMemberId: userMemberId)
|
||||
var i = 1
|
||||
while i < ft.count {
|
||||
res = res + formatText(ft[i], preview, showSecret: showSecrets, mentions: mentions, userMemberId: userMemberId)
|
||||
i = i + 1
|
||||
}
|
||||
} else {
|
||||
res = Text(s)
|
||||
}
|
||||
|
||||
if let i = icon {
|
||||
res = Text(Image(systemName: i)).foregroundColor(secondaryColor) + textSpace + res
|
||||
}
|
||||
|
||||
if let p = prefix {
|
||||
res = p + res
|
||||
}
|
||||
|
||||
if let s = sender {
|
||||
let t = Text(s)
|
||||
return (preview ? t : t.fontWeight(.medium)) + Text(verbatim: ": ") + res
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
private func formatText(_ ft: FormattedText, _ preview: Bool, showSecret: Bool, mentions: [String: CIMention]?, userMemberId: String?) -> Text {
|
||||
let t = ft.text
|
||||
if let f = ft.format {
|
||||
switch (f) {
|
||||
case .bold: return Text(t).bold()
|
||||
case .italic: return Text(t).italic()
|
||||
case .strikeThrough: return Text(t).strikethrough()
|
||||
case .snippet: return Text(t).font(.body.monospaced())
|
||||
case .secret: return
|
||||
showSecret
|
||||
? Text(t)
|
||||
: Text(AttributedString(t, attributes: AttributeContainer([
|
||||
.foregroundColor: UIColor.clear as Any,
|
||||
.backgroundColor: UIColor.secondarySystemFill as Any
|
||||
])))
|
||||
case let .colored(color): return Text(t).foregroundColor(color.uiColor)
|
||||
case .uri: return linkText(t, t, preview, prefix: "")
|
||||
case let .simplexLink(linkType, simplexUri, smpHosts):
|
||||
switch privacySimplexLinkModeDefault.get() {
|
||||
case .description: return linkText(simplexLinkText(linkType, smpHosts), simplexUri, preview, prefix: "")
|
||||
case .full: return linkText(t, simplexUri, preview, prefix: "")
|
||||
case .browser: return linkText(t, simplexUri, preview, prefix: "")
|
||||
}
|
||||
case let .mention(memberName):
|
||||
if let m = mentions?[memberName] {
|
||||
if let ref = m.memberRef {
|
||||
let name: String = if let alias = ref.localAlias, alias != "" {
|
||||
"\(alias) (\(ref.displayName))"
|
||||
} else {
|
||||
ref.displayName
|
||||
func handleTextLinks(_ s: NSAttributedString, showSecrets: Binding<Set<Int>>? = nil) -> some View {
|
||||
return GeometryReader { g in
|
||||
Rectangle()
|
||||
.fill(Color.clear)
|
||||
.contentShape(Rectangle())
|
||||
.simultaneousGesture(DragGesture(minimumDistance: 0).onEnded { event in
|
||||
let t = event.translation
|
||||
if t.width * t.width + t.height * t.height > 100 { return }
|
||||
let framesetter = CTFramesetterCreateWithAttributedString(s as CFAttributedString)
|
||||
let path = CGPath(rect: CGRect(origin: .zero, size: g.size), transform: nil)
|
||||
let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, s.length), path, nil)
|
||||
let point = CGPoint(x: event.location.x, y: g.size.height - event.location.y) // Flip y for UIKit
|
||||
var index: CFIndex?
|
||||
if let lines = CTFrameGetLines(frame) as? [CTLine] {
|
||||
var origins = [CGPoint](repeating: .zero, count: lines.count)
|
||||
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), &origins)
|
||||
for i in 0 ..< lines.count {
|
||||
let bounds = CTLineGetBoundsWithOptions(lines[i], .useOpticalBounds)
|
||||
if bounds.offsetBy(dx: origins[i].x, dy: origins[i].y).contains(point) {
|
||||
index = CTLineGetStringIndexForPosition(lines[i], point)
|
||||
break
|
||||
}
|
||||
}
|
||||
let tName = mentionText(name)
|
||||
return m.memberId == userMemberId ? tName.foregroundColor(.accentColor) : tName
|
||||
} else {
|
||||
return mentionText(memberName)
|
||||
}
|
||||
if let index, let (url, browser) = attributedStringLink(s, for: index) {
|
||||
if browser {
|
||||
openBrowserAlert(uri: url)
|
||||
} else {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func attributedStringLink(_ s: NSAttributedString, for index: CFIndex) -> (URL, Bool)? {
|
||||
var linkURL: URL?
|
||||
var browser: Bool = false
|
||||
s.enumerateAttributes(in: NSRange(location: 0, length: s.length)) { attrs, range, stop in
|
||||
if index >= range.location && index < range.location + range.length {
|
||||
if let url = attrs[linkAttrKey] as? NSURL {
|
||||
linkURL = url.absoluteURL
|
||||
browser = attrs[webLinkAttrKey] != nil
|
||||
} else if let showSecrets, let i = attrs[secretAttrKey] as? Int {
|
||||
if showSecrets.wrappedValue.contains(i) {
|
||||
showSecrets.wrappedValue.remove(i)
|
||||
} else {
|
||||
showSecrets.wrappedValue.insert(i)
|
||||
}
|
||||
}
|
||||
stop.pointee = true
|
||||
}
|
||||
return Text(t)
|
||||
case .email: return linkText(t, t, preview, prefix: "mailto:")
|
||||
case .phone: return linkText(t, t.replacingOccurrences(of: " ", with: ""), preview, prefix: "tel:")
|
||||
}
|
||||
} else {
|
||||
return Text(t)
|
||||
return if let linkURL { (linkURL, browser) } else { nil }
|
||||
}
|
||||
}
|
||||
|
||||
private func mentionText(_ name: String) -> Text {
|
||||
Text(verbatim: name.contains(" @") ? "@'\(name)'" : "@\(name)").fontWeight(.semibold)
|
||||
}
|
||||
private let linkAttrKey = NSAttributedString.Key("chat.simplex.app.link")
|
||||
|
||||
private func linkText(_ s: String, _ link: String, _ preview: Bool, prefix: String, color: Color = Color(uiColor: uiLinkColor), uiColor: UIColor = uiLinkColor) -> Text {
|
||||
preview
|
||||
? Text(s).foregroundColor(color).underline(color: color)
|
||||
: Text(AttributedString(s, attributes: AttributeContainer([
|
||||
.link: NSURL(string: prefix + link) as Any,
|
||||
.foregroundColor: uiColor as Any
|
||||
]))).underline()
|
||||
private let webLinkAttrKey = NSAttributedString.Key("chat.simplex.app.webLink")
|
||||
|
||||
private let secretAttrKey = NSAttributedString.Key("chat.simplex.app.secret")
|
||||
|
||||
func messageText(_ text: String, _ formattedText: [FormattedText]?, textStyle: UIFont.TextStyle = .body, sender: String?, preview: Bool = false, mentions: [String: CIMention]?, userMemberId: String?, showSecrets: Set<Int>?, secondaryColor: Color, prefix: NSAttributedString? = nil) -> NSMutableAttributedString {
|
||||
let res = NSMutableAttributedString()
|
||||
let descr = UIFontDescriptor.preferredFontDescriptor(withTextStyle: textStyle)
|
||||
let font = UIFont.preferredFont(forTextStyle: textStyle)
|
||||
let plain: [NSAttributedString.Key: Any] = [
|
||||
.font: font,
|
||||
.foregroundColor: UIColor.label
|
||||
]
|
||||
var link: [NSAttributedString.Key: Any]?
|
||||
|
||||
if let sender {
|
||||
if preview {
|
||||
res.append(NSAttributedString(string: sender + ": ", attributes: plain))
|
||||
} else {
|
||||
var attrs = plain
|
||||
attrs[.font] = UIFont(descriptor: descr.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.medium]]), size: descr.pointSize)
|
||||
res.append(NSAttributedString(string: sender, attributes: attrs))
|
||||
res.append(NSAttributedString(string: ": ", attributes: plain))
|
||||
}
|
||||
}
|
||||
|
||||
if let prefix {
|
||||
res.append(prefix)
|
||||
}
|
||||
|
||||
if let fts = formattedText, fts.count > 0 {
|
||||
var bold: UIFont?
|
||||
var italic: UIFont?
|
||||
var snippet: UIFont?
|
||||
var mention: UIFont?
|
||||
var secretIdx: Int = 0
|
||||
for ft in fts {
|
||||
var t = ft.text
|
||||
var attrs = plain
|
||||
switch (ft.format) {
|
||||
case .bold:
|
||||
bold = bold ?? UIFont(descriptor: descr.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.bold]]), size: descr.pointSize)
|
||||
attrs[.font] = bold
|
||||
case .italic:
|
||||
italic = italic ?? UIFont(descriptor: descr.withSymbolicTraits(.traitItalic) ?? descr, size: descr.pointSize)
|
||||
attrs[.font] = italic
|
||||
case .strikeThrough:
|
||||
attrs[.strikethroughStyle] = NSUnderlineStyle.single.rawValue
|
||||
case .snippet:
|
||||
snippet = snippet ?? UIFont.monospacedSystemFont(ofSize: descr.pointSize, weight: .regular)
|
||||
attrs[.font] = snippet
|
||||
case .secret:
|
||||
if let showSecrets {
|
||||
if !showSecrets.contains(secretIdx) {
|
||||
attrs[.foregroundColor] = UIColor.clear
|
||||
attrs[.backgroundColor] = UIColor.secondarySystemFill // secretColor
|
||||
}
|
||||
attrs[secretAttrKey] = secretIdx
|
||||
secretIdx += 1
|
||||
} else {
|
||||
attrs[.foregroundColor] = UIColor.clear
|
||||
attrs[.backgroundColor] = UIColor.secondarySystemFill
|
||||
}
|
||||
case let .colored(color):
|
||||
if let c = color.uiColor {
|
||||
attrs[.foregroundColor] = UIColor(c)
|
||||
}
|
||||
case .uri:
|
||||
attrs = linkAttrs()
|
||||
if !preview {
|
||||
attrs[linkAttrKey] = NSURL(string: ft.text)
|
||||
attrs[webLinkAttrKey] = true
|
||||
}
|
||||
case let .simplexLink(linkType, simplexUri, smpHosts):
|
||||
attrs = linkAttrs()
|
||||
if !preview {
|
||||
attrs[linkAttrKey] = NSURL(string: simplexUri)
|
||||
}
|
||||
if case .description = privacySimplexLinkModeDefault.get() {
|
||||
t = simplexLinkText(linkType, smpHosts)
|
||||
}
|
||||
case let .mention(memberName):
|
||||
if let m = mentions?[memberName] {
|
||||
mention = mention ?? UIFont(descriptor: descr.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]]), size: descr.pointSize)
|
||||
attrs[.font] = mention
|
||||
if let ref = m.memberRef {
|
||||
let name: String = if let alias = ref.localAlias, alias != "" {
|
||||
"\(alias) (\(ref.displayName))"
|
||||
} else {
|
||||
ref.displayName
|
||||
}
|
||||
if m.memberId == userMemberId {
|
||||
attrs[.foregroundColor] = UIColor.tintColor
|
||||
}
|
||||
t = "@'\(name)'"
|
||||
} else {
|
||||
t = "@'\(memberName)'"
|
||||
}
|
||||
}
|
||||
case .email:
|
||||
attrs = linkAttrs()
|
||||
if !preview {
|
||||
attrs[linkAttrKey] = NSURL(string: "mailto:" + ft.text)
|
||||
}
|
||||
case .phone:
|
||||
attrs = linkAttrs()
|
||||
if !preview {
|
||||
attrs[linkAttrKey] = NSURL(string: "tel:" + t.replacingOccurrences(of: " ", with: ""))
|
||||
}
|
||||
case .none: ()
|
||||
}
|
||||
res.append(NSAttributedString(string: t, attributes: attrs))
|
||||
}
|
||||
} else {
|
||||
res.append(NSMutableAttributedString(string: text, attributes: plain))
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
func linkAttrs() -> [NSAttributedString.Key: Any] {
|
||||
link = link ?? [
|
||||
.font: font,
|
||||
.foregroundColor: uiLinkColor,
|
||||
.underlineStyle: NSUnderlineStyle.single.rawValue
|
||||
]
|
||||
return link!
|
||||
}
|
||||
}
|
||||
|
||||
func simplexLinkText(_ linkType: SimplexLinkType, _ smpHosts: [String]) -> String {
|
||||
|
@ -193,9 +315,9 @@ struct MsgContentView_Previews: PreviewProvider {
|
|||
chat: Chat.sampleData,
|
||||
text: chatItem.text,
|
||||
formattedText: chatItem.formattedText,
|
||||
textStyle: .body,
|
||||
sender: chatItem.memberDisplayName,
|
||||
meta: chatItem.meta,
|
||||
showSecrets: false
|
||||
meta: chatItem.meta
|
||||
)
|
||||
.environmentObject(Chat.sampleData)
|
||||
}
|
||||
|
|
|
@ -274,10 +274,11 @@ struct ChatItemInfoView: View {
|
|||
var sender: String? = nil
|
||||
var mentions: [String: CIMention]?
|
||||
var userMemberId: String?
|
||||
@State private var showSecrets = false
|
||||
@State private var showSecrets: Set<Int> = []
|
||||
|
||||
var body: some View {
|
||||
toggleSecrets(formattedText, $showSecrets, messageText(text, formattedText, sender, mentions: mentions, userMemberId: userMemberId, showSecrets: showSecrets, secondaryColor: theme.colors.secondary))
|
||||
let s = messageText(text, formattedText, sender: sender, mentions: mentions, userMemberId: userMemberId, showSecrets: showSecrets, secondaryColor: theme.colors.secondary)
|
||||
Text(AttributedString(s)).overlay(handleTextLinks(s, showSecrets: $showSecrets))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ struct ContextItemView: View {
|
|||
}
|
||||
|
||||
private func contextMsgPreview(_ contextItem: ChatItem) -> Text {
|
||||
return attachment() + messageText(contextItem.text, contextItem.formattedText, nil, preview: true, mentions: contextItem.mentions, userMemberId: nil, showSecrets: false, secondaryColor: theme.colors.secondary)
|
||||
return attachment() + Text(AttributedString(messageText(contextItem.text, contextItem.formattedText, sender: nil, preview: true, mentions: contextItem.mentions, userMemberId: nil, showSecrets: nil, secondaryColor: theme.colors.secondary)))
|
||||
|
||||
func attachment() -> Text {
|
||||
let isFileLoaded = if let fileSource = getLoadedFileSource(contextItem.file) {
|
||||
|
|
|
@ -263,13 +263,12 @@ struct SendMessageView: View {
|
|||
@State private var pressed: TimeInterval? = nil
|
||||
|
||||
var body: some View {
|
||||
Button(action: {}) {
|
||||
Image(systemName: "mic.fill")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundColor(theme.colors.primary)
|
||||
}
|
||||
Image(systemName: "mic.fill")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundColor(theme.colors.primary)
|
||||
.opacity(holdingVMR ? 0.7 : 1)
|
||||
.disabled(disabled)
|
||||
.frame(width: 31, height: 31)
|
||||
.padding([.bottom, .trailing], 4)
|
||||
|
@ -279,9 +278,7 @@ struct SendMessageView: View {
|
|||
pressed = ProcessInfo.processInfo.systemUptime
|
||||
startVoiceMessageRecording?()
|
||||
} else {
|
||||
let now = ProcessInfo.processInfo.systemUptime
|
||||
if let pressed = pressed,
|
||||
now - pressed >= 1 {
|
||||
if let pressed, ProcessInfo.processInfo.systemUptime - pressed >= 1 {
|
||||
finishVoiceMessageRecording?()
|
||||
}
|
||||
holdingVMR = false
|
||||
|
|
|
@ -58,7 +58,9 @@ struct GroupWelcomeView: View {
|
|||
}
|
||||
|
||||
private func textPreview() -> some View {
|
||||
messageText(welcomeText, parseSimpleXMarkdown(welcomeText), nil, mentions: nil, userMemberId: nil, showSecrets: false, secondaryColor: theme.colors.secondary)
|
||||
let s = messageText(welcomeText, parseSimpleXMarkdown(welcomeText), sender: nil, mentions: nil, userMemberId: nil, showSecrets: nil, secondaryColor: theme.colors.secondary)
|
||||
return Text(AttributedString(s))
|
||||
.overlay(handleTextLinks(s))
|
||||
.frame(minHeight: 130, alignment: .topLeading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ struct ChatPreviewView: View {
|
|||
let msg = draft.message
|
||||
return image("rectangle.and.pencil.and.ellipsis", color: theme.colors.primary)
|
||||
+ attachment()
|
||||
+ messageText(msg, parseSimpleXMarkdown(msg), nil, preview: true, mentions: draft.mentions, userMemberId: nil, showSecrets: false, secondaryColor: theme.colors.secondary)
|
||||
+ Text(AttributedString(messageText(msg, parseSimpleXMarkdown(msg), sender: nil, preview: true, mentions: draft.mentions, userMemberId: nil, showSecrets: nil, secondaryColor: theme.colors.secondary)))
|
||||
|
||||
func image(_ s: String, color: Color = Color(uiColor: .tertiaryLabel)) -> Text {
|
||||
Text(Image(systemName: s)).foregroundColor(color) + textSpace
|
||||
|
@ -282,7 +282,7 @@ struct ChatPreviewView: View {
|
|||
func chatItemPreview(_ cItem: ChatItem) -> Text {
|
||||
let itemText = cItem.meta.itemDeleted == nil ? cItem.text : markedDeletedText()
|
||||
let itemFormattedText = cItem.meta.itemDeleted == nil ? cItem.formattedText : nil
|
||||
return messageText(itemText, itemFormattedText, cItem.memberDisplayName, icon: nil, preview: true, mentions: cItem.mentions, userMemberId: chat.chatInfo.groupInfo?.membership.memberId, showSecrets: false, secondaryColor: theme.colors.secondary, prefix: prefix())
|
||||
return Text(AttributedString(messageText(itemText, itemFormattedText, sender: cItem.memberDisplayName, preview: true, mentions: cItem.mentions, userMemberId: chat.chatInfo.groupInfo?.membership.memberId, showSecrets: nil, secondaryColor: theme.colors.secondary, prefix: prefix())))
|
||||
|
||||
// same texts are in markedDeletedText in MarkedDeletedItemView, but it returns LocalizedStringKey;
|
||||
// can be refactored into a single function if functions calling these are changed to return same type
|
||||
|
@ -309,10 +309,10 @@ struct ChatPreviewView: View {
|
|||
}
|
||||
}
|
||||
|
||||
func prefix() -> Text {
|
||||
func prefix() -> NSAttributedString? {
|
||||
switch cItem.content.msgContent {
|
||||
case let .report(_, reason): return Text(!itemText.isEmpty ? "\(reason.text): " : reason.text).italic().foregroundColor(Color.red)
|
||||
default: return Text("")
|
||||
case let .report(_, reason): reason.attrString
|
||||
default: nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +348,6 @@ struct ChatPreviewView: View {
|
|||
}
|
||||
|
||||
@ViewBuilder func chatItemContentPreview(_ chat: Chat, _ ci: ChatItem) -> some View {
|
||||
let linkClicksEnabled = privacyChatListOpenLinksDefault.get() != PrivacyChatListOpenLinksMode.no
|
||||
let mc = ci.content.msgContent
|
||||
switch mc {
|
||||
case let .link(_, preview):
|
||||
|
@ -370,17 +369,7 @@ struct ChatPreviewView: View {
|
|||
.cornerRadius(8)
|
||||
}
|
||||
.onTapGesture {
|
||||
switch privacyChatListOpenLinksDefault.get() {
|
||||
case .yes: UIApplication.shared.open(preview.uri)
|
||||
case .no: ItemsModel.shared.loadOpenChat(chat.id)
|
||||
case .ask: AlertManager.shared.showAlert(
|
||||
Alert(title: Text("Open web link?"),
|
||||
message: Text(preview.uri.absoluteString),
|
||||
primaryButton: .default(Text("Open chat"), action: { ItemsModel.shared.loadOpenChat(chat.id) }),
|
||||
secondaryButton: .default(Text("Open link"), action: { UIApplication.shared.open(preview.uri) })
|
||||
)
|
||||
)
|
||||
}
|
||||
openBrowserAlert(uri: preview.uri)
|
||||
}
|
||||
}
|
||||
case let .image(_, image):
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import SwiftUI
|
||||
|
||||
extension View {
|
||||
@inline(__always)
|
||||
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
|
||||
if condition {
|
||||
transform(self)
|
||||
|
|
|
@ -38,7 +38,6 @@ extension AppSettings {
|
|||
privacyLinkPreviewsGroupDefault.set(val)
|
||||
def.setValue(val, forKey: DEFAULT_PRIVACY_LINK_PREVIEWS)
|
||||
}
|
||||
if let val = privacyChatListOpenLinks { privacyChatListOpenLinksDefault.set(val) }
|
||||
if let val = privacyShowChatPreviews { def.setValue(val, forKey: DEFAULT_PRIVACY_SHOW_CHAT_PREVIEWS) }
|
||||
if let val = privacySaveLastDraft { def.setValue(val, forKey: DEFAULT_PRIVACY_SAVE_LAST_DRAFT) }
|
||||
if let val = privacyProtectScreen { def.setValue(val, forKey: DEFAULT_PRIVACY_PROTECT_SCREEN) }
|
||||
|
@ -78,7 +77,6 @@ extension AppSettings {
|
|||
c.privacyAskToApproveRelays = privacyAskToApproveRelaysGroupDefault.get()
|
||||
c.privacyAcceptImages = privacyAcceptImagesGroupDefault.get()
|
||||
c.privacyLinkPreviews = def.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS)
|
||||
c.privacyChatListOpenLinks = privacyChatListOpenLinksDefault.get()
|
||||
c.privacyShowChatPreviews = def.bool(forKey: DEFAULT_PRIVACY_SHOW_CHAT_PREVIEWS)
|
||||
c.privacySaveLastDraft = def.bool(forKey: DEFAULT_PRIVACY_SAVE_LAST_DRAFT)
|
||||
c.privacyProtectScreen = def.bool(forKey: DEFAULT_PRIVACY_PROTECT_SCREEN)
|
||||
|
|
|
@ -14,7 +14,6 @@ struct PrivacySettings: View {
|
|||
@EnvironmentObject var theme: AppTheme
|
||||
@AppStorage(DEFAULT_PRIVACY_ACCEPT_IMAGES) private var autoAcceptImages = true
|
||||
@AppStorage(DEFAULT_PRIVACY_LINK_PREVIEWS) private var useLinkPreviews = true
|
||||
@State private var chatListOpenLinks = privacyChatListOpenLinksDefault.get()
|
||||
@AppStorage(DEFAULT_PRIVACY_SHOW_CHAT_PREVIEWS) private var showChatPreviews = true
|
||||
@AppStorage(DEFAULT_PRIVACY_SAVE_LAST_DRAFT) private var saveLastDraft = true
|
||||
@AppStorage(GROUP_DEFAULT_PRIVACY_ENCRYPT_LOCAL_FILES, store: groupDefaults) private var encryptLocalFiles = true
|
||||
|
@ -77,17 +76,6 @@ struct PrivacySettings: View {
|
|||
privacyLinkPreviewsGroupDefault.set(linkPreviews)
|
||||
}
|
||||
}
|
||||
settingsRow("arrow.up.right.circle", color: theme.colors.secondary) {
|
||||
Picker("Open links from chat list", selection: $chatListOpenLinks) {
|
||||
ForEach(PrivacyChatListOpenLinksMode.allCases) { mode in
|
||||
Text(mode.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 36)
|
||||
.onChange(of: chatListOpenLinks) { mode in
|
||||
privacyChatListOpenLinksDefault.set(mode)
|
||||
}
|
||||
settingsRow("message", color: theme.colors.secondary) {
|
||||
Toggle("Show last messages", isOn: $showChatPreviews)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ let DEFAULT_WEBRTC_ICE_SERVERS = "webrtcICEServers"
|
|||
let DEFAULT_CALL_KIT_CALLS_IN_RECENTS = "callKitCallsInRecents"
|
||||
let DEFAULT_PRIVACY_ACCEPT_IMAGES = "privacyAcceptImages" // unused. Use GROUP_DEFAULT_PRIVACY_ACCEPT_IMAGES instead
|
||||
let DEFAULT_PRIVACY_LINK_PREVIEWS = "privacyLinkPreviews" // deprecated, moved to app group
|
||||
let DEFAULT_PRIVACY_CHAT_LIST_OPEN_LINKS = "privacyChatListOpenLinks"
|
||||
let DEFAULT_PRIVACY_SIMPLEX_LINK_MODE = "privacySimplexLinkMode"
|
||||
let DEFAULT_PRIVACY_SHOW_CHAT_PREVIEWS = "privacyShowChatPreviews"
|
||||
let DEFAULT_PRIVACY_SAVE_LAST_DRAFT = "privacySaveLastDraft"
|
||||
|
@ -185,8 +184,6 @@ let connectViaLinkTabDefault = EnumDefault<ConnectViaLinkTab>(defaults: UserDefa
|
|||
|
||||
let privacySimplexLinkModeDefault = EnumDefault<SimpleXLinkMode>(defaults: UserDefaults.standard, forKey: DEFAULT_PRIVACY_SIMPLEX_LINK_MODE, withDefault: .description)
|
||||
|
||||
let privacyChatListOpenLinksDefault = EnumDefault<PrivacyChatListOpenLinksMode>(defaults: UserDefaults.standard, forKey: DEFAULT_PRIVACY_CHAT_LIST_OPEN_LINKS, withDefault: PrivacyChatListOpenLinksMode.ask)
|
||||
|
||||
let privacyLocalAuthModeDefault = EnumDefault<LAMode>(defaults: UserDefaults.standard, forKey: DEFAULT_LA_MODE, withDefault: .system)
|
||||
|
||||
let privacyDeliveryReceiptsSet = BoolDefault(defaults: UserDefaults.standard, forKey: DEFAULT_PRIVACY_DELIVERY_RECEIPTS_SET)
|
||||
|
|
|
@ -4137,18 +4137,16 @@ public enum FormatColor: String, Decodable, Hashable {
|
|||
case black = "black"
|
||||
case white = "white"
|
||||
|
||||
public var uiColor: Color {
|
||||
get {
|
||||
switch (self) {
|
||||
case .red: return .red
|
||||
case .green: return .green
|
||||
case .blue: return .blue
|
||||
case .yellow: return .yellow
|
||||
case .cyan: return .cyan
|
||||
case .magenta: return .purple
|
||||
case .black: return .primary
|
||||
case .white: return .primary
|
||||
}
|
||||
public var uiColor: Color? {
|
||||
switch (self) {
|
||||
case .red: .red
|
||||
case .green: .green
|
||||
case .blue: .blue
|
||||
case .yellow: .yellow
|
||||
case .cyan: .cyan
|
||||
case .magenta: .purple
|
||||
case .black: nil
|
||||
case .white: nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4173,6 +4171,14 @@ public enum ReportReason: Hashable {
|
|||
case let .unknown(type): return type
|
||||
}
|
||||
}
|
||||
|
||||
public var attrString: NSAttributedString {
|
||||
let descr = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
|
||||
return NSAttributedString(string: text.isEmpty ? self.text : "\(self.text): ", attributes: [
|
||||
.font: UIFont(descriptor: descr.withSymbolicTraits(.traitItalic) ?? descr, size: 0),
|
||||
.foregroundColor: UIColor(Color.red)
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
extension ReportReason: Encodable {
|
||||
|
|
|
@ -25,8 +25,6 @@ data NotificationPreviewMode = NPMHidden | NPMContact | NPMMessage deriving (Sho
|
|||
|
||||
data LockScreenCalls = LSCDisable | LSCShow | LSCAccept deriving (Show)
|
||||
|
||||
data OpenLinksSetting = OLSYes | OLSNo | OLSAsk deriving (Show)
|
||||
|
||||
data AppSettings = AppSettings
|
||||
{ appPlatform :: Maybe AppPlatform,
|
||||
networkConfig :: Maybe NetworkConfig,
|
||||
|
@ -35,7 +33,6 @@ data AppSettings = AppSettings
|
|||
privacyAskToApproveRelays :: Maybe Bool,
|
||||
privacyAcceptImages :: Maybe Bool,
|
||||
privacyLinkPreviews :: Maybe Bool,
|
||||
privacyChatListOpenLinks :: Maybe OpenLinksSetting,
|
||||
privacyShowChatPreviews :: Maybe Bool,
|
||||
privacySaveLastDraft :: Maybe Bool,
|
||||
privacyProtectScreen :: Maybe Bool,
|
||||
|
@ -86,7 +83,6 @@ defaultAppSettings =
|
|||
privacyAskToApproveRelays = Just True,
|
||||
privacyAcceptImages = Just True,
|
||||
privacyLinkPreviews = Just True,
|
||||
privacyChatListOpenLinks = Just OLSAsk,
|
||||
privacyShowChatPreviews = Just True,
|
||||
privacySaveLastDraft = Just True,
|
||||
privacyProtectScreen = Just False,
|
||||
|
@ -124,7 +120,6 @@ defaultParseAppSettings =
|
|||
privacyAskToApproveRelays = Nothing,
|
||||
privacyAcceptImages = Nothing,
|
||||
privacyLinkPreviews = Nothing,
|
||||
privacyChatListOpenLinks = Nothing,
|
||||
privacyShowChatPreviews = Nothing,
|
||||
privacySaveLastDraft = Nothing,
|
||||
privacyProtectScreen = Nothing,
|
||||
|
@ -162,7 +157,6 @@ combineAppSettings platformDefaults storedSettings =
|
|||
privacyAskToApproveRelays = p privacyAskToApproveRelays,
|
||||
privacyAcceptImages = p privacyAcceptImages,
|
||||
privacyLinkPreviews = p privacyLinkPreviews,
|
||||
privacyChatListOpenLinks = p privacyChatListOpenLinks,
|
||||
privacyShowChatPreviews = p privacyShowChatPreviews,
|
||||
privacySaveLastDraft = p privacySaveLastDraft,
|
||||
privacyProtectScreen = p privacyProtectScreen,
|
||||
|
@ -203,8 +197,6 @@ $(JQ.deriveJSON (enumJSON $ dropPrefix "LSC") ''LockScreenCalls)
|
|||
|
||||
$(JQ.deriveJSON (enumJSON $ dropPrefix "NPA") ''NetworkProxyAuth)
|
||||
|
||||
$(JQ.deriveJSON (enumJSON $ dropPrefix "OLS") ''OpenLinksSetting)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''NetworkProxy)
|
||||
|
||||
$(JQ.deriveToJSON defaultJSON ''AppSettings)
|
||||
|
@ -218,7 +210,6 @@ instance FromJSON AppSettings where
|
|||
privacyAskToApproveRelays <- p "privacyAskToApproveRelays"
|
||||
privacyAcceptImages <- p "privacyAcceptImages"
|
||||
privacyLinkPreviews <- p "privacyLinkPreviews"
|
||||
privacyChatListOpenLinks <- p "privacyChatListOpenLinks"
|
||||
privacyShowChatPreviews <- p "privacyShowChatPreviews"
|
||||
privacySaveLastDraft <- p "privacySaveLastDraft"
|
||||
privacyProtectScreen <- p "privacyProtectScreen"
|
||||
|
@ -253,7 +244,6 @@ instance FromJSON AppSettings where
|
|||
privacyAskToApproveRelays,
|
||||
privacyAcceptImages,
|
||||
privacyLinkPreviews,
|
||||
privacyChatListOpenLinks,
|
||||
privacyShowChatPreviews,
|
||||
privacySaveLastDraft,
|
||||
privacyProtectScreen,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue