mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 09:52:14 +00:00
* 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>
172 lines
6.4 KiB
Swift
172 lines
6.4 KiB
Swift
//
|
|
// GroupLinkView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by JRoberts on 15.10.2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct GroupLinkView: View {
|
|
var groupId: Int64
|
|
@Binding var groupLink: String?
|
|
@Binding var groupLinkMemberRole: GroupMemberRole
|
|
var showTitle: Bool = false
|
|
var creatingGroup: Bool = false
|
|
var linkCreatedCb: (() -> Void)? = nil
|
|
@State private var creatingLink = false
|
|
@State private var alert: GroupLinkAlert?
|
|
@State private var shouldCreate = true
|
|
|
|
private enum GroupLinkAlert: Identifiable {
|
|
case deleteLink
|
|
case error(title: LocalizedStringKey, error: LocalizedStringKey?)
|
|
|
|
var id: String {
|
|
switch self {
|
|
case .deleteLink: return "deleteLink"
|
|
case let .error(title, _): return "error \(title)"
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
if creatingGroup {
|
|
NavigationView {
|
|
groupLinkView()
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button ("Continue") { linkCreatedCb?() }
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
groupLinkView()
|
|
}
|
|
}
|
|
|
|
private func groupLinkView() -> some View {
|
|
List {
|
|
Group {
|
|
if showTitle {
|
|
Text("Group link")
|
|
.font(.largeTitle)
|
|
.bold()
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
Text("You can share a link or a QR code - anybody will be able to join the group. You won't lose members of the group if you later delete it.")
|
|
}
|
|
.listRowBackground(Color.clear)
|
|
.listRowSeparator(.hidden)
|
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
|
|
|
|
Section {
|
|
if let groupLink = groupLink {
|
|
Picker("Initial role", selection: $groupLinkMemberRole) {
|
|
ForEach([GroupMemberRole.member, GroupMemberRole.observer]) { role in
|
|
Text(role.text)
|
|
}
|
|
}
|
|
.frame(height: 36)
|
|
SimpleXLinkQRCode(uri: groupLink)
|
|
.id("simplex-qrcode-view-for-\(groupLink)")
|
|
Button {
|
|
showShareSheet(items: [simplexChatLink(groupLink)])
|
|
} label: {
|
|
Label("Share link", systemImage: "square.and.arrow.up")
|
|
}
|
|
|
|
if !creatingGroup {
|
|
Button(role: .destructive) { alert = .deleteLink } label: {
|
|
Label("Delete link", systemImage: "trash")
|
|
}
|
|
}
|
|
} else {
|
|
Button(action: createGroupLink) {
|
|
Label("Create link", systemImage: "link.badge.plus")
|
|
}
|
|
.disabled(creatingLink)
|
|
if creatingLink {
|
|
ProgressView()
|
|
.scaleEffect(2)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
}
|
|
.alert(item: $alert) { alert in
|
|
switch alert {
|
|
case .deleteLink:
|
|
return Alert(
|
|
title: Text("Delete link?"),
|
|
message: Text("All group members will remain connected."),
|
|
primaryButton: .destructive(Text("Delete")) {
|
|
Task {
|
|
do {
|
|
try await apiDeleteGroupLink(groupId)
|
|
await MainActor.run { groupLink = nil }
|
|
} catch let error {
|
|
logger.error("GroupLinkView apiDeleteGroupLink: \(responseError(error))")
|
|
}
|
|
}
|
|
}, secondaryButton: .cancel()
|
|
)
|
|
case let .error(title, error):
|
|
return mkAlert(title: title, message: error)
|
|
}
|
|
}
|
|
.onChange(of: groupLinkMemberRole) { _ in
|
|
Task {
|
|
do {
|
|
_ = try await apiGroupLinkMemberRole(groupId, memberRole: groupLinkMemberRole)
|
|
} catch let error {
|
|
let a = getErrorAlert(error, "Error updating group link")
|
|
alert = .error(title: a.title, error: a.message)
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
if groupLink == nil && !creatingLink && shouldCreate {
|
|
createGroupLink()
|
|
}
|
|
shouldCreate = false
|
|
}
|
|
}
|
|
.modifier(ThemedBackground(grouped: true))
|
|
}
|
|
|
|
private func createGroupLink() {
|
|
Task {
|
|
do {
|
|
creatingLink = true
|
|
let link = try await apiCreateGroupLink(groupId)
|
|
await MainActor.run {
|
|
creatingLink = false
|
|
(groupLink, groupLinkMemberRole) = link
|
|
}
|
|
} catch let error {
|
|
logger.error("GroupLinkView apiCreateGroupLink: \(responseError(error))")
|
|
await MainActor.run {
|
|
creatingLink = false
|
|
let a = getErrorAlert(error, "Error creating group link")
|
|
alert = .error(title: a.title, error: a.message)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct GroupLinkView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
@State var groupLink: String? = "https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2FPQUV2eL0t7OStZOoAsPEV2QYWt4-xilbakvGUGOItUo%3D%40smp6.simplex.im%2FK1rslx-m5bpXVIdMZg9NLUZ_8JBm8xTt%23MCowBQYDK2VuAyEALDeVe-sG8mRY22LsXlPgiwTNs9dbiLrNuA7f3ZMAJ2w%3D"
|
|
@State var noGroupLink: String? = nil
|
|
|
|
return Group {
|
|
GroupLinkView(groupId: 1, groupLink: $groupLink, groupLinkMemberRole: Binding.constant(.member))
|
|
GroupLinkView(groupId: 1, groupLink: $noGroupLink, groupLinkMemberRole: Binding.constant(.member))
|
|
}
|
|
}
|
|
}
|
|
|