types.nim 3.9 KB

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