~reesmichael1/roman

ref: 027978a6a87d081a4d6d2cab7cbd147c7b4aa378 roman/src/romanpkg/types.nim -rw-r--r-- 1.3 KiB
027978a6Michael Rees Add mark all as read command 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import hashes
import options


type
  RomanConfig* = object
    up*: char
    down*: char
    next*: char
    previous*: char
    quit*: char
    goToTop*: char
    goToBottom*: char
    toggleRead*: char
    allRead*: char
    postWidth*: int
    extractLinks*: char

  # Use our own Post type instead of RSSItem
  # to show metadata we collect (e.g., read/unread)
  Post* = ref object
    title*: string
    link*: string
    rendered*: string
    raw*: string
    guid*: string
    read*: bool
    author*: Option[string]

  FeedKind* = enum
    RSS = "RSS", Atom = "Atom", Unknown

  Feed* = ref object
    kind*: FeedKind
    posts*: seq[Post]
    title*: string
    unreadPosts*: int

  Subscription* = ref object
    url*: string
    name*: string
    feedKind*: FeedKind

  PostLink* = ref object
    text*: string
    url*: string

  ManageAction* = enum
    EditTitle, NoOp, Unsubscribe



proc hash*(pl: PostLink): Hash =
  result = pl.text.hash !& pl.url.hash
  result = !$result


proc hash*(sub: Subscription): Hash =
  result = sub.name.hash !& sub.url.hash !& sub.feedKind.hash
  result = !$result


proc hash*(feed: Feed): Hash =
  result = feed.kind.hash !& feed.title.hash !& feed.unreadPosts.hash
  result = !$result


proc `$`*[T](input: ref T): string = $(input[])
proc hash*[T](input: ref T): Hash = hash(input[])