2022-02-12 15:59:43 +00:00
|
|
|
//
|
|
|
|
// CIMetaView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by Evgeny Poberezkin on 11/02/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-05-31 07:55:13 +01:00
|
|
|
import SimpleXChat
|
2022-02-12 15:59:43 +00:00
|
|
|
|
|
|
|
struct CIMetaView: View {
|
2023-10-31 09:44:57 +00:00
|
|
|
@ObservedObject var chat: Chat
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2024-08-25 21:21:24 +03:00
|
|
|
@Environment(\.showTimestamp) var showTimestamp: Bool
|
2022-02-12 15:59:43 +00:00
|
|
|
var chatItem: ChatItem
|
2024-07-03 22:42:13 +01:00
|
|
|
var metaColor: Color
|
2023-07-28 13:16:52 +04:00
|
|
|
var paleMetaColor = Color(UIColor.tertiaryLabel)
|
2024-04-25 12:41:20 +04:00
|
|
|
var showStatus = true
|
|
|
|
var showEdited = true
|
2022-02-12 15:59:43 +00:00
|
|
|
|
2024-05-15 16:09:42 +04:00
|
|
|
@AppStorage(DEFAULT_SHOW_SENT_VIA_RPOXY) private var showSentViaProxy = false
|
|
|
|
|
2022-02-12 15:59:43 +00:00
|
|
|
var body: some View {
|
2022-12-21 12:59:45 +00:00
|
|
|
if chatItem.isDeletedContent {
|
|
|
|
chatItem.timestampText.font(.caption).foregroundColor(metaColor)
|
|
|
|
} else {
|
2024-09-03 09:59:40 +03:00
|
|
|
ciMetaText(
|
|
|
|
chatItem.meta,
|
|
|
|
chatTTL: chat.chatInfo.timedMessagesTTL,
|
|
|
|
encrypted: chatItem.encryptedFile,
|
|
|
|
color: chatItem.meta.itemStatus.sndProgress == .partial
|
|
|
|
? paleMetaColor
|
|
|
|
: metaColor,
|
|
|
|
showStatus: showStatus,
|
|
|
|
showEdited: showEdited,
|
|
|
|
showViaProxy: showSentViaProxy,
|
|
|
|
showTimesamp: showTimestamp
|
|
|
|
)
|
2022-02-12 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 12:41:20 +04:00
|
|
|
func ciMetaText(
|
|
|
|
_ meta: CIMeta,
|
|
|
|
chatTTL: Int?,
|
|
|
|
encrypted: Bool?,
|
|
|
|
color: Color = .clear,
|
2024-07-03 22:42:13 +01:00
|
|
|
primaryColor: Color = .accentColor,
|
2024-04-25 12:41:20 +04:00
|
|
|
transparent: Bool = false,
|
|
|
|
showStatus: Bool = true,
|
2024-05-15 16:09:42 +04:00
|
|
|
showEdited: Bool = true,
|
2024-08-25 21:21:24 +03:00
|
|
|
showViaProxy: Bool,
|
|
|
|
showTimesamp: Bool
|
2024-04-25 12:41:20 +04:00
|
|
|
) -> Text {
|
2022-12-21 12:59:45 +00:00
|
|
|
var r = Text("")
|
2024-04-25 12:41:20 +04:00
|
|
|
if showEdited, meta.itemEdited {
|
2022-12-21 12:59:45 +00:00
|
|
|
r = r + statusIconText("pencil", color)
|
|
|
|
}
|
|
|
|
if meta.disappearing {
|
|
|
|
r = r + statusIconText("timer", color).font(.caption2)
|
|
|
|
let ttl = meta.itemTimed?.ttl
|
|
|
|
if ttl != chatTTL {
|
2023-05-15 16:07:55 +04:00
|
|
|
r = r + Text(shortTimeText(ttl)).foregroundColor(color)
|
2022-12-21 12:59:45 +00:00
|
|
|
}
|
|
|
|
r = r + Text(" ")
|
|
|
|
}
|
2024-05-15 16:09:42 +04:00
|
|
|
if showViaProxy, meta.sentViaProxy == true {
|
|
|
|
r = r + statusIconText("arrow.forward", color.opacity(0.67)).font(.caption2)
|
|
|
|
}
|
2024-04-25 15:15:52 +04:00
|
|
|
if showStatus {
|
2024-09-03 09:59:40 +03:00
|
|
|
if let (image, statusColor) = meta.itemStatus.statusIcon(color, primaryColor) {
|
|
|
|
r = r + Text(image).foregroundColor(transparent ? .clear : statusColor) + Text(" ")
|
2024-04-25 15:15:52 +04:00
|
|
|
} else if !meta.disappearing {
|
|
|
|
r = r + statusIconText("circlebadge.fill", .clear) + Text(" ")
|
2023-07-16 14:55:31 +04:00
|
|
|
}
|
2022-12-21 12:59:45 +00:00
|
|
|
}
|
2023-09-07 11:28:37 +01:00
|
|
|
if let enc = encrypted {
|
|
|
|
r = r + statusIconText(enc ? "lock" : "lock.open", color) + Text(" ")
|
|
|
|
}
|
2024-08-25 21:21:24 +03:00
|
|
|
if showTimesamp {
|
|
|
|
r = r + meta.timestampText.foregroundColor(color)
|
|
|
|
}
|
2023-09-07 11:28:37 +01:00
|
|
|
return r.font(.caption)
|
2022-12-21 12:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func statusIconText(_ icon: String, _ color: Color) -> Text {
|
|
|
|
Text(Image(systemName: icon)).foregroundColor(color)
|
|
|
|
}
|
|
|
|
|
2022-02-12 15:59:43 +00:00
|
|
|
struct CIMetaView_Previews: PreviewProvider {
|
2024-07-03 22:42:13 +01:00
|
|
|
static let metaColor = Color.secondary
|
2022-02-12 15:59:43 +00:00
|
|
|
static var previews: some View {
|
2022-12-03 15:40:31 +04:00
|
|
|
Group {
|
2024-07-03 22:42:13 +01:00
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndSent(sndProgress: .complete)), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndSent(sndProgress: .partial)), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndRcvd(msgRcptStatus: .ok, sndProgress: .complete)), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndRcvd(msgRcptStatus: .ok, sndProgress: .partial)), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndRcvd(msgRcptStatus: .badMsgHash, sndProgress: .complete)), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getSample(2, .directSnd, .now, "https://simplex.chat", .sndSent(sndProgress: .complete), itemEdited: true), metaColor: metaColor)
|
|
|
|
CIMetaView(chat: Chat.sampleData, chatItem: ChatItem.getDeletedContentSample(), metaColor: metaColor)
|
2022-03-25 22:26:05 +04:00
|
|
|
}
|
2022-03-30 20:37:47 +04:00
|
|
|
.previewLayout(.fixed(width: 360, height: 100))
|
2022-02-12 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|