Skip to content

Commit

Permalink
1.3.1 (mlemgroup#1081)
Browse files Browse the repository at this point in the history
Co-authored-by: Sjmarf <[email protected]>
  • Loading branch information
EricBAndrews and Sjmarf authored Jun 2, 2024
1 parent e506ba1 commit 66c03b7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4610,7 +4610,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -4653,7 +4653,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
"revision" : "ecb18d8ce4d88277cc4fb103973352d91e18c535"
}
},
{
"identity" : "networkimage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gonzalezreal/NetworkImage",
"state" : {
"revision" : "7aff8d1b31148d32c5933d75557d42f6323ee3d1",
"version" : "6.0.0"
}
},
{
"identity" : "nuke",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kean/Nuke",
"state" : {
"revision" : "989586f86b683680f7bd5765d6a5683edbea0c1b",
"version" : "12.1.4"
"revision" : "8e431251dea0081b6ab154dab61a6ec74e4b6577",
"version" : "12.6.0"
}
},
{
Expand Down Expand Up @@ -68,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/gonzalezreal/swift-markdown-ui.git",
"state" : {
"revision" : "12b351a75201a8124c2f2e1f9fc6ef5cd812c0b9",
"version" : "2.1.0"
"revision" : "ae799d015a5374708f7b4c85f3294c05f2a564e2",
"version" : "2.3.0"
}
},
{
Expand Down
9 changes: 7 additions & 2 deletions Mlem/API/APIClient/APIClient+Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ extension APIClient {

// swiftlint:enable function_parameter_count

func markPostAsRead(for postId: Int, read: Bool) async throws -> SuccessResponse {
let request = try MarkPostReadRequest(session: session, postId: postId, read: read)
func markPostAsRead(for postId: Int, read: Bool, version: SiteVersion?) async throws -> SuccessResponse {
let request: MarkPostReadRequest
if (version ?? .infinity) < .init("0.19.0") {
request = try MarkPostReadRequest(session: session, postId: postId, read: read)
} else {
request = try MarkPostReadRequest(session: session, postIds: [postId], read: read)
}
// TODO: 0.18 deprecation simply return result of perform
let compatibilityResponse = try await perform(request: request)
return SuccessResponse(from: compatibilityResponse)
Expand Down
3 changes: 2 additions & 1 deletion Mlem/API/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ extension APIClientError: CustomStringConvertible {
case .invalidSession:
return "Invalid session"
case let .decoding(data, error):
guard let string = String(data: data, encoding: .utf8) else {
let string = String(decoding: data, as: UTF8.self)
guard !string.isEmpty else {
return localizedDescription
}

Expand Down
5 changes: 4 additions & 1 deletion Mlem/Extensions/String/String+WithEscapedCharacters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ extension String {
func withEscapedCharacters() -> String? {
do {
let jsonRepresentation = try JSONEncoder().encode(self)
return String(data: jsonRepresentation, encoding: .utf8)
let ret = String(decoding: jsonRepresentation, as: UTF8.self)
// slightly awkward but preserves contract
if !ret.isEmpty { return ret }
return nil
} catch {
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion Mlem/Logic/InstanceMetadataParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct InstanceMetadataParser {
// MARK: - Public Methods

static func parse(from data: Data) throws -> [InstanceMetadata] {
guard let string = String(data: data, encoding: .utf8), !string.isEmpty else {
let string = String(decoding: data, as: UTF8.self)
guard !string.isEmpty else {
throw ParsingError.invalidData
}

Expand Down
6 changes: 5 additions & 1 deletion Mlem/Models/Content/Post/PostModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ class PostModel: ContentIdentifiable, Removable, Purgable, ObservableObject {

// API call
do {
let updatedPost = try await postRepository.markRead(post: self, read: newRead)
let updatedPost = try await postRepository.markRead(
post: self,
read: newRead,
version: SiteInformationTracker.liveValue.version
)
await reinit(from: updatedPost)
} catch {
hapticManager.play(haptic: .failure, priority: .high)
Expand Down
4 changes: 2 additions & 2 deletions Mlem/Repositories/PictrsRespository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PictrsRespository {
print("Upload failed (2): \(error)")
switch error {
case let APIClientError.decoding(data, _):
let text = String(data: data, encoding: .utf8)
if text?.contains("413 Request Entity Too Large") ?? false {
let text = String(decoding: data, as: UTF8.self)
if text.contains("413 Request Entity Too Large") {
imageModel.state = .failed("Image too large")
} else {
imageModel.state = .failed(text)
Expand Down
8 changes: 6 additions & 2 deletions Mlem/Repositories/PostRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ class PostRepository {
/// - Parameters:
/// - post: PostModel to attempt to read
/// - read: Intended read state of the post model (true to mark read, false to mark unread)
func markRead(post: PostModel, read: Bool) async throws -> PostModel {
let success = try await apiClient.markPostAsRead(for: post.postId, read: read).success
func markRead(post: PostModel, read: Bool, version: SiteVersion?) async throws -> PostModel {
let success = try await apiClient.markPostAsRead(
for: post.postId,
read: read,
version: version
).success
return PostModel(from: post, read: success ? read : post.read)
}

Expand Down
3 changes: 2 additions & 1 deletion Mlem/Views/Shared/Instance/InstanceView+Logic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extension InstanceView {
}
} catch let APIClientError.decoding(data, error) {
withAnimation(.easeOut(duration: 0.2)) {
if let content = String(data: data, encoding: .utf8) {
let content = String(decoding: data, as: UTF8.self)
if !content.isEmpty {
if content.contains("<div class=\"kbin-container\">") {
errorDetails = ErrorDetails(
title: "KBin Instance",
Expand Down
8 changes: 4 additions & 4 deletions MlemTests/Parsers/InstanceMetadataParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import XCTest
final class InstanceMetadataParserTests: XCTestCase {
func testParserHandlesExpectedData() throws {
// construct some test data
let data = """
let data = Data("""
Instance,NU,NC,Fed,Adult,↓V,Users,BI,BB,UT,MO,Version
[Lemmy.world](https://lemmy.world),Yes,Yes,Yes,Yes,Yes,18431,53,3,97%,2,0.18.4
[lemm.ee](https://lemm.ee),Yes,No,Yes,No,Yes,3710,34,0,100%,2,0.1.2
""".data(using: .utf8)!
""".utf8)

// ask the parser to parse it
let metadata = try InstanceMetadataParser.parse(from: data)
Expand Down Expand Up @@ -57,11 +57,11 @@ final class InstanceMetadataParserTests: XCTestCase {

func testParserIsNotReliantOnHeaderFieldOrder() throws {
// construct some test data with some the fields moved around
let data = """
let data = Data("""
Users,NU,NC,Fed,Version,Adult,↓V,BI,BB,UT,MO,Instance
18431,Yes,Yes,Yes,0.18.4,Yes,Yes,53,3,97%,2,[Lemmy.world](https://lemmy.world)
3710,Yes,No,Yes,0.1.2,No,Yes,34,0,100%,2,[lemm.ee](https://lemm.ee)
""".data(using: .utf8)!
""".utf8)

// ask the parser to parse it
let metadata = try InstanceMetadataParser.parse(from: data)
Expand Down

0 comments on commit 66c03b7

Please sign in to comment.