Files
simplex-chat/apps/ios/Shared/Views/Chat/ComposeMessage/ContextItemView.swift
T
Evgeny @ SimpleX Chat 348c42a640 ui, core, mcp: show Claude as an agent and User as a person (#8179)
* plan: mcp-agent-profile

* plan: mcp-agent-profile, answers Q1 (b) and Q2 (b)

* plan: mcp-agent-profile, lists render on GitHub

* mcp: User has the peer type of a person

* ui: show the peer type placeholder of members and contacts

* plan: mcp-agent-profile, answers to the user's notes

* ui: compare link icons with peerTypeIcon in the desktop test

* ui: snapshot references of the peer type placeholders

* android: peer type placeholder of a caller on the lock screen

* ios: agent icon of a link in the compose context at text size

* plan: mcp-agent-profile, review fixes

* ios: snapshot references with the compose context line of a link

* core: send a change of the peer type alone to groups

* mcp: User's peer type reaches existing session groups

* plan: mcp-agent-profile, Q1 (a)

* mcp: mark the agent profile item delivered in the roadmap
2026-11-14 09:12:01 +00:00

112 lines
4.7 KiB
Swift

//
// ContextItemView.swift
// SimpleX
//
// Created by JRoberts on 13/03/2022.
// Copyright © 2022 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct ContextItemView: View {
@EnvironmentObject var theme: AppTheme
@ObservedObject var chat: Chat
let contextItems: [ChatItem]
let contextIcon: String
let cancelContextItem: () -> Void
var contextIconForeground: Color? = nil
var showSender: Bool = true
var body: some View {
HStack {
Image(systemName: contextIcon)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 16, height: 16)
.foregroundColor(contextIconForeground ?? theme.colors.secondary)
if let singleItem = contextItems.first, contextItems.count == 1 {
if showSender, let sender = singleItem.memberDisplayName {
VStack(alignment: .leading, spacing: 4) {
Text(sender).font(.caption).foregroundColor(theme.colors.secondary)
msgContentView(lines: 2, contextItem: singleItem)
}
} else {
msgContentView(lines: 3, contextItem: singleItem)
}
} else {
Text(
chat.chatInfo.chatType == .local
? "Saving \(contextItems.count) messages"
: "Forwarding \(contextItems.count) messages"
)
.italic()
}
Spacer()
Button {
withAnimation {
cancelContextItem()
}
} label: {
Image(systemName: "multiply")
}
.tint(theme.colors.primary)
}
.padding(12)
.frame(minHeight: 54)
.frame(maxWidth: .infinity)
.background(background)
}
private var background: Color {
contextItems.first
.map { chatItemFrameColor($0, theme) }
?? Color(uiColor: .tertiarySystemBackground)
}
private func msgContentView(lines: Int, contextItem: ChatItem) -> some View {
contextMsgPreview(contextItem)
.multilineTextAlignment(isRightToLeft(contextItem.text) ? .trailing : .leading)
.lineLimit(lines)
}
private func contextMsgPreview(_ contextItem: ChatItem) -> some View {
let r = messageText(contextItem.text, contextItem.formattedText, markdownBlocks: contextItem.markdownBlocks, sender: nil, preview: true, mentions: contextItem.mentions, userMemberId: nil, showSecrets: nil, backgroundColor: UIColor(background), stripLink: contextItem.content.msgContent?.chatLinkStr)
let t = attachment() + Text(AttributedString(r.string))
return t.if(r.hasSecrets, transform: hiddenSecretsView)
func attachment() -> Text {
let isFileLoaded = if let fileSource = getLoadedFileSource(contextItem.file) {
FileManager.default.fileExists(atPath: getAppFilePath(fileSource.filePath).path)
} else { false }
switch contextItem.content.msgContent {
case .file: return isFileLoaded ? image(Image(systemName: "doc.fill")) : Text("")
case .image: return image(Image(systemName: "photo"))
case .voice: return isFileLoaded ? image(Image(systemName: "play.fill")) : Text("")
case let .chat(_, chatLink, _):
let hasText = contextItem.text != chatLink.connLinkStr
return image(chatLink.smallIcon(agent: textAgentIcon())) + Text(chatLink.displayName) + Text(verbatim: hasText ? " - " : "")
default: return Text("")
}
}
func image(_ i: Image) -> Text {
Text(i).foregroundColor(Color(uiColor: .tertiaryLabel)) + textSpace
}
func textAgentIcon() -> Image {
guard let person = UIImage(systemName: "person", withConfiguration: UIImage.SymbolConfiguration(textStyle: .body)),
let agent = UIImage(named: "agent") else { return Image("agent") }
let size = CGSize(width: person.size.height * agent.size.width / agent.size.height, height: person.size.height)
return Image(uiImage: UIGraphicsImageRenderer(size: size).image { _ in agent.draw(in: CGRect(origin: .zero, size: size)) }.withRenderingMode(.alwaysTemplate))
}
}
}
struct ContextItemView_Previews: PreviewProvider {
static var previews: some View {
let contextItem: ChatItem = ChatItem.getSample(1, .directSnd, previewDate, "hello")
return ContextItemView(chat: Chat.sampleData, contextItems: [contextItem], contextIcon: "pencil.circle", cancelContextItem: {}, contextIconForeground: Color.red)
}
}