removed ApiEmoji cos its not used

This commit is contained in:
neon443
2025-11-02 20:28:59 +00:00
parent ae202380a2
commit 4b32a9e6ae
6 changed files with 21 additions and 97 deletions

View File

@@ -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 = "<group>"; };
A924C3742EA9134C00F20781 /* StickerSlack.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StickerSlack.entitlements; sourceTree = "<group>"; };
A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCategory.swift; sourceTree = "<group>"; };
A940FE3C2EA232590016870B /* ApiEmoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiEmoji.swift; sourceTree = "<group>"; };
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 = "<group>"; };
A949B1F02EA04E8200215164 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -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;
};

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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
)
}
}
}

View File

@@ -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")!
)
)
}

View File

@@ -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()