types.nim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import times, sequtils, options
  2. import norm/sqlite
  3. import prefs_impl
  4. export sqlite, options
  5. type
  6. VideoType* = enum
  7. vmap, m3u8, mp4
  8. dbTypes:
  9. type
  10. Profile* = object
  11. username*: string
  12. fullname*: string
  13. location*: string
  14. website*: string
  15. bio*: string
  16. userpic*: string
  17. banner*: string
  18. following*: string
  19. followers*: string
  20. tweets*: string
  21. likes*: string
  22. media*: string
  23. verified*: bool
  24. protected*: bool
  25. joinDate* {.
  26. dbType: "INTEGER"
  27. parseIt: it.i.fromUnix()
  28. formatIt: dbValue(it.toUnix())
  29. .}: Time
  30. updated* {.
  31. dbType: "INTEGER"
  32. parseIt: it.i.fromUnix()
  33. formatIt: dbValue(getTime().toUnix())
  34. .}: Time
  35. Video* = object
  36. videoId*: string
  37. contentId*: string
  38. durationMs*: int
  39. url*: string
  40. thumb*: string
  41. views*: string
  42. available*: bool
  43. reason*: string
  44. playbackType* {.
  45. dbType: "STRING"
  46. parseIt: parseEnum[VideoType](it.s)
  47. formatIt: dbValue($it)
  48. .}: VideoType
  49. genPrefsType()
  50. dbFromTypes("cache.db", "", "", "", [Profile, Video])
  51. type
  52. QueryKind* = enum
  53. replies, media, multi, custom = "search"
  54. Query* = object
  55. kind*: QueryKind
  56. text*: string
  57. filters*: seq[string]
  58. includes*: seq[string]
  59. excludes*: seq[string]
  60. fromUser*: seq[string]
  61. sep*: string
  62. Result*[T] = ref object
  63. content*: seq[T]
  64. minId*: string
  65. maxId*: string
  66. hasMore*: bool
  67. beginning*: bool
  68. query*: Option[Query]
  69. Gif* = object
  70. url*: string
  71. thumb*: string
  72. GalleryPhoto* = object
  73. url*: string
  74. tweetId*: string
  75. color*: string
  76. Poll* = object
  77. options*: seq[string]
  78. values*: seq[int]
  79. votes*: string
  80. status*: string
  81. leader*: int
  82. CardKind* = enum
  83. summary = "summary"
  84. summaryLarge = "summary_large_image"
  85. promoWebsite = "promo_website"
  86. promoVideo = "promo_video_website"
  87. player = "player"
  88. liveEvent = "live_event"
  89. Card* = object
  90. kind*: CardKind
  91. id*: string
  92. query*: string
  93. url*: string
  94. title*: string
  95. dest*: string
  96. text*: string
  97. image*: Option[string]
  98. video*: Option[Video]
  99. Quote* = object
  100. id*: string
  101. profile*: Profile
  102. text*: string
  103. reply*: seq[string]
  104. hasThread*: bool
  105. sensitive*: bool
  106. available*: bool
  107. tombstone*: string
  108. thumb*: string
  109. badge*: string
  110. Retweet* = object
  111. by*: string
  112. id*: string
  113. TweetStats* = object
  114. replies*: string
  115. retweets*: string
  116. likes*: string
  117. Tweet* = ref object
  118. id*: string
  119. threadId*: string
  120. profile*: Profile
  121. text*: string
  122. time*: Time
  123. shortTime*: string
  124. reply*: seq[string]
  125. pinned*: bool
  126. hasThread*: bool
  127. available*: bool
  128. tombstone*: string
  129. stats*: TweetStats
  130. retweet*: Option[Retweet]
  131. quote*: Option[Quote]
  132. card*: Option[Card]
  133. gif*: Option[Gif]
  134. video*: Option[Video]
  135. photos*: seq[string]
  136. poll*: Option[Poll]
  137. Thread* = ref object
  138. content*: seq[Tweet]
  139. more*: int
  140. Conversation* = ref object
  141. tweet*: Tweet
  142. before*: Thread
  143. after*: Thread
  144. replies*: seq[Thread]
  145. Timeline* = Result[Tweet]
  146. Config* = ref object
  147. address*: string
  148. port*: int
  149. useHttps*: bool
  150. title*: string
  151. staticDir*: string
  152. cacheDir*: string
  153. profileCacheTime*: int
  154. proc contains*(thread: Thread; tweet: Tweet): bool =
  155. thread.content.anyIt(it.id == tweet.id)