types.nim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. 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. player = "player"
  91. liveEvent = "live_event"
  92. Card* = object
  93. kind*: CardKind
  94. id*: string
  95. query*: string
  96. url*: string
  97. title*: string
  98. dest*: string
  99. text*: string
  100. image*: Option[string]
  101. video*: Option[Video]
  102. Quote* = object
  103. id*: string
  104. profile*: Profile
  105. text*: string
  106. reply*: seq[string]
  107. hasThread*: bool
  108. sensitive*: bool
  109. available*: bool
  110. tombstone*: string
  111. thumb*: string
  112. badge*: string
  113. Retweet* = object
  114. by*: string
  115. id*: string
  116. TweetStats* = object
  117. replies*: string
  118. retweets*: string
  119. likes*: string
  120. Tweet* = ref object
  121. id*: string
  122. threadId*: string
  123. profile*: Profile
  124. text*: string
  125. time*: Time
  126. shortTime*: string
  127. reply*: seq[string]
  128. pinned*: bool
  129. hasThread*: bool
  130. available*: bool
  131. tombstone*: string
  132. stats*: TweetStats
  133. retweet*: Option[Retweet]
  134. quote*: Option[Quote]
  135. card*: Option[Card]
  136. gif*: Option[Gif]
  137. video*: Option[Video]
  138. photos*: seq[string]
  139. poll*: Option[Poll]
  140. Chain* = ref object
  141. content*: seq[Tweet]
  142. more*: int
  143. Conversation* = ref object
  144. tweet*: Tweet
  145. before*: Chain
  146. after*: Chain
  147. replies*: Result[Chain]
  148. Timeline* = Result[Tweet]
  149. Config* = ref object
  150. address*: string
  151. port*: int
  152. useHttps*: bool
  153. title*: string
  154. staticDir*: string
  155. cacheDir*: string
  156. profileCacheTime*: int
  157. proc contains*(thread: Chain; tweet: Tweet): bool =
  158. thread.content.anyIt(it.id == tweet.id)