2024-04-16 12:28:39 +04:00
|
|
|
//
|
|
|
|
// ChatItemForwardingView.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by spaced4ndy on 12.04.2024.
|
|
|
|
// Copyright © 2024 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import SimpleXChat
|
|
|
|
|
|
|
|
struct ChatItemForwardingView: View {
|
|
|
|
@EnvironmentObject var chatModel: ChatModel
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2024-04-16 12:28:39 +04:00
|
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
|
|
|
|
var ci: ChatItem
|
|
|
|
var fromChatInfo: ChatInfo
|
|
|
|
@Binding var composeState: ComposeState
|
|
|
|
|
|
|
|
@State private var searchText: String = ""
|
|
|
|
@FocusState private var searchFocused
|
2024-06-19 12:51:56 +01:00
|
|
|
@State private var alert: SomeAlert?
|
2024-07-28 17:54:58 +01:00
|
|
|
private let chatsToForwardTo = filterChatsToForwardTo(chats: ChatModel.shared.chats)
|
2024-04-16 12:28:39 +04:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
forwardListView()
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
Button("Cancel") {
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ToolbarItem(placement: .principal) {
|
|
|
|
Text("Forward")
|
|
|
|
.bold()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 22:42:13 +01:00
|
|
|
.modifier(ThemedBackground())
|
2024-06-19 12:51:56 +01:00
|
|
|
.alert(item: $alert) { $0.alert }
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private func forwardListView() -> some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
if !chatsToForwardTo.isEmpty {
|
2024-06-19 12:51:56 +01:00
|
|
|
List {
|
2024-07-03 22:42:13 +01:00
|
|
|
searchFieldView(text: $searchText, focussed: $searchFocused, theme.colors.onBackground, theme.colors.secondary)
|
2024-06-19 12:51:56 +01:00
|
|
|
.padding(.leading, 2)
|
|
|
|
let s = searchText.trimmingCharacters(in: .whitespaces).localizedLowercase
|
|
|
|
let chats = s == "" ? chatsToForwardTo : chatsToForwardTo.filter { foundChat($0, s) }
|
|
|
|
ForEach(chats) { chat in
|
|
|
|
forwardListChatView(chat)
|
|
|
|
.disabled(chatModel.deletedChats.contains(chat.chatInfo.id))
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
|
|
|
}
|
2024-07-03 22:42:13 +01:00
|
|
|
.modifier(ThemedBackground(grouped: true))
|
2024-04-16 12:28:39 +04:00
|
|
|
} else {
|
2024-07-03 22:42:13 +01:00
|
|
|
ZStack {
|
|
|
|
emptyList()
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
|
|
.modifier(ThemedBackground())
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func emptyList() -> some View {
|
|
|
|
Text("No filtered chats")
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(theme.colors.secondary)
|
2024-04-16 12:28:39 +04:00
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
}
|
2024-07-03 22:42:13 +01:00
|
|
|
|
2024-06-19 13:49:44 +04:00
|
|
|
@ViewBuilder private func forwardListChatView(_ chat: Chat) -> some View {
|
2024-08-01 09:48:17 +03:00
|
|
|
let prohibited = chat.prohibitedByPref(
|
|
|
|
hasSimplexLink: hasSimplexLink(ci.content.msgContent?.text),
|
|
|
|
isMediaOrFileAttachment: ci.content.msgContent?.isMediaOrFileAttachment ?? false,
|
|
|
|
isVoice: ci.content.msgContent?.isVoice ?? false
|
|
|
|
)
|
2024-04-16 12:28:39 +04:00
|
|
|
Button {
|
2024-06-19 12:51:56 +01:00
|
|
|
if prohibited {
|
|
|
|
alert = SomeAlert(
|
2024-06-19 13:49:44 +04:00
|
|
|
alert: mkAlert(
|
|
|
|
title: "Cannot forward message",
|
|
|
|
message: "Selected chat preferences prohibit this message."
|
|
|
|
),
|
|
|
|
id: "forward prohibited by preferences"
|
|
|
|
)
|
2024-04-16 12:28:39 +04:00
|
|
|
} else {
|
2024-06-19 13:49:44 +04:00
|
|
|
dismiss()
|
|
|
|
if chat.id == fromChatInfo.id {
|
|
|
|
composeState = ComposeState(
|
|
|
|
message: composeState.message,
|
|
|
|
preview: composeState.linkPreview != nil ? composeState.preview : .noPreview,
|
|
|
|
contextItem: .forwardingItem(chatItem: ci, fromChatInfo: fromChatInfo)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
composeState = ComposeState.init(forwardingItem: ci, fromChatInfo: fromChatInfo)
|
|
|
|
chatModel.chatId = chat.id
|
|
|
|
}
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
HStack {
|
2024-04-24 21:20:26 +01:00
|
|
|
ChatInfoImage(chat: chat, size: 30)
|
2024-04-16 12:28:39 +04:00
|
|
|
.padding(.trailing, 2)
|
|
|
|
Text(chat.chatInfo.chatViewName)
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(prohibited ? theme.colors.secondary : theme.colors.onBackground)
|
2024-04-16 12:28:39 +04:00
|
|
|
.lineLimit(1)
|
|
|
|
if chat.chatInfo.incognito {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "theatermasks")
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: 22, height: 22)
|
2024-07-03 22:42:13 +01:00
|
|
|
.foregroundColor(theme.colors.secondary)
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
ChatItemForwardingView(
|
|
|
|
ci: ChatItem.getSample(1, .directSnd, .now, "hello"),
|
|
|
|
fromChatInfo: .direct(contact: Contact.sampleData),
|
|
|
|
composeState: Binding.constant(ComposeState(message: "hello"))
|
2024-07-03 22:42:13 +01:00
|
|
|
).environmentObject(CurrentColors.toAppTheme())
|
2024-04-16 12:28:39 +04:00
|
|
|
}
|
2024-07-28 17:54:58 +01:00
|
|
|
|