2022-03-17 09:42:59 +00:00
|
|
|
//
|
|
|
|
// MsgContentView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by Evgeny on 13/03/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-05-31 07:55:13 +01:00
|
|
|
import SimpleXChat
|
2022-03-17 09:42:59 +00:00
|
|
|
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
let uiLinkColor = UIColor(red: 0, green: 0.533, blue: 1, alpha: 1)
|
2022-03-17 09:42:59 +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
2025-05-10 14:37:45 +01:00
|
|
|
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
|
2022-12-17 14:02:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 09:42:59 +00:00
|
|
|
struct MsgContentView: View {
|
2023-10-31 09:44:57 +00:00
|
|
|
@ObservedObject var chat: Chat
|
2024-08-25 21:21:24 +03:00
|
|
|
@Environment(\.showTimestamp) var showTimestamp: Bool
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2022-05-13 12:57:30 +04:00
|
|
|
var text: String
|
2022-03-17 09:42:59 +00:00
|
|
|
var formattedText: [FormattedText]? = nil
|
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
2025-05-10 14:37:45 +01:00
|
|
|
var textStyle: UIFont.TextStyle
|
2022-03-17 09:42:59 +00:00
|
|
|
var sender: String? = nil
|
2022-12-17 14:02:07 +00:00
|
|
|
var meta: CIMeta? = nil
|
2025-02-03 20:47:32 +00:00
|
|
|
var mentions: [String: CIMention]? = nil
|
|
|
|
var userMemberId: String? = nil
|
2022-09-24 19:26:55 +01:00
|
|
|
var rightToLeft = false
|
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
2025-05-10 14:37:45 +01:00
|
|
|
var prefix: NSAttributedString? = nil
|
|
|
|
@State private var showSecrets: Set<Int> = []
|
2022-12-17 14:02:07 +00:00
|
|
|
@State private var typingIdx = 0
|
|
|
|
@State private var timer: Timer?
|
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
2025-05-10 14:37:45 +01:00
|
|
|
@State private var typingIndicators: [NSAttributedString] = []
|
|
|
|
@State private var noTyping = NSAttributedString(string: " ")
|
|
|
|
@State private var phase: CGFloat = 0
|
2022-03-17 09:42:59 +00:00
|
|
|
|
2024-05-15 16:09:42 +04:00
|
|
|
@AppStorage(DEFAULT_SHOW_SENT_VIA_RPOXY) private var showSentViaProxy = false
|
|
|
|
|
2022-03-25 22:26:05 +04:00
|
|
|
var body: some View {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
let v = msgContentView()
|
2022-12-17 14:02:07 +00:00
|
|
|
if meta?.isLive == true {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
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()
|
|
|
|
}
|
2022-12-17 14:02:07 +00:00
|
|
|
.onDisappear(perform: stopTyping)
|
|
|
|
.onChange(of: meta?.isLive, perform: switchTyping)
|
|
|
|
.onChange(of: meta?.recent, perform: switchTyping)
|
|
|
|
} else {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
v
|
2022-12-17 14:02:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func switchTyping(_: Bool? = nil) {
|
|
|
|
if let meta = meta, meta.isLive && meta.recent {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
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])
|
|
|
|
]
|
|
|
|
}
|
2022-12-17 14:02:07 +00:00
|
|
|
timer = timer ?? Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { _ in
|
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
2025-05-10 14:37:45 +01:00
|
|
|
typingIdx = typingIdx + 1
|
2022-12-17 14:02:07 +00:00
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
} else {
|
2022-12-17 14:02:07 +00:00
|
|
|
stopTyping()
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-17 14:02:07 +00:00
|
|
|
|
|
|
|
private func stopTyping() {
|
|
|
|
timer?.invalidate()
|
|
|
|
timer = nil
|
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
2025-05-10 14:37:45 +01:00
|
|
|
typingIdx = 0
|
2022-12-17 14:02:07 +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
2025-05-10 14:37:45 +01:00
|
|
|
@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
|
2022-12-17 14:02:07 +00:00
|
|
|
if let mt = meta {
|
|
|
|
if mt.isLive {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
s.append(typingIndicator(mt.recent))
|
2022-12-17 14:02:07 +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
2025-05-10 14:37:45 +01:00
|
|
|
t = Text(AttributedString(s)) + reserveSpaceForMeta(mt)
|
|
|
|
} else {
|
|
|
|
t = Text(AttributedString(s))
|
2022-12-17 14:02:07 +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
2025-05-10 14:37:45 +01:00
|
|
|
return t.overlay(handleTextLinks(s, showSecrets: $showSecrets))
|
2022-12-17 14:02:07 +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
2025-05-10 14:37:45 +01:00
|
|
|
@inline(__always)
|
|
|
|
private func typingIndicator(_ recent: Bool) -> NSAttributedString {
|
|
|
|
recent && !typingIndicators.isEmpty
|
|
|
|
? typingIndicators[typingIdx % 4]
|
|
|
|
: noTyping
|
2022-12-17 14:02:07 +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
2025-05-10 14:37:45 +01:00
|
|
|
@inline(__always)
|
2022-12-21 12:59:45 +00:00
|
|
|
private func reserveSpaceForMeta(_ mt: CIMeta) -> Text {
|
2025-03-07 16:50:44 +04:00
|
|
|
(rightToLeft ? textNewLine : Text(verbatim: " ")) + ciMetaText(mt, chatTTL: chat.chatInfo.timedMessagesTTL, encrypted: nil, colorMode: .transparent, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
|
2022-03-17 09:42:59 +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
2025-05-10 14:37:45 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let index, let (url, browser) = attributedStringLink(s, for: index) {
|
|
|
|
if browser {
|
|
|
|
openBrowserAlert(uri: url)
|
|
|
|
} else {
|
|
|
|
UIApplication.shared.open(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-03-17 09:42:59 +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
2025-05-10 14:37:45 +01:00
|
|
|
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 if let linkURL { (linkURL, browser) } else { nil }
|
2023-01-27 22:09:39 +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
2025-05-10 14:37:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private let linkAttrKey = NSAttributedString.Key("chat.simplex.app.link")
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
2025-01-08 18:28:45 +00:00
|
|
|
}
|
2023-01-27 22:09:39 +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
2025-05-10 14:37:45 +01:00
|
|
|
if let prefix {
|
|
|
|
res.append(prefix)
|
2022-03-17 09:42:59 +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
2025-05-10 14:37:45 +01:00
|
|
|
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
|
2025-02-03 20:47:32 +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
2025-05-10 14:37:45 +01:00
|
|
|
attrs[secretAttrKey] = secretIdx
|
|
|
|
secretIdx += 1
|
2025-02-03 20:47:32 +00:00
|
|
|
} else {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
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)
|
2025-02-03 20:47:32 +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
2025-05-10 14:37:45 +01:00
|
|
|
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: ()
|
2025-02-03 20:47:32 +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
2025-05-10 14:37:45 +01:00
|
|
|
res.append(NSAttributedString(string: t, attributes: attrs))
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
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
2025-05-10 14:37:45 +01:00
|
|
|
res.append(NSMutableAttributedString(string: text, attributes: plain))
|
2022-03-17 09:42:59 +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
2025-05-10 14:37:45 +01:00
|
|
|
|
|
|
|
return res
|
2025-02-03 20:47:32 +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
2025-05-10 14:37:45 +01:00
|
|
|
func linkAttrs() -> [NSAttributedString.Key: Any] {
|
|
|
|
link = link ?? [
|
|
|
|
.font: font,
|
|
|
|
.foregroundColor: uiLinkColor,
|
|
|
|
.underlineStyle: NSUnderlineStyle.single.rawValue
|
|
|
|
]
|
|
|
|
return link!
|
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
|
ios: rework UX of creating new connection (#3482)
* ios: connection UI (wip)
* custom search
* rework invite
* connect paste link ui
* scan rework, process errors, other fixes
* scan layout
* clear link on cancel
* improved search
* further improve search
* animation
* connect on paste in search
* layout
* layout
* layout
* layout, add conn
* delete unused invitation, create used invitation chat
* remove old views
* regular paste button
* new chat menu
* previews
* increase spacing
* animation, fix alerts
* swipe
* change text
* less sensitive gesture
* layout
* search cancel button transition
* slow down chat list animation (uses deprecated modifiers)
* icons
* update code scanner, layout
* manage camera permissions
* ask to delete unused invitation
* comment
* remove onDismiss
* don't filter chats on link in search, allow to paste text with link
* cleanup link after connection
* filter chat by link
* revert change
* show link descr
* disabled search
* underline
* filter own group
* simplify
* no animation
* add delay, move createInvitation
* update library
* possible fix for ios 15
* add explicit frame to qr code
* update library
* Revert "add explicit frame to qr code"
This reverts commit 95c7d31e47b3da39b5985cd57638885c45b77de1.
* remove comment
* fix pasteboardHasURLs, disable paste button based on it
* align help texts with changed button names
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
* update library
* Revert "fix pasteboardHasURLs, disable paste button based on it"
This reverts commit 46f63572e90dbf460faab9ce694181209712bd00.
* remove unused var
* restore disabled
* export localizations
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
2023-12-29 16:29:49 +04:00
|
|
|
func simplexLinkText(_ linkType: SimplexLinkType, _ smpHosts: [String]) -> String {
|
2022-11-24 17:14:56 +00:00
|
|
|
linkType.description + " " + "(via \(smpHosts.first ?? "?"))"
|
|
|
|
}
|
|
|
|
|
2022-03-17 09:42:59 +00:00
|
|
|
struct MsgContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
let chatItem = ChatItem.getSample(1, .directSnd, .now, "hello")
|
|
|
|
return MsgContentView(
|
2023-10-31 09:44:57 +00:00
|
|
|
chat: Chat.sampleData,
|
2022-05-13 12:57:30 +04:00
|
|
|
text: chatItem.text,
|
2022-03-17 09:42:59 +00:00
|
|
|
formattedText: chatItem.formattedText,
|
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
2025-05-10 14:37:45 +01:00
|
|
|
textStyle: .body,
|
2022-03-17 09:42:59 +00:00
|
|
|
sender: chatItem.memberDisplayName,
|
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
2025-05-10 14:37:45 +01:00
|
|
|
meta: chatItem.meta
|
2022-03-17 09:42:59 +00:00
|
|
|
)
|
2022-12-21 12:59:45 +00:00
|
|
|
.environmentObject(Chat.sampleData)
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
}
|