types.nim 3.6 KB

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