Something went wrong. Try again.
Something went wrong. Try again.
2.6 kB · 84 lines
Swift
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485//// UserAccountParameter.swift// shortcut//// Created by Bailey Townsend on 6/29/25.//
import AppIntentsimport Foundation
struct AtIdentifierAppEntity: AppEntity { //The users handle var id: UUID
@Property var handle: String
@Property var did: String
static var typeDisplayName: LocalizedStringResource = "Saved AT Identifier"
static var typeDescription: LocalizedStringResource? = "This is your saved user session that is created inside of the app"
var displayRepresentation: AppIntents.DisplayRepresentation { DisplayRepresentation(title: LocalizedStringResource(stringLiteral: handle)) }
static var typeDisplayRepresentation: TypeDisplayRepresentation = TypeDisplayRepresentation( name: LocalizedStringResource("AT Identifier"))
static var defaultQuery = AtIdentifierAppEntityQuery()}
struct AtIdentifierAppEntityQuery: EntityQuery {
func entities(for identifiers: [UUID]) async throws -> [AtIdentifierAppEntity] { let atProtocolManager = AtProtocolManager() do { let sessions = try await atProtocolManager.getSessions(sessionIDs: identifiers) if sessions.isEmpty { return []
} return sessions.map { session in let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) userAccount.handle = session.handle userAccount.did = session.sessionDID return userAccount } } // return identifiers.compactMap { SessionManager.session(for: $0) }
catch { print(error) throw GenericIntentError.message( "Could not retrieve saved AT Identifiers. Please make sure you have logged in via the app" ) } }
func suggestedEntities() async throws -> [AtIdentifierAppEntity] {
let atProtocolManager = AtProtocolManager() do { let sessions = try await atProtocolManager.getAllSessions() if sessions.isEmpty { return [] } return sessions.map { session in let userAccount: AtIdentifierAppEntity = AtIdentifierAppEntity(id: session.id) userAccount.handle = session.handle userAccount.did = session.sessionDID return userAccount } }
catch { throw GenericIntentError.message( "Could not retrieve saved AT Identifiers. Please make sure you have logged in via the app" ) } }}