mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-11 19:45:00 +00:00
6865515f43
* ios: share extension (#4414) * ios: add share extension target * ios: Add UI * ios: send file from share-sheet * image utils * ShareError * error handling; ui-cleanup * progress bar; completion for direct chat * cleanup * cleanup * ios: unify filter and sort between forward and share sheets * ios: match share sheet styling with the main app * ios: fix text input stroke width * ios: align compose views * more of the same... * ShareAPI * remove combine * minor * Better error descriptions --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: enable file sending workers in share extension (#4474) * ios: align compose background, row height and fallback images for share-sheet (#4467) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: coordinate database access between share extension, the app and notifications extension (#4472) * ios: database management proposal * Add SEState * Global event loop * minor * reset state * use apiCreateItem for local chats * simplify waiting for suspension * loading bar * Dismiss share sheet with error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * send image message (#4481) Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: improve share extension completion handling (#4486) * improve completion handling * minor * show only spinner for group send * rework event loop, errorAlert * group chat timeout loading bar * state machine WIP * event loop actor * alert * errors text * default * file error --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: add remaining share types; process attachment in background on launch (#4510) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: share extension - additional alerts and media previews (#4521) * add remaining share types; process attachment in background on launch * cleanup diff * revert `makeVideoQualityLower` * reduce diff * reduce diff * iOS15 support * process events when sharing link and text * cleanup * remove video file on failure * cleanup CompletionHandler * media previews * network timeout alert * revert framework compiler optimisation flag * suspend chat after sheet dismiss * activate chat * update * fix search * sendMessageColor, file preview, chat deselect, simplify error action * cleanup * interupt database closing when sheet is reopened quickly * cleanup redundant alert check * restore package * refactor previews, remove link preview * show link preview when becomes available * comment * dont fail on invalid image * suspend --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: descriptive database errors (#4527) * ios: set share extension as inactive when suspending chat --------- Co-authored-by: Arturs Krumins <auth@levitatingpineapple.com>
157 lines
5.7 KiB
Swift
157 lines
5.7 KiB
Swift
//
|
|
// 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
|
|
@EnvironmentObject var theme: AppTheme
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
var ci: ChatItem
|
|
var fromChatInfo: ChatInfo
|
|
@Binding var composeState: ComposeState
|
|
|
|
@State private var searchText: String = ""
|
|
@FocusState private var searchFocused
|
|
@State private var alert: SomeAlert?
|
|
@State private var hasSimplexLink_: Bool?
|
|
private let chatsToForwardTo = filterChatsToForwardTo(chats: ChatModel.shared.chats)
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
forwardListView()
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
Button("Cancel") {
|
|
dismiss()
|
|
}
|
|
}
|
|
ToolbarItem(placement: .principal) {
|
|
Text("Forward")
|
|
.bold()
|
|
}
|
|
}
|
|
}
|
|
.modifier(ThemedBackground())
|
|
.alert(item: $alert) { $0.alert }
|
|
}
|
|
|
|
@ViewBuilder private func forwardListView() -> some View {
|
|
VStack(alignment: .leading) {
|
|
if !chatsToForwardTo.isEmpty {
|
|
List {
|
|
searchFieldView(text: $searchText, focussed: $searchFocused, theme.colors.onBackground, theme.colors.secondary)
|
|
.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))
|
|
}
|
|
}
|
|
.modifier(ThemedBackground(grouped: true))
|
|
} else {
|
|
ZStack {
|
|
emptyList()
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.modifier(ThemedBackground())
|
|
}
|
|
}
|
|
}
|
|
|
|
private func prohibitedByPref(_ chat: Chat) -> Bool {
|
|
// preference checks should match checks in compose view
|
|
let simplexLinkProhibited = hasSimplexLink && !chat.groupFeatureEnabled(.simplexLinks)
|
|
let fileProhibited = (ci.content.msgContent?.isMediaOrFileAttachment ?? false) && !chat.groupFeatureEnabled(.files)
|
|
let voiceProhibited = (ci.content.msgContent?.isVoice ?? false) && !chat.chatInfo.featureEnabled(.voice)
|
|
return switch chat.chatInfo {
|
|
case .direct: voiceProhibited
|
|
case .group: simplexLinkProhibited || fileProhibited || voiceProhibited
|
|
case .local: false
|
|
case .contactRequest: false
|
|
case .contactConnection: false
|
|
case .invalidJSON: false
|
|
}
|
|
}
|
|
|
|
private var hasSimplexLink: Bool {
|
|
if let hasSimplexLink_ { return hasSimplexLink_ }
|
|
let r =
|
|
if let mcText = ci.content.msgContent?.text,
|
|
let parsedMsg = parseSimpleXMarkdown(mcText) {
|
|
parsedMsgHasSimplexLink(parsedMsg)
|
|
} else {
|
|
false
|
|
}
|
|
hasSimplexLink_ = r
|
|
return r
|
|
}
|
|
|
|
private func emptyList() -> some View {
|
|
Text("No filtered chats")
|
|
.foregroundColor(theme.colors.secondary)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
|
|
@ViewBuilder private func forwardListChatView(_ chat: Chat) -> some View {
|
|
let prohibited = prohibitedByPref(chat)
|
|
Button {
|
|
if prohibited {
|
|
alert = SomeAlert(
|
|
alert: mkAlert(
|
|
title: "Cannot forward message",
|
|
message: "Selected chat preferences prohibit this message."
|
|
),
|
|
id: "forward prohibited by preferences"
|
|
)
|
|
} else {
|
|
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
|
|
}
|
|
}
|
|
} label: {
|
|
HStack {
|
|
ChatInfoImage(chat: chat, size: 30)
|
|
.padding(.trailing, 2)
|
|
Text(chat.chatInfo.chatViewName)
|
|
.foregroundColor(prohibited ? theme.colors.secondary : theme.colors.onBackground)
|
|
.lineLimit(1)
|
|
if chat.chatInfo.incognito {
|
|
Spacer()
|
|
Image(systemName: "theatermasks")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 22, height: 22)
|
|
.foregroundColor(theme.colors.secondary)
|
|
}
|
|
}
|
|
.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"))
|
|
).environmentObject(CurrentColors.toAppTheme())
|
|
}
|
|
|