From 10b1ffc67a3e8ec2768d120e86bd482bcc22d4e5 Mon Sep 17 00:00:00 2001 From: Thomas Rademaker Date: Mon, 11 May 2026 18:31:01 -0400 Subject: [PATCH] Add optional createdAt to putEpisodeState so updates preserve the record's original creation time --- Sources/EffemKit/EffemRepoService.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/EffemKit/EffemRepoService.swift b/Sources/EffemKit/EffemRepoService.swift index 9e21f82..9115989 100644 --- a/Sources/EffemKit/EffemRepoService.swift +++ b/Sources/EffemKit/EffemRepoService.swift @@ -240,6 +240,10 @@ public struct EffemRepoService: Sendable { // MARK: - Episode States /// Creates or updates an episode state record in the user's AT Proto repo. + /// + /// Pass `createdAt` with the value from the existing record on subsequent + /// updates so the original creation timestamp is preserved; pass `nil` on + /// the first write to use the current time. public func putEpisodeState( episode: EpisodeRef, positionS: Int? = nil, @@ -247,19 +251,21 @@ public struct EffemRepoService: Sendable { played: Bool? = nil, saved: Bool? = nil, hidden: Bool? = nil, + createdAt: String? = nil, repo: String ) async throws -> CreateRecordResponse { + let now = Self.now() var record: [String: Any] = [ "$type": "xyz.effem.feed.episodeState", "episode": episode.toRecord(), - "createdAt": Self.now(), + "createdAt": createdAt ?? now, ] if let positionS { record["positionS"] = positionS } if let durationS { record["durationS"] = durationS } if let played { record["played"] = played } if let saved { record["saved"] = saved } if let hidden { record["hidden"] = hidden } - record["updatedAt"] = Self.now() + record["updatedAt"] = now let body: [String: Any] = [ "repo": repo, -- 2.51.2