add an all emojis thingy on messages, add a dlcount

This commit is contained in:
Nihaal Sharma committed 2026-08-01 00:29:04 +05:30
1 parent 9b0a05abc3
commit 7a4a83ace8
5 files changed
+76 -15

No files matched your search

@@ -17,6 +17,15 @@ struct EmojiPack: Identifiable, Codable, Equatable, Hashable, CustomStringConver
var description: String {
return "\(items.count) emoji\(items.count.plural)"
}
var downloadedDescription: (Int) -> String {
{ dlCount in
if dlCount != items.count {
return "\(dlCount) / \(items.count) emoji\(items.count.plural)"
} else {
return "\(items.count) emoji\(items.count.plural)"
}
}
}
init(id: UUID, name: String, items: [String]) {
self.id = id
@@ -135,6 +135,24 @@ class EmojiHoarder: BaseHoarder {
}
sendChangeNotif(for: .downloadedEmojis)
}
func buildDownloadedStickersSync() {
var newSet: Set<String> = []
if let files = try? FileManager.default.contentsOfDirectory(atPath: EmojiHoarder.container.safePath) {
for file in files {
let name = String(file.split(separator: ".")[0])
newSet.insert(name)
}
}
newSet.remove("DS_Store")
let immutable = newSet
self.downloadedStickers = []
self.downloadedStickers = immutable
downloadedStickersArr = Array(downloadedStickers).sorted()
sendChangeNotif(for: .downloadedEmojis)
return
}
private func loadLocalDB() -> [Emoji] {
do {
@@ -10,7 +10,16 @@ import Messages
import SwiftUI
class MessagesAppViewController: MSMessagesAppViewController {
var emojiHoarder: EmojiHoarder = EmojiHoarder(localOnly: true, skipIndex: false)
var emojiHoarder: EmojiHoarder = EmojiHoarder(localOnly: true, skipIndex: true)
init() {
emojiHoarder.buildDownloadedStickersSync()
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
@@ -10,7 +10,7 @@ import UIKit
class MessagesPackListView: UITableViewController {
var emojiHoarder: EmojiHoarder!
var onSelect: ((EmojiPack) -> Void)?
var onSelect: ((EmojiPack?) -> Void)?
init(hoarder: EmojiHoarder) {
self.emojiHoarder = hoarder
@@ -26,22 +26,52 @@ class MessagesPackListView: UITableViewController {
return emojiHoarder.emojiPacks[indexPath.row]
}
@objc func reload() {
var indexPaths: [IndexPath] = []
for row in 0..<tableView(tableView, numberOfRowsInSection: 1) {
indexPaths.append(IndexPath(row: row, section: 1))
}
tableView.reconfigureRows(at: indexPaths)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: .top)
reload()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return emojiHoarder.emojiPacks.count
if section == 1 {
return emojiHoarder.emojiPacks.count
} else {
return 1
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let cell: UITableViewCell = tableView.cellForRow(at: indexPath) ?? .init()
guard indexPath.section == 1 else {
var config = cell.defaultContentConfiguration()
cell.backgroundColor = .lightGray
config.text = "All Downloaded"
config.textProperties.font = UIFont.systemFont(ofSize: 14)
cell.contentConfiguration = config
return cell
}
var config = cell.defaultContentConfiguration()
if let pack = packFor(indexPath: indexPath) {
config.text = pack.name
config.textProperties.font = UIFont.systemFont(ofSize: 14)
config.secondaryText = pack.description
let dlCount = emojiHoarder.downloadedStickers.intersection(pack.items).count
config.secondaryText = pack.downloadedDescription(dlCount)
config.secondaryTextProperties.font = UIFont.systemFont(ofSize: 12)
config.secondaryTextProperties.color = .systemGray
}
@@ -51,6 +81,10 @@ class MessagesPackListView: UITableViewController {
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
onSelect?(emojiHoarder.emojiPacks[indexPath.row])
if indexPath.section == 1 {
onSelect?(emojiHoarder.emojiPacks[indexPath.row])
} else {
onSelect?(nil)
}
}
}
@@ -20,15 +20,6 @@ class StickerBrowserViewController: MSStickerBrowserViewController {
self.pack = pack
super.init(stickerSize: .small)
reload()
NotificationCenter.default.addObserver(
self,
selector: #selector(reload),
name: EmojiHoarder.NotifCategory.downloadedEmojis.name,
object: nil
)
}
required init?(coder: NSCoder) {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.