Compare commits

...
3 Commits
Author SHA1 Message Date
neon443 046ede9475 m,lkk 2026-03-19 22:32:25 +00:00
neon443 a79bdd3e40 new test gif
made some things optional in gifobject
2026-03-19 20:11:35 +00:00
Nihaal Sharma d64ca5cd42 about 15% faster trie building not much but eh
also stopped using a Task for searching
2026-03-19 10:18:13 +00:00
6 changed files with 134 additions and 34 deletions

No files matched your search

+103 -9
View File
@@ -16,14 +16,14 @@ struct Gif: StickerProtocol {
let urlString = remoteImageURL.absoluteString let urlString = remoteImageURL.absoluteString
let split = urlString.split(separator: ".") let split = urlString.split(separator: ".")
let fileExtension = ".\(split.last ?? "png")" let fileExtension = ".\(split.last ?? "png")"
return GifHoarder.container.absoluteString+id+fileExtension return GifHoarder.container.absoluteString+id+fileExtension
} }
var remoteImageURL: URL var remoteImageURL: URL
// enum CodingKeys: String, CodingKey { // enum CodingKeys: String, CodingKey {
// //
// } // }
init( init(
name: String, name: String,
@@ -45,7 +45,7 @@ struct Gif: StickerProtocol {
if let uiImage = UIImage(data: data), if let uiImage = UIImage(data: data),
let cgImage = uiImage.cgImage, let cgImage = uiImage.cgImage,
!self.localImageURLString.contains(".gif"), !self.localImageURLString.contains(".gif"),
cgImage.width < 300 || cgImage.height < 300 { cgImage.width < 300 || cgImage.height < 300 {
data = resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()! data = resize(image: uiImage, to: CGSize(width: 300, height: 300)).pngData()!
} }
@@ -54,8 +54,102 @@ struct Gif: StickerProtocol {
return return
} }
static var test: Gif = Gif( static var test: Gif = GifObject(
name: "doesheknow", type: "gif",
url: URL(string: "https://media1.tenor.com/m/FN9udnZmQU8AAAAd/does-he-know-batman.gif")! id: "XAeEGyCbp8UehBPkSA",
) slug: "know-does-he-XAeEGyCbp8UehBPkSA",
url: "https://giphy.com/gifs/know-does-he-XAeEGyCbp8UehBPkSA",
bitly_url: "https://gph.is/g/4AKMQlV",
embed_url: "https://giphy.com/embed/XAeEGyCbp8UehBPkSA",
username: "Ommarbisafool",
source: "",
rating: "g",
source_tld: "",
source_post_url: "",
import_datetime: "2025-11-06 15:48:02",
images: GiphyImages(
fixed_height: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200.gif&ct=g",
width: "270",
height: "200",
size: "74672",
mp4: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200.mp4?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200.mp4&ct=g",
mp4_size: "11433",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200.webp&ct=g",
webp_size: "10962"
),
fixed_height_still: nil,
fixed_height_downsampled: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200_d.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200_d.gif&ct=g",
width: "270",
height: "200",
size: "51332",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200_d.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200_d.webp&ct=g",
webp_size: "44850"
),
fixed_height_small: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100.gif&ct=g",
width: "134",
height: "100",
size: "16461",
mp4: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100.mp4?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100.mp4&ct=g",
mp4_size: "5340",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100.webp&ct=g",
webp_size: "3142"
),
fixed_height_small_still: nil,
fixed_width: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200w.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200w.gif&ct=g",
width: "200",
height: "148",
size: "42579",
mp4: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200w.mp4?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200w.mp4&ct=g",
mp4_size: "8158",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200w.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200w.webp&ct=g",
webp_size: "4458"
),
fixed_width_still: nil,
fixed_width_downsampled: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200w_d.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200w_d.gif&ct=g",
width: "200",
height: "148",
size: "23483",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/200w_d.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=200w_d.webp&ct=g",
webp_size: "22586"
),
fixed_width_small: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100w.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100w.gif&ct=g",
width: "100",
height: "74",
size: "8150",
mp4: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100w.mp4?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100w.mp4&ct=g",
mp4_size: "4103",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/100w.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=100w.webp&ct=g",
webp_size: "1814"
),
fixed_width_small_still: nil,
downsized: nil,
downsized_still: nil,
downsized_large: nil,
downsized_medium: nil,
downsized_small: nil,
original: .init(
url: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/giphy.gif?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=giphy.gif&ct=g",
width: "480",
height: "356",
size: "245829",
mp4: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/giphy.mp4?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=giphy.mp4&ct=g",
mp4_size: "23259",
webp: "https://media2.giphy.com/media/XAeEGyCbp8UehBPkSA/giphy.webp?cid=acd65332fv0sn3gzwa5vi4jw834l2hhwmfm6d90329p1590n&ep=v1_gifs_search&rid=giphy.webp&ct=g",
webp_size: "26984"
),
original_still: nil,
// looping: nil,
preview: nil,
preview_gif: nil
),
title: "Know GIF",
alt_text: "",
is_low_contrast: false
).toGif
} }
+13 -13
View File
@@ -11,47 +11,47 @@ struct GiphyImages: Codable {
//fixed height of 200px //fixed height of 200px
var fixed_height: motion var fixed_height: motion
//fixed height of 200px still //fixed height of 200px still
var fixed_height_still: still var fixed_height_still: still?
//fixed height 200px with 6 frames //fixed height 200px with 6 frames
var fixed_height_downsampled: downsampled var fixed_height_downsampled: downsampled
//fixed height of 100px //fixed height of 100px
var fixed_height_small: motion var fixed_height_small: motion
//fixed height of 100px still //fixed height of 100px still
var fixed_height_small_still: still var fixed_height_small_still: still?
//fixed width of 200px //fixed width of 200px
var fixed_width: motion var fixed_width: motion
//fixed width of 200px //fixed width of 200px
var fixed_width_still: still var fixed_width_still: still?
//fixed width 200px with 6 frames //fixed width 200px with 6 frames
var fixed_width_downsampled: downsampled var fixed_width_downsampled: downsampled
//fixed width of 100px //fixed width of 100px
var fixed_width_small: motion var fixed_width_small: motion
//fixed width of 100px still //fixed width of 100px still
var fixed_width_small_still: still var fixed_width_small_still: still?
//under 2mb //under 2mb
var downsized: downsized var downsized: downsized?
//downsized still //downsized still
var downsized_still: still var downsized_still: still?
//under 8mb //under 8mb
var downsized_large: downsized var downsized_large: downsized?
//under 5mb //under 5mb
var downsized_medium: downsized var downsized_medium: downsized?
//under 200kb //under 200kb
var downsized_small: video var downsized_small: video?
var original: motion var original: motion
var original_still: still var original_still: still?
//15s looping version //15s looping version
// var looping: looping // var looping: looping?
//mp4 format 50kb, first 1-2s of the gif //mp4 format 50kb, first 1-2s of the gif
var preview: video var preview: video?
//50kb first 1-2s of the gif //50kb first 1-2s of the gif
var preview_gif: still var preview_gif: still?
struct motion: Codable { struct motion: Codable {
+1
View File
@@ -29,6 +29,7 @@ struct BrowseView: View {
case .giphyGifs: case .giphyGifs:
ForEach(gifHoarder.trendingGifs) { gif in ForEach(gifHoarder.trendingGifs) { gif in
StickerRow(hoarder: emojiHoarder, emoji: gif) StickerRow(hoarder: emojiHoarder, emoji: gif)
.listRowSeparator(.hidden)
} }
} }
} }
+8 -4
View File
@@ -34,10 +34,14 @@ struct StickerRow<T: Hoarder>: View {
Button { Button {
showTooltip.toggle() showTooltip.toggle()
} label: { } label: {
Image("slack.logo") if type(of: emoji) == Emoji.self {
.resizable().scaledToFit() Image("slack.logo")
.frame(width: 20, height: 20) .resizable().scaledToFit()
.foregroundStyle(.gray) .frame(width: 20, height: 20)
.foregroundStyle(.gray)
} else if type(of: emoji) == Gif.self {
Text("G")
}
} }
.buttonStyle(.borderless) .buttonStyle(.borderless)
.alert("From Slack", isPresented: $showTooltip) { .alert("From Slack", isPresented: $showTooltip) {
+5 -5
View File
@@ -34,15 +34,15 @@ struct SearchView: View {
if currentSearch != nil { if currentSearch != nil {
withAnimation { currentSearch?.cancel() } withAnimation { currentSearch?.cancel() }
} }
currentSearch = Task { // currentSearch = Task {
let result = await hoarder.trie.search(for: searchTerm) let result = hoarder.trie.search(for: searchTerm)
guard !Task.isCancelled else { return } guard !Task.isCancelled else { return }
await MainActor.run { // await MainActor.run {
withAnimation(.snappy) { withAnimation(.snappy) {
searchResult = result searchResult = result
} }
} // }
} // }
} }
} }
} }
+4 -3
View File
@@ -18,11 +18,12 @@ class Trie: ObservableObject {
var root: TrieNode = TrieNode() var root: TrieNode = TrieNode()
var dict: [String:Emoji] = [:] var dict: [String:Emoji] = [:]
var wordlist: [String] = [] var wordlist: Set<String> = []
// var previousSearchTerm
func insert(word: String) { func insert(word: String) {
let word = word.lowercased() let word = word.lowercased()
wordlist.append(word) wordlist.insert(word)
var currentNode = root var currentNode = root
let indices = word.indices let indices = word.indices
let last = indices.last let last = indices.last
@@ -42,7 +43,7 @@ class Trie: ObservableObject {
} }
func search(for query: String) -> [String] { func search(for query: String) -> [String] {
var result: Set<String> = Set(wordlist) var result: Set<String> = wordlist
for word in query.split(separator: " ") { for word in query.split(separator: " ") {
result = result.filter { $0.localizedCaseInsensitiveContains(word) } result = result.filter { $0.localizedCaseInsensitiveContains(word) }
} }
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.