diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index a972ca1..222bfb1 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -18,7 +18,6 @@ A924C3732EA9127200F20781 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924C3712EA9127200F20781 /* Emoji.swift */; }; A924C3782EA9225800F20781 /* Haptics in Frameworks */ = {isa = PBXBuildFile; productRef = A924C3772EA9225800F20781 /* Haptics */; }; A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */; }; - A940FE3D2EA232590016870B /* ApiEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A940FE3C2EA232590016870B /* ApiEmoji.swift */; }; A949B1F32EA04E8200215164 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A949B1EF2EA04E8200215164 /* Assets.xcassets */; }; A949B1F42EA04E8200215164 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F02EA04E8200215164 /* ContentView.swift */; }; A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F12EA04E8200215164 /* StickerSlackApp.swift */; }; @@ -31,7 +30,6 @@ A986A6C22EB6597600B6E0FA /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924C3712EA9127200F20781 /* Emoji.swift */; }; A986A6C32EB6598100B6E0FA /* FilterCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */; }; A986A6C42EB6598500B6E0FA /* SlackResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1FA2EA0518800215164 /* SlackResponse.swift */; }; - A986A6C52EB6599700B6E0FA /* ApiEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A940FE3C2EA232590016870B /* ApiEmoji.swift */; }; A986A6CD2EB659E000B6E0FA /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A986A6CA2EB659E000B6E0FA /* MessagesViewController.swift */; }; A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */; }; A986A6CF2EB659E000B6E0FA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A986A6C62EB659E000B6E0FA /* Assets.xcassets */; }; @@ -41,7 +39,6 @@ A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A924C3712EA9127200F20781 /* Emoji.swift */; }; A9B9A8312EB2CD14004C9245 /* FilterCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */; }; A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1FA2EA0518800215164 /* SlackResponse.swift */; }; - A9B9A8332EB2CD4B004C9245 /* ApiEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A940FE3C2EA232590016870B /* ApiEmoji.swift */; }; A9D15B8B2EB1142C00404792 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; /* End PBXBuildFile section */ @@ -83,7 +80,6 @@ A924C3712EA9127200F20781 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = ""; }; A924C3742EA9134C00F20781 /* StickerSlack.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StickerSlack.entitlements; sourceTree = ""; }; A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCategory.swift; sourceTree = ""; }; - A940FE3C2EA232590016870B /* ApiEmoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiEmoji.swift; sourceTree = ""; }; A949B1DF2EA04C0B00215164 /* StickerSlack.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StickerSlack.app; sourceTree = BUILT_PRODUCTS_DIR; }; A949B1EF2EA04E8200215164 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A949B1F02EA04E8200215164 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -201,7 +197,6 @@ isa = PBXGroup; children = ( A949B1FA2EA0518800215164 /* SlackResponse.swift */, - A940FE3C2EA232590016870B /* ApiEmoji.swift */, A924C3712EA9127200F20781 /* Emoji.swift */, A9D15B892EB1142C00404792 /* EmojiPack.swift */, A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */, @@ -387,7 +382,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - A940FE3D2EA232590016870B /* ApiEmoji.swift in Sources */, A949B1F42EA04E8200215164 /* ContentView.swift in Sources */, A949B1F52EA04E8200215164 /* StickerSlackApp.swift in Sources */, A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, @@ -407,7 +401,6 @@ A986A6C32EB6598100B6E0FA /* FilterCategory.swift in Sources */, A986A6CD2EB659E000B6E0FA /* MessagesViewController.swift in Sources */, A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */, - A986A6C52EB6599700B6E0FA /* ApiEmoji.swift in Sources */, A986A6C42EB6598500B6E0FA /* SlackResponse.swift in Sources */, A986A6C22EB6597600B6E0FA /* Emoji.swift in Sources */, A986A6C12EB6595F00B6E0FA /* EmojiHoarder.swift in Sources */, @@ -424,7 +417,6 @@ A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */, A9B9A82E2EB2CCBE004C9245 /* StickerSlackTests.swift in Sources */, A9B9A8312EB2CD14004C9245 /* FilterCategory.swift in Sources */, - A9B9A8332EB2CD4B004C9245 /* ApiEmoji.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/StickerSlack/Emoji/ApiEmoji.swift b/StickerSlack/Emoji/ApiEmoji.swift deleted file mode 100644 index 3af9e18..0000000 --- a/StickerSlack/Emoji/ApiEmoji.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// Emoji.swift -// StickerSlack -// -// Created by neon443 on 17/10/2025. -// - -import Foundation -import SwiftUI - -protocol EmojiProtocol: Codable, Hashable { - var name: String { get set } - var urlString: String { get set } -} - -struct ApiEmoji: EmojiProtocol { - var name: String - var urlString: String - - var url: URL { - return URL(string: urlString) ?? URL(string: "https://")! - } - - init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - self.init( - name: try container.decode(String.self, forKey: .name), - url: try container.decode(String.self, forKey: .urlString) - ) - } - - init( - name: String, - url: String, - ) { - self.name = name - self.urlString = url - } - - enum CodingKeys: CodingKey { - case name - case urlString - } - - func toEmoji(withID: UUID = UUID()) -> Emoji { - return Emoji(apiEmoji: self, id: withID) - } - - func encode(to encoder: any Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(self.name, forKey: .name) - try container.encode(self.urlString, forKey: .urlString) - } -} - diff --git a/StickerSlack/Emoji/Emoji.swift b/StickerSlack/Emoji/Emoji.swift index 977a3e4..0eaed48 100644 --- a/StickerSlack/Emoji/Emoji.swift +++ b/StickerSlack/Emoji/Emoji.swift @@ -61,13 +61,14 @@ struct Emoji: Codable, Identifiable, Hashable { } init( - apiEmoji: ApiEmoji, + name: String, + url: URL, id: UUID = UUID() ) { self.id = id self.uiID = id - self.name = apiEmoji.name - self.remoteImageURL = apiEmoji.url + self.name = name + self.remoteImageURL = url } func downloadImage() async throws -> UIImage { diff --git a/StickerSlack/Emoji/SlackResponse.swift b/StickerSlack/Emoji/SlackResponse.swift index 9fbe1e5..f3e4d00 100644 --- a/StickerSlack/Emoji/SlackResponse.swift +++ b/StickerSlack/Emoji/SlackResponse.swift @@ -17,10 +17,11 @@ struct SlackResponse: Identifiable, Codable { static func toEmojis(from response: [SlackResponse]?) -> [Emoji]? { guard let response else { return nil } return response.map { item in - ApiEmoji( + Emoji( name: item.name, - url: item.imageUrl - ).toEmoji(withID: item.id) + url: URL(string: item.imageUrl)!, + id: item.id + ) } } } diff --git a/StickerSlack/Views/EmojiPreview.swift b/StickerSlack/Views/EmojiPreview.swift index 535d0c0..aac1052 100644 --- a/StickerSlack/Views/EmojiPreview.swift +++ b/StickerSlack/Views/EmojiPreview.swift @@ -62,9 +62,9 @@ struct EmojiPreview: View { #Preview { EmojiPreview( - emoji: ApiEmoji( + emoji: Emoji( name: "s?", - url: "https://neon443.github.io/images/fav.ico" - ).toEmoji() + url: URL(string: "https://neon443.github.io/images/fav.ico")! + ) ) } diff --git a/StickerSlackTests/StickerSlackTests.swift b/StickerSlackTests/StickerSlackTests.swift index f61b2ae..95baf0c 100644 --- a/StickerSlackTests/StickerSlackTests.swift +++ b/StickerSlackTests/StickerSlackTests.swift @@ -8,38 +8,23 @@ import Testing import Foundation -struct ApiEmojiTests { - @Test func ApiEmojiEncode() async throws { - let apiEmoji = ApiEmoji(name: "name", url: "https://") - let encoded = try! JSONEncoder().encode(apiEmoji) - let decoded = try! JSONDecoder().decode(ApiEmoji.self, from: encoded) - #expect(decoded == apiEmoji) - } - - @Test func ApiEmojiEncoder() async throws { - let json = "{\"name\":\"name\",\"urlString\":\"https:\\/\\/\"}" - let decoded = try! JSONDecoder().decode(ApiEmoji.self, from: json.data(using: .utf8)!) - let expected = ApiEmoji(name: "name", url: "https://") - #expect(expected == ApiEmoji(name: "name", url: "https://")) - } - - @Test func ApiEmojiToEmoji() async throws { - let apiEmoji = ApiEmoji(name: "name", url: "https://") - let emoji = apiEmoji.toEmoji() - let expected = Emoji(apiEmoji: apiEmoji, id: emoji.id) - #expect(emoji == expected) - } -} - struct StickerSlackTests { var hoarder = EmojiHoarder() @Test func MSStickerValidation() async throws { - let goodEmoji = Emoji(apiEmoji: ApiEmoji(name: "name", url: "https://neon443.github.io/images/fav.ico"), id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")!) + let goodEmoji = Emoji( + name: "name", + url: URL(string: "https://neon443.github.io/images/fav.ico")!, + id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")! + ) let _ = try! await goodEmoji.downloadImage() #expect(goodEmoji.sticker!.validate(), "should be true") - let badEmoji = Emoji(apiEmoji: ApiEmoji(name: "160chars:shttps://emoji.slack-edge.com/T0266FRGM/100906/ddeb22d813b83b0f.pngs,sexpirationfds2025-10-28T08:00:02.011Zs},{gtypeh:jemojieeeidggg9cab2003-ad74-492a-", url: "https://files.catbox.moe/ifh710.png"), id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")!) + let badEmoji = Emoji( + name: "160chars:shttps://emoji.slack-edge.com/T0266FRGM/100906/ddeb22d813b83b0f.pngs,sexpirationfds2025-10-28T08:00:02.011Zs},{gtypeh:jemojieeeidggg9cab2003-ad74-492a-", + url: URL(string: "https://files.catbox.moe/ifh710.png")!, + id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")! + ) let _ = try! await badEmoji.downloadImage() #expect(goodEmoji.sticker!.validate(), "should be true") badEmoji.deleteImage()