mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-07 02:06:01 +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>
116 lines
3.1 KiB
Swift
116 lines
3.1 KiB
Swift
//
|
|
// ShareAPI.swift
|
|
// SimpleX SE
|
|
//
|
|
// Created by User on 15/07/2024.
|
|
// Copyright © 2024 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import OSLog
|
|
import Foundation
|
|
import SimpleXChat
|
|
|
|
let logger = Logger()
|
|
|
|
func apiGetActiveUser() throws -> User? {
|
|
let r = sendSimpleXCmd(.showActiveUser)
|
|
switch r {
|
|
case let .activeUser(user): return user
|
|
case .chatCmdError(_, .error(.noActiveUser)): return nil
|
|
default: throw r
|
|
}
|
|
}
|
|
|
|
func apiStartChat() throws -> Bool {
|
|
let r = sendSimpleXCmd(.startChat(mainApp: false, enableSndFiles: true))
|
|
switch r {
|
|
case .chatStarted: return true
|
|
case .chatRunning: return false
|
|
default: throw r
|
|
}
|
|
}
|
|
|
|
func apiSetNetworkConfig(_ cfg: NetCfg) throws {
|
|
let r = sendSimpleXCmd(.apiSetNetworkConfig(networkConfig: cfg))
|
|
if case .cmdOk = r { return }
|
|
throw r
|
|
}
|
|
|
|
func apiSetAppFilePaths(filesFolder: String, tempFolder: String, assetsFolder: String) throws {
|
|
let r = sendSimpleXCmd(.apiSetAppFilePaths(filesFolder: filesFolder, tempFolder: tempFolder, assetsFolder: assetsFolder))
|
|
if case .cmdOk = r { return }
|
|
throw r
|
|
}
|
|
|
|
func apiSetEncryptLocalFiles(_ enable: Bool) throws {
|
|
let r = sendSimpleXCmd(.apiSetEncryptLocalFiles(enable: enable))
|
|
if case .cmdOk = r { return }
|
|
throw r
|
|
}
|
|
|
|
func apiGetChats(userId: User.ID) throws -> Array<ChatData> {
|
|
let r = sendSimpleXCmd(.apiGetChats(userId: userId))
|
|
if case let .apiChats(user: _, chats: chats) = r { return chats }
|
|
throw r
|
|
}
|
|
|
|
func apiSendMessage(
|
|
chatInfo: ChatInfo,
|
|
cryptoFile: CryptoFile?,
|
|
msgContent: MsgContent
|
|
) throws -> AChatItem {
|
|
let r = sendSimpleXCmd(
|
|
chatInfo.chatType == .local
|
|
? .apiCreateChatItem(
|
|
noteFolderId: chatInfo.apiId,
|
|
file: cryptoFile,
|
|
msg: msgContent
|
|
)
|
|
: .apiSendMessage(
|
|
type: chatInfo.chatType,
|
|
id: chatInfo.apiId,
|
|
file: cryptoFile,
|
|
quotedItemId: nil,
|
|
msg: msgContent,
|
|
live: false,
|
|
ttl: nil
|
|
)
|
|
)
|
|
if case let .newChatItem(_, chatItem) = r {
|
|
return chatItem
|
|
} else {
|
|
if let filePath = cryptoFile?.filePath { removeFile(filePath) }
|
|
throw r
|
|
}
|
|
}
|
|
|
|
func apiActivateChat() throws {
|
|
chatReopenStore()
|
|
let r = sendSimpleXCmd(.apiActivateChat(restoreChat: false))
|
|
if case .cmdOk = r { return }
|
|
throw r
|
|
}
|
|
|
|
func apiSuspendChat(expired: Bool) {
|
|
let r = sendSimpleXCmd(.apiSuspendChat(timeoutMicroseconds: expired ? 0 : 3_000000))
|
|
// Block until `chatSuspended` received or 3 seconds has passed
|
|
var suspended = false
|
|
if case .cmdOk = r, !expired {
|
|
let startTime = CFAbsoluteTimeGetCurrent()
|
|
while CFAbsoluteTimeGetCurrent() - startTime < 3 {
|
|
switch recvSimpleXMsg(messageTimeout: 3_500000) {
|
|
case .chatSuspended:
|
|
suspended = false
|
|
break
|
|
default: continue
|
|
}
|
|
}
|
|
}
|
|
if !suspended {
|
|
_ = sendSimpleXCmd(.apiSuspendChat(timeoutMicroseconds: 0))
|
|
}
|
|
logger.debug("close store")
|
|
chatCloseStore()
|
|
SEChatState.shared.set(.inactive)
|
|
}
|