mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 21:45:20 +00:00
Keep share extension helpers target-local
This commit is contained in:
@@ -45,10 +45,6 @@ struct SharedContentPayload: Codable, Sendable, Equatable, Identifiable {
|
||||
SharedContentPayload(kind: .text, content: content, createdAt: createdAt)
|
||||
}
|
||||
|
||||
static func url(_ url: URL, title: String?, createdAt: Date = Date()) -> SharedContentPayload {
|
||||
SharedContentPayload(kind: .url, content: url.absoluteString, title: title, createdAt: createdAt)
|
||||
}
|
||||
|
||||
var composerText: String { content }
|
||||
|
||||
var preview: String {
|
||||
@@ -148,11 +144,6 @@ final class SharedContentStore {
|
||||
self.decoder = JSONDecoder()
|
||||
}
|
||||
|
||||
convenience init?(suiteName: String) {
|
||||
guard let defaults = UserDefaults(suiteName: suiteName) else { return nil }
|
||||
self.init(defaults: defaults)
|
||||
}
|
||||
|
||||
/// Replaces any older pending share with a validated, bounded envelope.
|
||||
func stage(_ payload: SharedContentPayload, now: Date = Date()) throws {
|
||||
try payload.validate(now: now)
|
||||
|
||||
@@ -148,8 +148,9 @@ final class ShareViewController: UIViewController {
|
||||
|
||||
// MARK: - Save + Finish
|
||||
private func saveAndFinish(url: URL, title: String?) {
|
||||
let payload = SharedContentPayload.url(
|
||||
url,
|
||||
let payload = SharedContentPayload(
|
||||
kind: .url,
|
||||
content: url.absoluteString,
|
||||
title: title ?? url.host ?? Strings.sharedLinkTitleFallback
|
||||
)
|
||||
stageAndFinish(payload)
|
||||
@@ -160,10 +161,11 @@ final class ShareViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func stageAndFinish(_ payload: SharedContentPayload) {
|
||||
guard let store = SharedContentStore(suiteName: Self.groupID) else {
|
||||
guard let defaults = UserDefaults(suiteName: Self.groupID) else {
|
||||
finishWithMessage(Strings.failedToSave)
|
||||
return
|
||||
}
|
||||
let store = SharedContentStore(defaults: defaults)
|
||||
|
||||
do {
|
||||
try store.stage(payload)
|
||||
|
||||
Reference in New Issue
Block a user