Compare commits

...

2 Commits

4 changed files with 30 additions and 17 deletions

View File

@ -77,7 +77,8 @@ class PostService: ObservableObject {
pollOptions: draft.poll?.pollOptions.map(\.text), pollOptions: draft.poll?.pollOptions.map(\.text),
pollExpiresIn: draft.poll == nil ? nil : Int(draft.poll!.duration), pollExpiresIn: draft.poll == nil ? nil : Int(draft.poll!.duration),
pollMultiple: draft.poll?.multiple, pollMultiple: draft.poll?.multiple,
localOnly: mastodonController.instanceFeatures.localOnlyPosts ? draft.localOnly : nil localOnly: mastodonController.instanceFeatures.localOnlyPosts ? draft.localOnly : nil,
idempotencyKey: draft.id.uuidString
) )
} }

View File

@ -113,6 +113,9 @@ public class Client {
var urlRequest = URLRequest(url: url, timeoutInterval: timeoutInterval) var urlRequest = URLRequest(url: url, timeoutInterval: timeoutInterval)
urlRequest.httpMethod = request.method.name urlRequest.httpMethod = request.method.name
urlRequest.httpBody = request.body.data urlRequest.httpBody = request.body.data
for (name, value) in request.headers {
urlRequest.setValue(value, forHTTPHeaderField: name)
}
if let mimeType = request.body.mimeType { if let mimeType = request.body.mimeType {
urlRequest.setValue(mimeType, forHTTPHeaderField: "Content-Type") urlRequest.setValue(mimeType, forHTTPHeaderField: "Content-Type")
} }
@ -397,8 +400,9 @@ public class Client {
pollOptions: [String]? = nil, pollOptions: [String]? = nil,
pollExpiresIn: Int? = nil, pollExpiresIn: Int? = nil,
pollMultiple: Bool? = nil, pollMultiple: Bool? = nil,
localOnly: Bool? = nil /* hometown only, not glitch */) -> Request<Status> { localOnly: Bool? = nil, /* hometown only, not glitch */
return Request<Status>(method: .post, path: "/api/v1/statuses", body: ParametersBody([ idempotencyKey: String) -> Request<Status> {
var req = Request<Status>(method: .post, path: "/api/v1/statuses", body: ParametersBody([
"status" => text, "status" => text,
"content_type" => contentType.mimeType, "content_type" => contentType.mimeType,
"in_reply_to_id" => inReplyTo, "in_reply_to_id" => inReplyTo,
@ -410,6 +414,8 @@ public class Client {
"poll[multiple]" => pollMultiple, "poll[multiple]" => pollMultiple,
"local_only" => localOnly, "local_only" => localOnly,
] + "media_ids" => mediaIDs + "poll[options]" => pollOptions)) ] + "media_ids" => mediaIDs + "poll[options]" => pollOptions))
req.headers["Idempotency-Key"] = idempotencyKey
return req
} }
public static func editStatus( public static func editStatus(

View File

@ -13,6 +13,7 @@ public struct Request<ResultType: Decodable>: Sendable {
let endpoint: Endpoint let endpoint: Endpoint
let body: Body let body: Body
var queryParameters: [Parameter] var queryParameters: [Parameter]
var headers: [String: String] = [:]
var additionalAcceptableHTTPCodes: [Int] = [] var additionalAcceptableHTTPCodes: [Int] = []
init(method: Method, path: Endpoint, body: Body = EmptyBody(), queryParameters: [Parameter] = []) { init(method: Method, path: Endpoint, body: Body = EmptyBody(), queryParameters: [Parameter] = []) {

View File

@ -79,7 +79,14 @@ class ShareViewController: UIViewController {
var attachments: [DraftAttachment] = [] var attachments: [DraftAttachment] = []
for itemProvider in inputItem.attachments ?? [] { for itemProvider in inputItem.attachments ?? [] {
if let attached: NSURL = await getObject(from: itemProvider) { // attachments have the highest priority, but only given this heuristic
// otherwise attachment decoding ends up being overzealous
let likelyAttachment = [UTType.image, .movie].contains(where: { itemProvider.hasItemConformingToTypeIdentifier($0.identifier) })
if likelyAttachment,
let attachment: DraftAttachment = await getObject(from: itemProvider) {
attachments.append(attachment)
} else if let attached: NSURL = await getObject(from: itemProvider) {
if url == nil { if url == nil {
url = attached as URL url = attached as URL
} }
@ -87,8 +94,6 @@ class ShareViewController: UIViewController {
if text.isEmpty { if text.isEmpty {
text = s as String text = s as String
} }
} else if let attachment: DraftAttachment = await getObject(from: itemProvider) {
attachments.append(attachment)
} }
} }