2021-09-28 19:21:57 +00:00
|
|
|
import json, sequtils
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
import ./settings
|
2021-09-28 19:21:57 +00:00
|
|
|
import ../types/[setting, gif_item]
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-28 19:21:57 +00:00
|
|
|
proc getRecentGifs*(): seq[GifItem] =
|
|
|
|
let node = settings.getSetting[JsonNode](Setting.Gifs_Recent, %*{})
|
|
|
|
return map(node{"items"}.getElems(), settingToGifItem)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-28 19:21:57 +00:00
|
|
|
proc getFavoriteGifs*(): seq[GifItem] =
|
|
|
|
let node = settings.getSetting[JsonNode](Setting.Gifs_Favorite, %*{})
|
|
|
|
return map(node{"items"}.getElems(), settingToGifItem)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-28 19:21:57 +00:00
|
|
|
proc setFavoriteGifs*(gifItems: seq[GifItem]) =
|
|
|
|
let node = %*{"items": map(gifItems, toJsonNode)}
|
|
|
|
discard settings.saveSetting(Setting.Gifs_Favorite, node)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-28 19:21:57 +00:00
|
|
|
proc setRecentGifs*(gifItems: seq[GifItem]) =
|
|
|
|
let node = %*{"items": map(gifItems, toJsonNode)}
|
|
|
|
discard settings.saveSetting(Setting.Gifs_Recent, node)
|