Skip to content

Commit

Permalink
Eric/master hotfix (#626)
Browse files Browse the repository at this point in the history
Co-authored-by: mormaer <[email protected]>
  • Loading branch information
EricBAndrews and mormaer authored Sep 19, 2023
1 parent af3722a commit a659894
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 57 deletions.
96 changes: 96 additions & 0 deletions Brewfile.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"entries": {
"brew": {
"swiftlint": {
"version": "0.52.4",
"bottle": {
"rebuild": 1,
"root_url": "https://ghcr.io/v2/homebrew/core",
"files": {
"arm64_ventura": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:718f5989e0909ea736848e0d6f32d07cfa20bb23cab5fb9989803872e88d1a29",
"sha256": "718f5989e0909ea736848e0d6f32d07cfa20bb23cab5fb9989803872e88d1a29"
},
"arm64_monterey": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:bcc2c13aa6c01634b382991df048bb331caa5eec230fff33ddbab19258a30c22",
"sha256": "bcc2c13aa6c01634b382991df048bb331caa5eec230fff33ddbab19258a30c22"
},
"ventura": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:5aec3b872abfead26c702334f0cffddb8ea653481720d7c1248ad836be37a975",
"sha256": "5aec3b872abfead26c702334f0cffddb8ea653481720d7c1248ad836be37a975"
},
"monterey": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:e3171413a8649150601f777176af1dae458cb4be35aa1185e31636db1bb7124a",
"sha256": "e3171413a8649150601f777176af1dae458cb4be35aa1185e31636db1bb7124a"
},
"x86_64_linux": {
"cellar": "/home/linuxbrew/.linuxbrew/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:e8ec45e149d2e33295ddcd87a142389492176b51d0c2216127ae00d3ade33a6b",
"sha256": "e8ec45e149d2e33295ddcd87a142389492176b51d0c2216127ae00d3ade33a6b"
}
}
}
},
"swiftformat": {
"version": "0.52.2",
"bottle": {
"rebuild": 0,
"root_url": "https://ghcr.io/v2/homebrew/core",
"files": {
"arm64_ventura": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:365be8eeb9ac865a41f06e0a42934fff1ab9a4c7d4eeb425542188c8af523ecf",
"sha256": "365be8eeb9ac865a41f06e0a42934fff1ab9a4c7d4eeb425542188c8af523ecf"
},
"arm64_monterey": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:19fed428d1201e6211c687604982ce288d4b87dd7ff4da1fd5db01efaaada8ae",
"sha256": "19fed428d1201e6211c687604982ce288d4b87dd7ff4da1fd5db01efaaada8ae"
},
"arm64_big_sur": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:a410d04988d771f4022b910e3d3a68429d4cd91e402d97885a70999fc5dffa7a",
"sha256": "a410d04988d771f4022b910e3d3a68429d4cd91e402d97885a70999fc5dffa7a"
},
"ventura": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:6e09bc4b333edebebd6eb01d5e5a7d370b1f252933b55da5ab2b1c6755c7dd57",
"sha256": "6e09bc4b333edebebd6eb01d5e5a7d370b1f252933b55da5ab2b1c6755c7dd57"
},
"monterey": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:cb38dffa5947928e8f84b70cf280d63f1d740a4ca46c7b91764cd88582acb57d",
"sha256": "cb38dffa5947928e8f84b70cf280d63f1d740a4ca46c7b91764cd88582acb57d"
},
"big_sur": {
"cellar": ":any_skip_relocation",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:d03cfd926f3ca6dc5e0851d46def2fbb9a1639a197bd9ab5f8108064d6e40621",
"sha256": "d03cfd926f3ca6dc5e0851d46def2fbb9a1639a197bd9ab5f8108064d6e40621"
},
"x86_64_linux": {
"cellar": "/home/linuxbrew/.linuxbrew/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/swiftformat/blobs/sha256:601170208546fac087ed96fa9fdddf26e46b5e45bd10a8bfa3248fbe4480a09d",
"sha256": "601170208546fac087ed96fa9fdddf26e46b5e45bd10a8bfa3248fbe4480a09d"
}
}
}
}
}
},
"system": {
"macos": {
"ventura": {
"HOMEBREW_VERSION": "4.1.6",
"HOMEBREW_PREFIX": "/opt/homebrew",
"Homebrew/homebrew-core": "api",
"CLT": "14.2.0.0.1.1668646533",
"Xcode": "14.3.1",
"macOS": "13.1"
}
}
}
}
20 changes: 18 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
5016A2B32A67EC0700B257E8 /* NotificationDisplayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016A2B22A67EC0700B257E8 /* NotificationDisplayer.swift */; };
503A5D752A78EF3C00488C38 /* Encodable+Export.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503A5D742A78EF3C00488C38 /* Encodable+Export.swift */; };
503BA26F2A2C94540052516C /* URL+Identifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503BA26E2A2C94540052516C /* URL+Identifiable.swift */; };
504ECBAE2AB45B2A006C0B96 /* LemmyURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBAD2AB45B2A006C0B96 /* LemmyURL.swift */; };
504ECBB12AB4B101006C0B96 /* LemmyURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBB02AB4B101006C0B96 /* LemmyURLTests.swift */; };
5064D03D2A6DE0AA00B22EE3 /* Notifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5064D03C2A6DE0AA00B22EE3 /* Notifier.swift */; };
5064D03F2A6DE0DB00B22EE3 /* Notifier+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5064D03E2A6DE0DB00B22EE3 /* Notifier+Dependency.swift */; };
5064D0412A6E63E000B22EE3 /* Task+Notifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5064D0402A6E63E000B22EE3 /* Task+Notifiable.swift */; };
Expand Down Expand Up @@ -405,6 +407,8 @@
5016A2B22A67EC0700B257E8 /* NotificationDisplayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationDisplayer.swift; sourceTree = "<group>"; };
503A5D742A78EF3C00488C38 /* Encodable+Export.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Encodable+Export.swift"; sourceTree = "<group>"; };
503BA26E2A2C94540052516C /* URL+Identifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Identifiable.swift"; sourceTree = "<group>"; };
504ECBAD2AB45B2A006C0B96 /* LemmyURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LemmyURL.swift; sourceTree = "<group>"; };
504ECBB02AB4B101006C0B96 /* LemmyURLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LemmyURLTests.swift; sourceTree = "<group>"; };
5064D03C2A6DE0AA00B22EE3 /* Notifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifier.swift; sourceTree = "<group>"; };
5064D03E2A6DE0DB00B22EE3 /* Notifier+Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notifier+Dependency.swift"; sourceTree = "<group>"; };
5064D0402A6E63E000B22EE3 /* Task+Notifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Task+Notifiable.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -893,6 +897,14 @@
path = TabBar;
sourceTree = "<group>";
};
504ECBAF2AB4B0DF006C0B96 /* Model */ = {
isa = PBXGroup;
children = (
504ECBB02AB4B101006C0B96 /* LemmyURLTests.swift */,
);
path = Model;
sourceTree = "<group>";
};
5064D03B2A6DE05000B22EE3 /* Notifications */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1249,6 +1261,7 @@
6363D5D927EE196A00E34822 /* MlemTests */ = {
isa = PBXGroup;
children = (
504ECBAF2AB4B0DF006C0B96 /* Model */,
50DBB8DE2A805770002870B1 /* Mocks */,
50C86AB82A7E507200277519 /* Persistence */,
6363D5DA27EE196A00E34822 /* MlemTests.swift */,
Expand Down Expand Up @@ -1310,6 +1323,7 @@
isa = PBXGroup;
children = (
637218032A3A2AAD008C4816 /* HierarchicalComment.swift */,
504ECBAD2AB45B2A006C0B96 /* LemmyURL.swift */,
);
path = Internal;
sourceTree = "<group>";
Expand Down Expand Up @@ -2254,6 +2268,7 @@
6D405B032A43E7DB00C65F9C /* Sidebar Header Label.swift in Sources */,
50C99B5E2A61F611005D57DD /* CommentRepository+Dependency.swift in Sources */,
632578182A29F83C00446A66 /* PostSortMenu.swift in Sources */,
504ECBAE2AB45B2A006C0B96 /* LemmyURL.swift in Sources */,
CDA217EA2A63093E00BDA173 /* ReportComment.swift in Sources */,
CDA217E82A63029B00BDA173 /* ReportMention.swift in Sources */,
508845CF2A3641160088E483 /* JSONDecoder+Default.swift in Sources */,
Expand Down Expand Up @@ -2487,6 +2502,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
504ECBB12AB4B101006C0B96 /* LemmyURLTests.swift in Sources */,
50DBB8E02A805836002870B1 /* MockErrorHandler.swift in Sources */,
6363D5DB27EE196A00E34822 /* MlemTests.swift in Sources */,
50DBB8E22A80F9E4002870B1 /* APICommunity+Mock.swift in Sources */,
Expand Down Expand Up @@ -2663,7 +2679,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -2704,7 +2720,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
27 changes: 27 additions & 0 deletions Mlem/API/Internal/LemmyURL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// LemmyURL.swift
// Mlem
//
// Created by mormaer on 15/09/2023.
//
//

import Foundation

struct LemmyURL {
let url: URL

init?(string: String?) {
guard let string else {
return nil
}

if let url = URL(string: string) {
self.url = url
} else if let encoded = string.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed), let url = URL(string: encoded) {
self.url = url
} else {
return nil
}
}
}
9 changes: 7 additions & 2 deletions Mlem/API/Models/Community/APICommunity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct APICommunity: Codable, Identifiable {
let nsfw: Bool
let actorId: URL
let local: Bool
let icon: URL?
let banner: URL?
let icon: String?
let banner: String?
let hidden: Bool
let postingRestrictedToMods: Bool
let instanceId: Int
Expand All @@ -44,3 +44,8 @@ extension APICommunity: Comparable {
return lhsFullCommunity < rhsFullCommunity
}
}

extension APICommunity {
var iconUrl: URL? { LemmyURL(string: icon)?.url }
var bannerUrl: URL? { LemmyURL(string: banner)?.url }
}
14 changes: 10 additions & 4 deletions Mlem/API/Models/Person/APIPerson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ struct APIPerson: Decodable, Identifiable, Hashable {
let id: Int
let name: String
let displayName: String?
let avatar: URL?
let avatar: String?
let banned: Bool
let published: Date
let updated: Date?
let actorId: URL
let bio: String?
let local: Bool
let banner: URL?
let banner: String?
let deleted: Bool
let sharedInboxUrl: URL?
let sharedInboxUrl: String?
let matrixUserId: String?
let admin: Bool
let admin: Bool? // this is no longer returned on beehaw...
let botAccount: Bool
let banExpires: Date?
let instanceId: Int
Expand All @@ -34,3 +34,9 @@ extension APIPerson: Equatable {
lhs.actorId == rhs.actorId
}
}

extension APIPerson {
var avatarUrl: URL? { LemmyURL(string: avatar)?.url }
var bannerUrl: URL? { LemmyURL(string: banner)?.url }
var sharedInboxLink: URL? { LemmyURL(string: sharedInboxUrl)?.url }
}
9 changes: 7 additions & 2 deletions Mlem/API/Models/Posts/APIPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
struct APIPost: Decodable {
let id: Int
let name: String
let url: URL?
let url: String?
let body: String?
let creatorId: Int
let communityId: Int
Expand All @@ -28,10 +28,15 @@ struct APIPost: Decodable {
let nsfw: Bool
let published: Date
let removed: Bool
let thumbnailUrl: URL?
let thumbnailUrl: String?
let updated: Date?
}

extension APIPost {
var linkUrl: URL? { LemmyURL(string: url)?.url }
var thumbnailImageUrl: URL? { LemmyURL(string: thumbnailUrl)?.url }
}

extension APIPost: Equatable {
static func == (lhs: APIPost, rhs: APIPost) -> Bool {
lhs.id == rhs.id
Expand Down
6 changes: 5 additions & 1 deletion Mlem/API/Models/Posts/APIPostReport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ struct APIPostReport: Decodable {
let creatorId: Int
let postId: Int
let originalPostName: String
let originalPostUrl: URL?
let originalPostUrl: String?
let originalPostBody: String?
let reason: String
let resolved: Bool
let resolverId: Int?
let published: Date
let updated: Date?
}

extension APIPostReport {
var originalUrl: URL? { LemmyURL(string: originalPostUrl)?.url }
}
9 changes: 7 additions & 2 deletions Mlem/API/Models/Site/APISite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ struct APISite: Decodable {
let name: String
let sidebar: String?
let published: Date
let icon: URL?
let banner: URL?
let icon: String?
let banner: String?
let description: String?
let actorId: String?
let lastRefreshedAt: Date
let inboxUrl: String
let publicKey: String
let instanceId: Int
}

extension APISite {
var iconUrl: URL? { LemmyURL(string: icon)?.url }
var bannerUrl: URL? { LemmyURL(string: banner)?.url }
}
4 changes: 2 additions & 2 deletions Mlem/Extensions/API Post View - Post Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Foundation
extension APIPostView {
var postType: PostType {
// post with URL: either image or link
if let postUrl = post.url {
if let postUrl = post.linkUrl {
// if image, return image link, otherwise return thumbnail
return postUrl.isImage ? .image(postUrl) : .link(post.thumbnailUrl)
return postUrl.isImage ? .image(postUrl) : .link(post.thumbnailImageUrl)
}

// otherwise text, but post.body needs to be present, even if it's an empty string
Expand Down
29 changes: 14 additions & 15 deletions Mlem/Extensions/JSONDecoder+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@ extension JSONDecoder {
static var defaultDecoder: JSONDecoder {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

let formatter = DateFormatter()

formatter.timeZone = .gmt
formatter.locale = Locale(identifier: "en_US_POSIX")


let formats = [
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS",
"yyyy-MM-dd'T'HH:mm:ss.SSSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSS",
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd HH:mm:ss.SSSSSS",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd"
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss"
]

let formatters = formats.map { format in
let formatter = DateFormatter()
formatter.timeZone = .gmt
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = format
return formatter
}

decoder.dateDecodingStrategy = .custom({ decoder in
let container = try decoder.singleValueContainer()
let string = try container.decode(String.self)

for format in formats {
formatter.dateFormat = format
for formatter in formatters {
if let date = formatter.date(from: string) {
return date
}
}

// after some discussion we've agreed to fail the modelling if the date
// does match either of the above, as based on the current API source code
// does match _any_ of the above, as based on the current API source code
// it should be one of those
throw Swift.DecodingError.dataCorrupted(
.init(codingPath: container.codingPath,
Expand Down
Loading

0 comments on commit a659894

Please sign in to comment.