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
|
|
|
|
2024-11-27 19:01:16 +00:00
|
|
|
private let noTyping = Text(verbatim: " ")
|
2022-12-17 14:02:07 +00:00
|
|
|
|
|
|
|
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(".").fontWeight(w)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
var sender: String? = nil
|
2022-12-17 14:02:07 +00:00
|
|
|
var meta: CIMeta? = nil
|
2022-09-24 19:26:55 +01:00
|
|
|
var rightToLeft = false
|
2023-12-30 18:57:10 +00:00
|
|
|
var showSecrets: Bool
|
2022-12-17 14:02:07 +00:00
|
|
|
@State private var typingIdx = 0
|
|
|
|
@State private var timer: Timer?
|
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 {
|
2022-12-17 14:02:07 +00:00
|
|
|
if meta?.isLive == true {
|
|
|
|
msgContentView()
|
|
|
|
.onAppear { switchTyping() }
|
|
|
|
.onDisappear(perform: stopTyping)
|
|
|
|
.onChange(of: meta?.isLive, perform: switchTyping)
|
|
|
|
.onChange(of: meta?.recent, perform: switchTyping)
|
|
|
|
} else {
|
|
|
|
msgContentView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func switchTyping(_: Bool? = nil) {
|
|
|
|
if let meta = meta, meta.isLive && meta.recent {
|
|
|
|
timer = timer ?? Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { _ in
|
|
|
|
typingIdx = (typingIdx + 1) % typingIndicators.count
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
private func msgContentView() -> Text {
|
2024-07-03 22:42:13 +01:00
|
|
|
var v = messageText(text, formattedText, sender, showSecrets: showSecrets, secondaryColor: theme.colors.secondary)
|
2022-12-17 14:02:07 +00:00
|
|
|
if let mt = meta {
|
|
|
|
if mt.isLive {
|
|
|
|
v = v + typingIndicator(mt.recent)
|
|
|
|
}
|
2022-12-21 12:59:45 +00:00
|
|
|
v = v + reserveSpaceForMeta(mt)
|
2022-12-17 14:02:07 +00:00
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
private func typingIndicator(_ recent: Bool) -> Text {
|
|
|
|
return (recent ? typingIndicators[typingIdx] : noTyping)
|
|
|
|
.font(.body.monospaced())
|
|
|
|
.kerning(-2)
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(theme.colors.secondary)
|
2022-12-17 14:02:07 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 12:59:45 +00:00
|
|
|
private func reserveSpaceForMeta(_ mt: CIMeta) -> Text {
|
2024-11-27 19:01:16 +00:00
|
|
|
(rightToLeft ? Text("\n") : Text(verbatim: " ")) + ciMetaText(mt, chatTTL: chat.chatInfo.timedMessagesTTL, encrypted: nil, colorMode: .transparent, showViaProxy: showSentViaProxy, showTimesamp: showTimestamp)
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 22:42:13 +01:00
|
|
|
func messageText(_ text: String, _ formattedText: [FormattedText]?, _ sender: String?, icon: String? = nil, preview: Bool = false, showSecrets: Bool, secondaryColor: Color) -> Text {
|
2022-04-19 12:29:03 +04:00
|
|
|
let s = text
|
2022-03-17 09:42:59 +00:00
|
|
|
var res: Text
|
2023-08-02 16:22:20 +01:00
|
|
|
if let ft = formattedText, ft.count > 0 && ft.count <= 200 {
|
2023-12-30 18:57:10 +00:00
|
|
|
res = formatText(ft[0], preview, showSecret: showSecrets)
|
2022-03-17 09:42:59 +00:00
|
|
|
var i = 1
|
|
|
|
while i < ft.count {
|
2023-12-30 18:57:10 +00:00
|
|
|
res = res + formatText(ft[i], preview, showSecret: showSecrets)
|
2022-03-17 09:42:59 +00:00
|
|
|
i = i + 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = Text(s)
|
|
|
|
}
|
|
|
|
|
2023-01-27 22:09:39 +00:00
|
|
|
if let i = icon {
|
2024-11-27 19:01:16 +00:00
|
|
|
res = Text(Image(systemName: i)).foregroundColor(secondaryColor) + textSpace + res
|
2023-01-27 22:09:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 09:42:59 +00:00
|
|
|
if let s = sender {
|
|
|
|
let t = Text(s)
|
|
|
|
return (preview ? t : t.fontWeight(.medium)) + Text(": ") + res
|
|
|
|
} else {
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-30 18:57:10 +00:00
|
|
|
private func formatText(_ ft: FormattedText, _ preview: Bool, showSecret: Bool) -> Text {
|
2022-03-17 09:42:59 +00:00
|
|
|
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())
|
2023-12-30 18:57:10 +00:00
|
|
|
case .secret: return
|
|
|
|
showSecret
|
|
|
|
? Text(t)
|
|
|
|
: Text(AttributedString(t, attributes: AttributeContainer([
|
|
|
|
.foregroundColor: UIColor.clear as Any,
|
|
|
|
.backgroundColor: UIColor.secondarySystemFill as Any
|
|
|
|
])))
|
2022-03-17 09:42:59 +00:00
|
|
|
case let .colored(color): return Text(t).foregroundColor(color.uiColor)
|
|
|
|
case .uri: return linkText(t, t, preview, prefix: "")
|
2023-10-17 12:56:12 +04:00
|
|
|
case let .simplexLink(linkType, simplexUri, smpHosts):
|
2022-11-24 17:14:56 +00:00
|
|
|
switch privacySimplexLinkModeDefault.get() {
|
|
|
|
case .description: return linkText(simplexLinkText(linkType, smpHosts), simplexUri, preview, prefix: "")
|
|
|
|
case .full: return linkText(t, simplexUri, preview, prefix: "")
|
2023-10-17 12:56:12 +04:00
|
|
|
case .browser: return linkText(t, simplexUri, preview, prefix: "")
|
2022-11-24 17:14:56 +00:00
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 09:55:51 +00:00
|
|
|
private func linkText(_ s: String, _ link: String, _ preview: Bool, prefix: String, color: Color = Color(uiColor: uiLinkColor), uiColor: UIColor = uiLinkColor) -> Text {
|
2022-03-17 09:42:59 +00:00
|
|
|
preview
|
2022-11-25 09:55:51 +00:00
|
|
|
? Text(s).foregroundColor(color).underline(color: color)
|
2022-03-17 09:42:59 +00:00
|
|
|
: Text(AttributedString(s, attributes: AttributeContainer([
|
|
|
|
.link: NSURL(string: prefix + link) as Any,
|
2022-11-25 09:55:51 +00:00
|
|
|
.foregroundColor: uiColor as Any
|
2022-03-17 09:42:59 +00:00
|
|
|
]))).underline()
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
sender: chatItem.memberDisplayName,
|
2023-12-30 18:57:10 +00:00
|
|
|
meta: chatItem.meta,
|
|
|
|
showSecrets: false
|
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
|
|
|
}
|
|
|
|
}
|