diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 7ed474e..157620f 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ A969D6AE2EA3F1AF00399C05 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A969D6A92EA3F1AF00399C05 /* MainInterface.storyboard */; }; A969D6AF2EA3F1AF00399C05 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */; }; A9773C2F2EA54AF000F3B753 /* EmojiPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */; }; + A9B9A81C2EB2BCE4004C9245 /* StickerBrowserDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */; }; + A9B9A81E2EB2BEF1004C9245 /* StickerBroswerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */; }; A9BE06DB2EA656B80033B213 /* EmojiHoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1F72EA04F2300215164 /* EmojiHoarder.swift */; }; A9BE06DC2EA657C70033B213 /* ApiEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A940FE3C2EA232590016870B /* ApiEmoji.swift */; }; A9BE06DD2EA657CF0033B213 /* SlackResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A949B1FA2EA0518800215164 /* SlackResponse.swift */; }; @@ -75,6 +77,8 @@ A969D6A82EA3F1AF00399C05 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = ""; }; A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPreview.swift; sourceTree = ""; }; + A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBrowserDataSource.swift; sourceTree = ""; }; + A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerBroswerViewController.swift; sourceTree = ""; }; A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -176,6 +180,8 @@ A969D6A72EA3F1AF00399C05 /* Info.plist */, A969D6A92EA3F1AF00399C05 /* MainInterface.storyboard */, A969D6AA2EA3F1AF00399C05 /* MessagesViewController.swift */, + A9B9A81B2EB2BCE4004C9245 /* StickerBrowserDataSource.swift */, + A9B9A81D2EB2BEF1004C9245 /* StickerBroswerViewController.swift */, ); path = StickerSlackiMessageExtension; sourceTree = ""; @@ -307,11 +313,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A9B9A81E2EB2BEF1004C9245 /* StickerBroswerViewController.swift in Sources */, A924C3722EA9127200F20781 /* Emoji.swift in Sources */, A9BE06DC2EA657C70033B213 /* ApiEmoji.swift in Sources */, A9BE06DB2EA656B80033B213 /* EmojiHoarder.swift in Sources */, A935437C2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */, A969D6AF2EA3F1AF00399C05 /* MessagesViewController.swift in Sources */, + A9B9A81C2EB2BCE4004C9245 /* StickerBrowserDataSource.swift in Sources */, A9BE06DD2EA657CF0033B213 /* SlackResponse.swift in Sources */, A9D15B8A2EB1142C00404792 /* EmojiPack.swift in Sources */, ); diff --git a/StickerSlack/Emoji/Emoji.swift b/StickerSlack/Emoji/Emoji.swift index 74bef4b..f4f9ce7 100644 --- a/StickerSlack/Emoji/Emoji.swift +++ b/StickerSlack/Emoji/Emoji.swift @@ -8,6 +8,7 @@ import Foundation import UIKit import SwiftUI +import Messages import UniformTypeIdentifiers struct Emoji: Codable, Identifiable, Hashable { @@ -26,6 +27,13 @@ struct Emoji: Codable, Identifiable, Hashable { return (try? Data(contentsOf: localImageURL)) != nil } + var sticker: MSSticker { + guard isLocal else { + fatalError("sticker \(name) isnt local") + } + return try! MSSticker(contentsOfFileURL: localImageURL, localizedDescription: name) + } + var image: UIImage? { if let data = try? Data(contentsOf: localImageURL), let img = UIImage(data: data) { diff --git a/StickerSlackiMessageExtension/MessagesViewController.swift b/StickerSlackiMessageExtension/MessagesViewController.swift index ef1dfb8..8ad7414 100644 --- a/StickerSlackiMessageExtension/MessagesViewController.swift +++ b/StickerSlackiMessageExtension/MessagesViewController.swift @@ -9,23 +9,30 @@ import UIKit import Messages class MessagesViewController: MSMessagesAppViewController { - var hoard: EmojiHoarder = EmojiHoarder() + let dataSource: StickerBrowserDataSource = StickerBrowserDataSource() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. +// sleep(5) } // MARK: - Conversation Handling override func willBecomeActive(with conversation: MSConversation) { - print(hoard.emojis.count) let l = UILabel() - l.frame = CGRect(x: 20, y: 20, width: 1000, height: 40) + l.frame = CGRect(x: 20, y: 20, width: 200, height: 40) l.textColor = .systemOrange - l.text = "\(hoard.emojis.count)" + l.text = "hii!" view.addSubview(l) view.bringSubviewToFront(l) + + let stickerBrowser = MSStickerBrowserView(frame: .zero, stickerSize: .regular) + stickerBrowser.frame = CGRect(x: 60, y: 20, width: 200, height: 600) + stickerBrowser.dataSource = dataSource + view.addSubview(stickerBrowser) + stickerBrowser.reloadData() + view.bringSubviewToFront(stickerBrowser) // Called when the extension is about to move from the inactive to active state. // This will happen when the extension is about to present UI. diff --git a/StickerSlackiMessageExtension/StickerBroswerViewController.swift b/StickerSlackiMessageExtension/StickerBroswerViewController.swift new file mode 100644 index 0000000..cc90a06 --- /dev/null +++ b/StickerSlackiMessageExtension/StickerBroswerViewController.swift @@ -0,0 +1,25 @@ +// +// StickerBroswerViewController.swift +// StickerSlackiMessageExtension +// +// Created by neon443 on 29/10/2025. +// + +import Foundation +import UIKit +import Messages + +class StickerBroswerViewController: MSStickerBrowserViewController { + var hoarder: EmojiHoarder = EmojiHoarder() + + var emojis: [Emoji] = [] + + override func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int { + emojis = hoarder.emojis.filter { $0.isLocal } + return emojis.count + } + + override func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker { + return emojis[index].sticker + } +} diff --git a/StickerSlackiMessageExtension/StickerBrowserDataSource.swift b/StickerSlackiMessageExtension/StickerBrowserDataSource.swift new file mode 100644 index 0000000..1224896 --- /dev/null +++ b/StickerSlackiMessageExtension/StickerBrowserDataSource.swift @@ -0,0 +1,21 @@ +// +// StickerBrowserDataSource.swift +// StickerSlackiMessageExtension +// +// Created by neon443 on 29/10/2025. +// + +import Foundation +import Messages + +class StickerBrowserDataSource: NSObject, MSStickerBrowserViewDataSource { + var hoarder: EmojiHoarder = EmojiHoarder() + + func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int { + return hoarder.emojis.filter { $0.isLocal }.count + } + + func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker { + return hoarder.emojis.filter { $0.isLocal }[index].sticker + } +}