Use atproto actions with ease in iOS shortcuts
1//
2// MakeAPostIntent.swift
3// shortcut
4//
5// Created by Bailey Townsend on 6/29/25.
6//
7
8// StartMeditationIntent creates a meditation session.
9
10import ATProtoKit
11import AppIntents
12import SwiftData
13
14struct CreateATidIntent: AppIntent {
15
16 @Parameter(
17 title: "Date Source",
18 description: "Choose whether to use the current datetime or specify a date",
19 )
20 var dateSource: DateSource
21
22 @Parameter(
23 title: "DateTime",
24 description:
25 "Creates a TID from the given datetime, if one is not given uses the current devices datetime. For best results make sure you use \"Date Format: Long\" and \"Time Format: Long\" on the date parameter"
26 )
27 var date: Date?
28
29 @Parameter(
30 title: "Clock Identifier",
31 description:
32 "(Optional) Used to create the same TID from the same DateTime. Helpful if you have a record you want to update and used as a unique ID for that record"
33 )
34 var clockIdentifier: Int?
35
36 static let title: LocalizedStringResource =
37 "Create a TID"
38
39 static let description: IntentDescription = IntentDescription(
40 "Creates a TID from the given DateTime, if one is not given uses the current DateTime",
41 resultValueName: "TID"
42 )
43
44 static var parameterSummary: some ParameterSummary {
45 Switch(\.$dateSource) {
46 Case(.currentTime) {
47 Summary("Create a TID from the \(\.$dateSource)") {
48 \.$clockIdentifier
49 }
50 }
51 Case(.specificDate) {
52 Summary("Create a TID from a \(\.$dateSource) using \(\.$date)") {
53 \.$clockIdentifier
54 }
55 }
56 DefaultCase {
57 Summary("Create a TID using \(\.$dateSource)") {
58 \.$clockIdentifier
59 }
60 }
61 }
62
63 }
64 func perform() async throws -> some ReturnsValue<String> {
65
66 var generator: TIDGenerator
67 if var clockIdentifier = self.clockIdentifier {
68 if clockIdentifier > 1023 {
69 clockIdentifier = 23
70 }
71 generator = TIDGenerator(clockIdentifier: UInt16(clockIdentifier))
72 } else {
73 generator = TIDGenerator()
74 }
75
76 if let date = self.date {
77 return .result(value: generator.generateTID(from: date))
78 }
79
80 return .result(value: generator.generateTID())
81 }
82
83}
84
85enum DateSource: String, Codable, Sendable {
86 case currentTime
87 case specificDate
88}
89
90extension DateSource: AppEnum {
91 static var typeDisplayRepresentation: TypeDisplayRepresentation {
92 TypeDisplayRepresentation(
93 name: LocalizedStringResource("Date Source", table: "AppIntents")
94 )
95 }
96
97 static let caseDisplayRepresentations: [DateSource: DisplayRepresentation] = [
98 .currentTime: DisplayRepresentation(
99 title: "Current Date Time",
100 subtitle: "Use the current time",
101 image: .init(systemName: "clock")
102 ),
103 .specificDate: DisplayRepresentation(
104 title: "Specific Date Time",
105 subtitle: "Provide a specific date and time",
106 image: .init(systemName: "calendar")
107 ),
108 ]
109}