Skip to content

Commit

Permalink
Refactor truncatedEncode calls
Browse files Browse the repository at this point in the history
A few calls have separated the additional
filtering via a variable. This commit merges them
into one line, but still separates the additional filtering
by a line.
  • Loading branch information
MasterJ93 committed May 2, 2024
1 parent a202fa8 commit f14aebc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,9 @@ public struct InterestViewPreferences: Codable {
// Truncate `tags` to 640 characters before encoding.
// `maxGraphemes`'s limit is 64, but `String.count` should respect that limit implictly.
// Then, truncate `tags` to 100 items before encoding.
let truncatedTags = self.tags.map { $0.truncated(toLength: 640) }
try truncatedEncode(truncatedTags, withContainer: &container, forKey: .tags, upToLength: 100)
try truncatedEncode(
self.tags.map { $0.truncated(toLength: 640) },
withContainer: &container, forKey: .tags, upToLength: 100)
}

enum CodingKeys: String, CodingKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ public struct EmbedImagesView: Codable {
/// The identifier of the lexicon.
///
/// - Warning: The value must not change.
public private(set) var type: String = "app.bsky.embed.images#view"
// public let type: String = "app.bsky.embed.images#view"
/// An array of images to be viewed.
public let images: [ViewImage]

public init(images: [ViewImage]) {
self.images = images
}
}

/// A data model for a definition related to viewing an image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ public struct FeedPost: ATRecordProtocol {
// Truncate `tags` to 640 characters before encoding
// `maxGraphemes`'s limit is 64, but `String.count` should respect that limit implictly
// Then, truncate `tags` to 8 items before encoding
let truncatedTags = self.tags.map { $0.truncated(toLength: 640) }
try truncatedEncodeIfPresent(truncatedTags, withContainer: &container, forKey: .tags, upToLength: 8)
try truncatedEncodeIfPresent(
self.tags.map { $0.truncated(toLength: 640) },
withContainer: &container, forKey: .tags, upToLength: 8)

try container.encode(self._createdAt, forKey: .createdAt)
}
Expand Down

0 comments on commit f14aebc

Please sign in to comment.