sidechat.js 2.6.1 → 2.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. package/.github/workflows/static.yml +0 -0
  2. package/README.md +0 -0
  3. package/dist/classes/SidechatAPIClient.d.ts +63 -47
  4. package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
  5. package/dist/classes/SidechatAPIError.d.ts +0 -0
  6. package/dist/classes/SidechatAPIError.d.ts.map +0 -0
  7. package/dist/classes/SidechatColorList.d.ts +0 -0
  8. package/dist/classes/SidechatColorList.d.ts.map +0 -0
  9. package/dist/index.cjs +1421 -1349
  10. package/dist/index.d.mts +0 -0
  11. package/dist/index.d.ts +0 -0
  12. package/dist/index.d.ts.map +0 -0
  13. package/dist/index.mjs +1421 -1349
  14. package/dist/types/SidechatTypes.d.ts +0 -0
  15. package/dist/types/SidechatTypes.d.ts.map +0 -0
  16. package/docs/sidechat.js/2.5.6/SidechatAPIClient.html +0 -0
  17. package/docs/sidechat.js/2.5.6/SidechatAPIError.html +0 -0
  18. package/docs/sidechat.js/2.5.6/SidechatColorList.html +0 -0
  19. package/docs/sidechat.js/2.5.6/classes_SidechatAPIClient.js.html +0 -0
  20. package/docs/sidechat.js/2.5.6/classes_SidechatAPIError.js.html +0 -0
  21. package/docs/sidechat.js/2.5.6/classes_SidechatColorList.js.html +0 -0
  22. package/docs/sidechat.js/2.5.6/data/search.json +0 -0
  23. package/docs/sidechat.js/2.5.6/fonts/Inconsolata-Regular.ttf +0 -0
  24. package/docs/sidechat.js/2.5.6/fonts/OpenSans-Regular.ttf +0 -0
  25. package/docs/sidechat.js/2.5.6/fonts/WorkSans-Bold.ttf +0 -0
  26. package/docs/sidechat.js/2.5.6/global.html +0 -0
  27. package/docs/sidechat.js/2.5.6/index.html +0 -0
  28. package/docs/sidechat.js/2.5.6/scripts/core.js +0 -0
  29. package/docs/sidechat.js/2.5.6/scripts/core.min.js +0 -0
  30. package/docs/sidechat.js/2.5.6/scripts/resize.js +0 -0
  31. package/docs/sidechat.js/2.5.6/scripts/search.js +0 -0
  32. package/docs/sidechat.js/2.5.6/scripts/search.min.js +0 -0
  33. package/docs/sidechat.js/2.5.6/scripts/third-party/Apache-License-2.0.txt +0 -0
  34. package/docs/sidechat.js/2.5.6/scripts/third-party/fuse.js +0 -0
  35. package/docs/sidechat.js/2.5.6/scripts/third-party/hljs-line-num-original.js +0 -0
  36. package/docs/sidechat.js/2.5.6/scripts/third-party/hljs-line-num.js +0 -0
  37. package/docs/sidechat.js/2.5.6/scripts/third-party/hljs-original.js +0 -0
  38. package/docs/sidechat.js/2.5.6/scripts/third-party/hljs.js +0 -0
  39. package/docs/sidechat.js/2.5.6/scripts/third-party/popper.js +0 -0
  40. package/docs/sidechat.js/2.5.6/scripts/third-party/tippy.js +0 -0
  41. package/docs/sidechat.js/2.5.6/scripts/third-party/tocbot.js +0 -0
  42. package/docs/sidechat.js/2.5.6/scripts/third-party/tocbot.min.js +0 -0
  43. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme-base.css +0 -0
  44. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme-dark.css +0 -0
  45. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme-light.css +0 -0
  46. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  47. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  48. package/docs/sidechat.js/2.5.6/styles/clean-jsdoc-theme.min.css +0 -0
  49. package/docs/sidechat.js/2.5.6/tutorial-Authentication.html +0 -0
  50. package/docs/sidechat.js/2.5.6/tutorial-Email Registration.html +0 -0
  51. package/docs/sidechat.js/2.5.6/types_SidechatTypes.js.html +0 -0
  52. package/docs/sidechat.js/2.6.0/SidechatAPIClient.html +0 -0
  53. package/docs/sidechat.js/2.6.0/SidechatAPIError.html +0 -0
  54. package/docs/sidechat.js/2.6.0/SidechatColorList.html +0 -0
  55. package/docs/sidechat.js/2.6.0/classes_SidechatAPIClient.js.html +0 -0
  56. package/docs/sidechat.js/2.6.0/classes_SidechatAPIError.js.html +0 -0
  57. package/docs/sidechat.js/2.6.0/classes_SidechatColorList.js.html +0 -0
  58. package/docs/sidechat.js/2.6.0/data/search.json +0 -0
  59. package/docs/sidechat.js/2.6.0/fonts/Inconsolata-Regular.ttf +0 -0
  60. package/docs/sidechat.js/2.6.0/fonts/OpenSans-Regular.ttf +0 -0
  61. package/docs/sidechat.js/2.6.0/fonts/WorkSans-Bold.ttf +0 -0
  62. package/docs/sidechat.js/2.6.0/global.html +0 -0
  63. package/docs/sidechat.js/2.6.0/index.html +0 -0
  64. package/docs/sidechat.js/2.6.0/scripts/core.js +0 -0
  65. package/docs/sidechat.js/2.6.0/scripts/core.min.js +0 -0
  66. package/docs/sidechat.js/2.6.0/scripts/resize.js +0 -0
  67. package/docs/sidechat.js/2.6.0/scripts/search.js +0 -0
  68. package/docs/sidechat.js/2.6.0/scripts/search.min.js +0 -0
  69. package/docs/sidechat.js/2.6.0/scripts/third-party/Apache-License-2.0.txt +0 -0
  70. package/docs/sidechat.js/2.6.0/scripts/third-party/fuse.js +0 -0
  71. package/docs/sidechat.js/2.6.0/scripts/third-party/hljs-line-num-original.js +0 -0
  72. package/docs/sidechat.js/2.6.0/scripts/third-party/hljs-line-num.js +0 -0
  73. package/docs/sidechat.js/2.6.0/scripts/third-party/hljs-original.js +0 -0
  74. package/docs/sidechat.js/2.6.0/scripts/third-party/hljs.js +0 -0
  75. package/docs/sidechat.js/2.6.0/scripts/third-party/popper.js +0 -0
  76. package/docs/sidechat.js/2.6.0/scripts/third-party/tippy.js +0 -0
  77. package/docs/sidechat.js/2.6.0/scripts/third-party/tocbot.js +0 -0
  78. package/docs/sidechat.js/2.6.0/scripts/third-party/tocbot.min.js +0 -0
  79. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme-base.css +0 -0
  80. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme-dark.css +0 -0
  81. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme-light.css +0 -0
  82. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  83. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  84. package/docs/sidechat.js/2.6.0/styles/clean-jsdoc-theme.min.css +0 -0
  85. package/docs/sidechat.js/2.6.0/tutorial-Authentication.html +0 -0
  86. package/docs/sidechat.js/2.6.0/tutorial-Email Registration.html +0 -0
  87. package/docs/sidechat.js/2.6.0/types_SidechatTypes.js.html +0 -0
  88. package/docs/sidechat.js/2.6.1/SidechatAPIClient.html +0 -0
  89. package/docs/sidechat.js/2.6.1/SidechatAPIError.html +0 -0
  90. package/docs/sidechat.js/2.6.1/SidechatColorList.html +0 -0
  91. package/docs/sidechat.js/2.6.1/classes_SidechatAPIClient.js.html +0 -0
  92. package/docs/sidechat.js/2.6.1/classes_SidechatAPIError.js.html +0 -0
  93. package/docs/sidechat.js/2.6.1/classes_SidechatColorList.js.html +0 -0
  94. package/docs/sidechat.js/2.6.1/data/search.json +0 -0
  95. package/docs/sidechat.js/2.6.1/fonts/Inconsolata-Regular.ttf +0 -0
  96. package/docs/sidechat.js/2.6.1/fonts/OpenSans-Regular.ttf +0 -0
  97. package/docs/sidechat.js/2.6.1/fonts/WorkSans-Bold.ttf +0 -0
  98. package/docs/sidechat.js/2.6.1/global.html +0 -0
  99. package/docs/sidechat.js/2.6.1/index.html +0 -0
  100. package/docs/sidechat.js/2.6.1/scripts/core.js +0 -0
  101. package/docs/sidechat.js/2.6.1/scripts/core.min.js +0 -0
  102. package/docs/sidechat.js/2.6.1/scripts/resize.js +0 -0
  103. package/docs/sidechat.js/2.6.1/scripts/search.js +0 -0
  104. package/docs/sidechat.js/2.6.1/scripts/search.min.js +0 -0
  105. package/docs/sidechat.js/2.6.1/scripts/third-party/Apache-License-2.0.txt +0 -0
  106. package/docs/sidechat.js/2.6.1/scripts/third-party/fuse.js +0 -0
  107. package/docs/sidechat.js/2.6.1/scripts/third-party/hljs-line-num-original.js +0 -0
  108. package/docs/sidechat.js/2.6.1/scripts/third-party/hljs-line-num.js +0 -0
  109. package/docs/sidechat.js/2.6.1/scripts/third-party/hljs-original.js +0 -0
  110. package/docs/sidechat.js/2.6.1/scripts/third-party/hljs.js +0 -0
  111. package/docs/sidechat.js/2.6.1/scripts/third-party/popper.js +0 -0
  112. package/docs/sidechat.js/2.6.1/scripts/third-party/tippy.js +0 -0
  113. package/docs/sidechat.js/2.6.1/scripts/third-party/tocbot.js +0 -0
  114. package/docs/sidechat.js/2.6.1/scripts/third-party/tocbot.min.js +0 -0
  115. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme-base.css +0 -0
  116. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme-dark.css +0 -0
  117. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme-light.css +0 -0
  118. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  119. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  120. package/docs/sidechat.js/2.6.1/styles/clean-jsdoc-theme.min.css +0 -0
  121. package/docs/sidechat.js/2.6.1/tutorial-Authentication.html +0 -0
  122. package/docs/sidechat.js/2.6.1/tutorial-Email Registration.html +0 -0
  123. package/docs/sidechat.js/2.6.1/types_SidechatTypes.js.html +0 -0
  124. package/docs/sidechat.js/2.6.4/SidechatAPIClient.html +3 -0
  125. package/docs/sidechat.js/2.6.4/SidechatAPIError.html +3 -0
  126. package/docs/sidechat.js/{2.5.4/SidechatAPIError.html → 2.6.4/SidechatColorList.html} +2 -2
  127. package/docs/sidechat.js/{2.5.5 → 2.6.4}/classes_SidechatAPIClient.js.html +184 -9
  128. package/docs/sidechat.js/{2.5.4 → 2.6.4}/classes_SidechatAPIError.js.html +2 -2
  129. package/docs/sidechat.js/{2.5.4 → 2.6.4}/classes_SidechatColorList.js.html +2 -2
  130. package/docs/sidechat.js/2.6.4/data/search.json +1 -0
  131. package/docs/sidechat.js/{2.5.1 → 2.6.4}/fonts/Inconsolata-Regular.ttf +0 -0
  132. package/docs/sidechat.js/{2.5.1 → 2.6.4}/fonts/OpenSans-Regular.ttf +0 -0
  133. package/docs/sidechat.js/{2.5.1 → 2.6.4}/fonts/WorkSans-Bold.ttf +0 -0
  134. package/docs/sidechat.js/2.6.4/global.html +3 -0
  135. package/docs/sidechat.js/{2.5.3 → 2.6.4}/index.html +2 -2
  136. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/core.js +0 -0
  137. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/core.min.js +0 -0
  138. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/resize.js +0 -0
  139. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/search.js +0 -0
  140. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/search.min.js +0 -0
  141. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/Apache-License-2.0.txt +0 -0
  142. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/fuse.js +0 -0
  143. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/hljs-line-num-original.js +0 -0
  144. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/hljs-line-num.js +0 -0
  145. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/hljs-original.js +0 -0
  146. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/hljs.js +0 -0
  147. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/popper.js +0 -0
  148. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/tippy.js +0 -0
  149. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/tocbot.js +0 -0
  150. package/docs/sidechat.js/{2.5.1 → 2.6.4}/scripts/third-party/tocbot.min.js +0 -0
  151. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme-base.css +0 -0
  152. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme-dark.css +0 -0
  153. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme-light.css +0 -0
  154. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  155. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  156. package/docs/sidechat.js/{2.5.1 → 2.6.4}/styles/clean-jsdoc-theme.min.css +0 -0
  157. package/docs/sidechat.js/{2.5.4 → 2.6.4}/tutorial-Authentication.html +2 -2
  158. package/docs/sidechat.js/{2.5.4 → 2.6.4}/tutorial-Email Registration.html +2 -2
  159. package/docs/sidechat.js/{2.5.3 → 2.6.4}/types_SidechatTypes.js.html +51 -7
  160. package/docs/sidechat.js/2.6.5/SidechatAPIClient.html +3 -0
  161. package/docs/sidechat.js/2.6.5/SidechatAPIError.html +3 -0
  162. package/docs/sidechat.js/{2.5.5/SidechatAPIError.html → 2.6.5/SidechatColorList.html} +2 -2
  163. package/docs/sidechat.js/{2.5.4 → 2.6.5}/classes_SidechatAPIClient.js.html +1427 -1238
  164. package/docs/sidechat.js/{2.5.5 → 2.6.5}/classes_SidechatAPIError.js.html +2 -2
  165. package/docs/sidechat.js/{2.5.2 → 2.6.5}/classes_SidechatColorList.js.html +2 -2
  166. package/docs/sidechat.js/2.6.5/data/search.json +1 -0
  167. package/docs/sidechat.js/{2.5.2 → 2.6.5}/fonts/Inconsolata-Regular.ttf +0 -0
  168. package/docs/sidechat.js/{2.5.2 → 2.6.5}/fonts/OpenSans-Regular.ttf +0 -0
  169. package/docs/sidechat.js/{2.5.2 → 2.6.5}/fonts/WorkSans-Bold.ttf +0 -0
  170. package/docs/sidechat.js/2.6.5/global.html +3 -0
  171. package/docs/sidechat.js/{2.5.4 → 2.6.5}/index.html +2 -2
  172. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/core.js +0 -0
  173. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/core.min.js +0 -0
  174. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/resize.js +0 -0
  175. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/search.js +0 -0
  176. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/search.min.js +0 -0
  177. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/Apache-License-2.0.txt +0 -0
  178. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/fuse.js +0 -0
  179. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/hljs-line-num-original.js +0 -0
  180. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/hljs-line-num.js +0 -0
  181. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/hljs-original.js +0 -0
  182. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/hljs.js +0 -0
  183. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/popper.js +0 -0
  184. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/tippy.js +0 -0
  185. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/tocbot.js +0 -0
  186. package/docs/sidechat.js/{2.5.2 → 2.6.5}/scripts/third-party/tocbot.min.js +0 -0
  187. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme-base.css +0 -0
  188. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme-dark.css +0 -0
  189. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme-light.css +0 -0
  190. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  191. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  192. package/docs/sidechat.js/{2.5.2 → 2.6.5}/styles/clean-jsdoc-theme.min.css +0 -0
  193. package/docs/sidechat.js/{2.5.5 → 2.6.5}/tutorial-Authentication.html +2 -2
  194. package/docs/sidechat.js/{2.5.5 → 2.6.5}/tutorial-Email Registration.html +2 -2
  195. package/docs/sidechat.js/{2.5.2 → 2.6.5}/types_SidechatTypes.js.html +51 -7
  196. package/docs/tutorials/Authentication.md +0 -0
  197. package/docs/tutorials/Email Registration.md +0 -0
  198. package/jsdoc.json +0 -0
  199. package/package.json +55 -54
  200. package/rollup.config.mjs +0 -0
  201. package/src/classes/SidechatAPIClient.js +1426 -1355
  202. package/src/classes/SidechatAPIError.js +0 -0
  203. package/src/classes/SidechatColorList.js +0 -0
  204. package/src/index.js +0 -0
  205. package/src/tests/colorTest.js +0 -0
  206. package/src/tests/commentTest.js +0 -0
  207. package/src/tests/directMessageTest.js +0 -0
  208. package/src/tests/logInTest.js +0 -0
  209. package/src/tests/postTest.js +0 -0
  210. package/src/tests/updatesTest.js +0 -0
  211. package/src/types/SidechatTypes.js +0 -0
  212. package/tsconfig.json +0 -0
  213. package/docs/sidechat.js/2.5.1/SidechatAPIClient.html +0 -3
  214. package/docs/sidechat.js/2.5.1/SidechatAPIError.html +0 -3
  215. package/docs/sidechat.js/2.5.1/SidechatColorList.html +0 -3
  216. package/docs/sidechat.js/2.5.1/classes_SidechatAPIClient.js.html +0 -1188
  217. package/docs/sidechat.js/2.5.1/classes_SidechatAPIError.js.html +0 -16
  218. package/docs/sidechat.js/2.5.1/classes_SidechatColorList.js.html +0 -79
  219. package/docs/sidechat.js/2.5.1/data/search.json +0 -1
  220. package/docs/sidechat.js/2.5.1/global.html +0 -3
  221. package/docs/sidechat.js/2.5.1/index.html +0 -4
  222. package/docs/sidechat.js/2.5.1/tutorial-Authentication.html +0 -14
  223. package/docs/sidechat.js/2.5.1/tutorial-Email Registration.html +0 -6
  224. package/docs/sidechat.js/2.5.1/types_SidechatTypes.js.html +0 -160
  225. package/docs/sidechat.js/2.5.2/SidechatAPIClient.html +0 -3
  226. package/docs/sidechat.js/2.5.2/SidechatAPIError.html +0 -3
  227. package/docs/sidechat.js/2.5.2/SidechatColorList.html +0 -3
  228. package/docs/sidechat.js/2.5.2/classes_SidechatAPIClient.js.html +0 -1188
  229. package/docs/sidechat.js/2.5.2/classes_SidechatAPIError.js.html +0 -16
  230. package/docs/sidechat.js/2.5.2/data/search.json +0 -1
  231. package/docs/sidechat.js/2.5.2/global.html +0 -3
  232. package/docs/sidechat.js/2.5.2/index.html +0 -4
  233. package/docs/sidechat.js/2.5.2/tutorial-Authentication.html +0 -14
  234. package/docs/sidechat.js/2.5.2/tutorial-Email Registration.html +0 -6
  235. package/docs/sidechat.js/2.5.3/SidechatAPIClient.html +0 -3
  236. package/docs/sidechat.js/2.5.3/SidechatAPIError.html +0 -3
  237. package/docs/sidechat.js/2.5.3/SidechatColorList.html +0 -3
  238. package/docs/sidechat.js/2.5.3/classes_SidechatAPIClient.js.html +0 -1180
  239. package/docs/sidechat.js/2.5.3/classes_SidechatAPIError.js.html +0 -16
  240. package/docs/sidechat.js/2.5.3/classes_SidechatColorList.js.html +0 -79
  241. package/docs/sidechat.js/2.5.3/data/search.json +0 -1
  242. package/docs/sidechat.js/2.5.3/fonts/Inconsolata-Regular.ttf +0 -0
  243. package/docs/sidechat.js/2.5.3/fonts/OpenSans-Regular.ttf +0 -0
  244. package/docs/sidechat.js/2.5.3/fonts/WorkSans-Bold.ttf +0 -0
  245. package/docs/sidechat.js/2.5.3/global.html +0 -3
  246. package/docs/sidechat.js/2.5.3/scripts/core.js +0 -726
  247. package/docs/sidechat.js/2.5.3/scripts/core.min.js +0 -23
  248. package/docs/sidechat.js/2.5.3/scripts/resize.js +0 -90
  249. package/docs/sidechat.js/2.5.3/scripts/search.js +0 -265
  250. package/docs/sidechat.js/2.5.3/scripts/search.min.js +0 -6
  251. package/docs/sidechat.js/2.5.3/scripts/third-party/Apache-License-2.0.txt +0 -202
  252. package/docs/sidechat.js/2.5.3/scripts/third-party/fuse.js +0 -9
  253. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-line-num-original.js +0 -369
  254. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-line-num.js +0 -1
  255. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-original.js +0 -5171
  256. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs.js +0 -1
  257. package/docs/sidechat.js/2.5.3/scripts/third-party/popper.js +0 -5
  258. package/docs/sidechat.js/2.5.3/scripts/third-party/tippy.js +0 -1
  259. package/docs/sidechat.js/2.5.3/scripts/third-party/tocbot.js +0 -672
  260. package/docs/sidechat.js/2.5.3/scripts/third-party/tocbot.min.js +0 -1
  261. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-base.css +0 -1159
  262. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-dark.css +0 -412
  263. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-light.css +0 -482
  264. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-scrollbar.css +0 -30
  265. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
  266. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme.min.css +0 -1
  267. package/docs/sidechat.js/2.5.3/tutorial-Authentication.html +0 -14
  268. package/docs/sidechat.js/2.5.3/tutorial-Email Registration.html +0 -6
  269. package/docs/sidechat.js/2.5.4/SidechatAPIClient.html +0 -3
  270. package/docs/sidechat.js/2.5.4/SidechatColorList.html +0 -3
  271. package/docs/sidechat.js/2.5.4/data/search.json +0 -1
  272. package/docs/sidechat.js/2.5.4/fonts/Inconsolata-Regular.ttf +0 -0
  273. package/docs/sidechat.js/2.5.4/fonts/OpenSans-Regular.ttf +0 -0
  274. package/docs/sidechat.js/2.5.4/fonts/WorkSans-Bold.ttf +0 -0
  275. package/docs/sidechat.js/2.5.4/global.html +0 -3
  276. package/docs/sidechat.js/2.5.4/scripts/core.js +0 -726
  277. package/docs/sidechat.js/2.5.4/scripts/core.min.js +0 -23
  278. package/docs/sidechat.js/2.5.4/scripts/resize.js +0 -90
  279. package/docs/sidechat.js/2.5.4/scripts/search.js +0 -265
  280. package/docs/sidechat.js/2.5.4/scripts/search.min.js +0 -6
  281. package/docs/sidechat.js/2.5.4/scripts/third-party/Apache-License-2.0.txt +0 -202
  282. package/docs/sidechat.js/2.5.4/scripts/third-party/fuse.js +0 -9
  283. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num-original.js +0 -369
  284. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num.js +0 -1
  285. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-original.js +0 -5171
  286. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs.js +0 -1
  287. package/docs/sidechat.js/2.5.4/scripts/third-party/popper.js +0 -5
  288. package/docs/sidechat.js/2.5.4/scripts/third-party/tippy.js +0 -1
  289. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.js +0 -672
  290. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.min.js +0 -1
  291. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-base.css +0 -1159
  292. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-dark.css +0 -412
  293. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-light.css +0 -482
  294. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-scrollbar.css +0 -30
  295. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
  296. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme.min.css +0 -1
  297. package/docs/sidechat.js/2.5.4/types_SidechatTypes.js.html +0 -180
  298. package/docs/sidechat.js/2.5.5/SidechatAPIClient.html +0 -3
  299. package/docs/sidechat.js/2.5.5/SidechatColorList.html +0 -3
  300. package/docs/sidechat.js/2.5.5/classes_SidechatColorList.js.html +0 -79
  301. package/docs/sidechat.js/2.5.5/data/search.json +0 -1
  302. package/docs/sidechat.js/2.5.5/fonts/Inconsolata-Regular.ttf +0 -0
  303. package/docs/sidechat.js/2.5.5/fonts/OpenSans-Regular.ttf +0 -0
  304. package/docs/sidechat.js/2.5.5/fonts/WorkSans-Bold.ttf +0 -0
  305. package/docs/sidechat.js/2.5.5/global.html +0 -3
  306. package/docs/sidechat.js/2.5.5/index.html +0 -4
  307. package/docs/sidechat.js/2.5.5/scripts/core.js +0 -726
  308. package/docs/sidechat.js/2.5.5/scripts/core.min.js +0 -23
  309. package/docs/sidechat.js/2.5.5/scripts/resize.js +0 -90
  310. package/docs/sidechat.js/2.5.5/scripts/search.js +0 -265
  311. package/docs/sidechat.js/2.5.5/scripts/search.min.js +0 -6
  312. package/docs/sidechat.js/2.5.5/scripts/third-party/Apache-License-2.0.txt +0 -202
  313. package/docs/sidechat.js/2.5.5/scripts/third-party/fuse.js +0 -9
  314. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-line-num-original.js +0 -369
  315. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-line-num.js +0 -1
  316. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-original.js +0 -5171
  317. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs.js +0 -1
  318. package/docs/sidechat.js/2.5.5/scripts/third-party/popper.js +0 -5
  319. package/docs/sidechat.js/2.5.5/scripts/third-party/tippy.js +0 -1
  320. package/docs/sidechat.js/2.5.5/scripts/third-party/tocbot.js +0 -672
  321. package/docs/sidechat.js/2.5.5/scripts/third-party/tocbot.min.js +0 -1
  322. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-base.css +0 -1159
  323. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-dark.css +0 -412
  324. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-light.css +0 -482
  325. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-scrollbar.css +0 -30
  326. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
  327. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme.min.css +0 -1
  328. package/docs/sidechat.js/2.5.5/types_SidechatTypes.js.html +0 -180
package/dist/index.cjs CHANGED
@@ -217,1355 +217,1427 @@ class SidechatAPIError extends Error {
217
217
  }
218
218
  }
219
219
 
220
- /**
221
- * API client class for making requests to Sidechat's private API. You'll need to [authenticate]{@tutorial Authentication} before using most of the methods.
222
- * @class
223
- * @since 2.0.0-alpha.0
224
- */
225
- class SidechatAPIClient {
226
- /**
227
- * User bearer token
228
- * @type {SidechatAuthToken}
229
- * */
230
- userToken;
231
-
232
- /**
233
- * Default headers for every API request
234
- * @type {Object}
235
- * @static
236
- * @constant
237
- */
238
- defaultHeaders = {
239
- Accept: "application/json",
240
- "Content-Type": "application/json",
241
- "App-Version": "6.0.0",
242
- Dnt: 1,
243
- };
244
-
245
- /**
246
- * Root URL for every API request
247
- * @type {String}
248
- * @default "https://api.sidechat.lol"
249
- */
250
- apiRoot = "https://api.sidechat.lol";
251
-
252
- /**
253
- * Create a new instance of the API client
254
- * @param {SidechatAuthToken} [token] - user bearer token
255
- * @param {String} rootUrl - custom API root URL for mocking or using other server
256
- */
257
- constructor(token = "", rootUrl = "") {
258
- if (token) {
259
- this.userToken = token;
260
- }
261
- if (rootUrl) {
262
- this.apiRoot = rootUrl;
263
- }
264
- }
265
-
266
- /**
267
- * Manually set the currently signed in user's token. Generally try to avoid this and instead either pass a token to the constructor or login automatically through the auth functions
268
- * @method
269
- * @param {SidechatAuthToken} token - user bearer token
270
- */
271
- setToken = (token) => {
272
- this.userToken = token;
273
- };
274
-
275
- /**
276
- * Manually set the root URL for all API requests. This can be used for mocking requests or redirecting them to a different server
277
- * @method
278
- * @param {String} url - new root URL to set
279
- * @since 2.3.9
280
- */
281
- setAPIRoot = (url) => {
282
- this.apiRoot = url;
283
- };
284
-
285
- /**
286
- * Run an arbitrary API request using the current client's authentication
287
- * @method
288
- * @param {String} endpoint - API endpoint to request (e.g. "/v1/posts")
289
- * @param {"GET"|"POST"|"PUT"|"DELETE"|"PATCH"|"OPTIONS"} [method] - HTTP method to use
290
- * @param {Object} [body] - body to send with the request
291
- * @param {Object} [headers] - custom headers to send with the request
292
- * @param {Boolean} [stripHeaders] - remove the default headers from the request
293
- * @since 2.4.9
294
- */
295
- sendRequest = (
296
- endpoint,
297
- method = "GET",
298
- body = undefined,
299
- headers = {},
300
- stripHeaders = false
301
- ) => {
302
- let requestHeaders = this.defaultHeaders;
303
- if (stripHeaders) {
304
- headers = {};
305
- }
306
- requestHeaders = { ...requestHeaders, ...headers };
307
- return fetch(`${this.apiRoot}${endpoint}`, {
308
- headers: { Authorization: `Bearer ${this.userToken}`, ...requestHeaders },
309
- body: body,
310
- method: method,
311
- });
312
- };
313
-
314
- /**
315
- * Initiate the login process with a phone number. Should be followed up with verifySMSCode().
316
- * @method
317
- * @since 1.0.0
318
- * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
319
- */
320
- loginViaSMS = async (phoneNumber) => {
321
- try {
322
- const res = await fetch(`${this.apiRoot}/v1/login_register`, {
323
- method: "POST",
324
- headers: this.defaultHeaders,
325
- body: JSON.stringify({
326
- phone_number: `+1${phoneNumber}`,
327
- version: 3,
328
- }),
329
- });
330
- const json = await res.json();
331
- return json;
332
- } catch (err) {
333
- console.error(err);
334
- throw new SidechatAPIError("Failed to request SMS verification.");
335
- }
336
- };
337
-
338
- /**
339
- * Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
340
- * @method
341
- * @since 1.0.0
342
- * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
343
- * @param {String} code - the verification code
344
- */
345
- verifySMSCode = async (phoneNumber, code) => {
346
- try {
347
- const res = await fetch(`${this.apiRoot}/v1/verify_phone_number`, {
348
- method: "POST",
349
- headers: this.defaultHeaders,
350
- body: JSON.stringify({
351
- phone_number: `+1${phoneNumber}`,
352
- code: code.toUpperCase(),
353
- }),
354
- });
355
- const json = await res.json();
356
- if (json?.logged_in_user?.token) {
357
- this.userToken = json.logged_in_user.token;
358
- }
359
- return json;
360
- } catch (err) {
361
- console.error(err);
362
- throw new SidechatAPIError("Failed verify this code.");
363
- }
364
- };
365
-
366
- /**
367
- * Set the user's age. If this function succeeds, the user will be authenticated for future requests.
368
- * @method
369
- * @since 1.0.0
370
- * @param {Number} age - user's age in years
371
- * @param {String} registrationID - the registration ID generated by verifySMSCode()
372
- */
373
- setAge = async (age, registrationID) => {
374
- if (age < 13) {
375
- throw new SidechatAPIError("You're too young to use Offsides.");
376
- }
377
- try {
378
- const res = await fetch(`${this.apiRoot}/v1/complete_registration`, {
379
- method: "POST",
380
- headers: this.defaultHeaders,
381
- body: JSON.stringify({
382
- age: Number(age),
383
- registration_id: registrationID,
384
- }),
385
- });
386
- const json = await res.json();
387
- if (json.token) {
388
- this.userToken = json.token;
389
- }
390
- return json;
391
- } catch (err) {
392
- console.error(err);
393
- throw new SidechatAPIError("Failed verify this code.");
394
- }
395
- };
396
-
397
- /**
398
- * Initiate the email setup process. Should be followed up with checkEmailVerification().
399
- * @method
400
- * @since 1.0.0
401
- * @param {String} email - school email address to send verification code to
402
- * @tutorial Email Registration
403
- */
404
- registerEmail = async (email) => {
405
- if (!this.userToken) {
406
- throw new SidechatAPIError("User is not authenticated.");
407
- }
408
- try {
409
- const res = await fetch(`${this.apiRoot}/v2/users/register_email`, {
410
- method: "POST",
411
- headers: {
412
- ...this.defaultHeaders,
413
- Authorization: `Bearer ${this.userToken}`,
414
- },
415
- body: JSON.stringify({
416
- email: email,
417
- }),
418
- });
419
- const json = await res.json();
420
- if (json.message) {
421
- throw new SidechatAPIError(json.message);
422
- }
423
- return json;
424
- } catch (err) {
425
- console.error(err);
426
- throw new SidechatAPIError("Failed to request email verification.");
427
- }
428
- };
429
-
430
- /**
431
- * Check is the user's email is verified.
432
- * @method
433
- * @since 1.0.0
434
- */
435
- checkEmailVerification = async () => {
436
- if (!this.userToken) {
437
- throw new SidechatAPIError("User is not authenticated.");
438
- }
439
- try {
440
- const res = await fetch(`${this.apiRoot}/v1/users/check_email_verified`, {
441
- method: "GET",
442
- headers: {
443
- ...this.defaultHeaders,
444
- Authorization: `Bearer ${this.userToken}`,
445
- },
446
- });
447
- const json = await res.json();
448
- if (json.verified_email_updates_response) {
449
- return json.verified_email_updates_response;
450
- } else {
451
- throw new SidechatAPIError(json?.message || "Email is not verified.");
452
- }
453
- } catch (err) {
454
- console.error(err);
455
- throw new SidechatAPIError("Email is not verified.");
456
- }
457
- };
458
-
459
- /**
460
- * Set the device ID of the current user
461
- * @method
462
- * @since 1.0.0
463
- * @param {String} deviceId - the device ID to set
464
- */
465
- setDeviceID = async (deviceID) => {
466
- if (!this.userToken) {
467
- throw new SidechatAPIError("User is not authenticated.");
468
- }
469
- try {
470
- const res = await fetch(`${this.apiRoot}/v1/register_device_token`, {
471
- method: "POST",
472
- headers: {
473
- ...this.defaultHeaders,
474
- Authorization: `Bearer ${this.userToken}`,
475
- },
476
- body: JSON.stringify({
477
- build_type: "release",
478
- bundle_id: "com.flowerave.sidechat",
479
- device_token: deviceID,
480
- }),
481
- });
482
- const json = await res.json();
483
- return json;
484
- } catch (err) {
485
- console.error(err);
486
- throw new SidechatAPIError("Failed verify this code.");
487
- }
488
- };
489
-
490
- /**
491
- * Get updated status for user and group
492
- * @method
493
- * @since 1.0.0
494
- * @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
495
- * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
496
- */
497
- getUserAndGroup = async (groupID = "") => {
498
- const json = await this.getUpdates(groupID);
499
- return json;
500
- };
501
-
502
- /**
503
- * Get updated status for user and group
504
- * @method
505
- * @since 2.1.0
506
- * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
507
- */
508
- getUpdates = async (groupID = "") => {
509
- if (!this.userToken) {
510
- throw new SidechatAPIError("User is not authenticated.");
511
- }
512
- try {
513
- const res = await fetch(
514
- `${this.apiRoot}/v1/updates?group_id=${groupID}`,
515
- {
516
- method: "GET",
517
- headers: {
518
- ...this.defaultHeaders,
519
- Authorization: `Bearer ${this.userToken}`,
520
- },
521
- }
522
- );
523
- const json = await res.json();
524
- return json;
525
- } catch (err) {
526
- console.error(err);
527
- throw new SidechatAPIError(`Failed to get posts from group.`);
528
- }
529
- };
530
-
531
- /**
532
- * Fetches posts from the specified category in a group
533
- * @method
534
- * @since 1.0.0
535
- * @param {String} groupID - group ID
536
- * @param {"hot"|"recent"|"top"} category - category to filter posts
537
- * @param {SidechatCursorString} [cursor] - cursor string
538
- * @returns {SidechatPostsAndCursor} List of posts and cursor
539
- */
540
- getGroupPosts = async (groupID, category = "hot", cursor) => {
541
- if (!this.userToken) {
542
- throw new SidechatAPIError("User is not authenticated.");
543
- }
544
- try {
545
- const res = await fetch(
546
- `${this.apiRoot}/v1/posts?${cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
547
- }group_id=${groupID}&type=${category}`,
548
- {
549
- method: "GET",
550
- headers: {
551
- ...this.defaultHeaders,
552
- Authorization: `Bearer ${this.userToken}`,
553
- },
554
- }
555
- );
556
- const json = await res.json();
557
- return json;
558
- } catch (err) {
559
- console.error(err);
560
- throw new SidechatAPIError(`Failed to get posts from group.`);
561
- }
562
- };
563
-
564
- /**
565
- * Upvote or downvote, or unvote a post
566
- * @method
567
- * @since 2.0.0-alpha.0
568
- * @param {String} postID - post ID to vote on
569
- * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote
570
- */
571
- setVote = async (postID, action) => {
572
- if (!this.userToken) {
573
- throw new SidechatAPIError("User is not authenticated.");
574
- }
575
- try {
576
- const res = await fetch(`${this.apiRoot}/v1/posts/set_vote`, {
577
- method: "POST",
578
- headers: {
579
- ...this.defaultHeaders,
580
- Authorization: `Bearer ${this.userToken}`,
581
- },
582
- body: JSON.stringify({
583
- post_id: postID,
584
- vote_status: action,
585
- }),
586
- });
587
- const json = await res.json();
588
- return json;
589
- } catch (err) {
590
- console.error(err);
591
- throw new SidechatAPIError(`Failed to change the vote on post.`);
592
- }
593
- };
594
-
595
- /**
596
- * Fetches a single post with just its ID
597
- * @method
598
- * @since 2.3.0
599
- * @param {String} postID - ID of post to fetch
600
- * @param {Boolean} includeDeleted - undocumented
601
- * @returns {SidechatPostOrComment} post object
602
- */
603
- getPost = async (postID, includeDeleted = false) => {
604
- if (!this.userToken) {
605
- throw new SidechatAPIError("User is not authenticated.");
606
- }
607
- try {
608
- const res = await fetch(
609
- `${this.apiRoot}/v1/posts/get?include_deleted=${includeDeleted}&post_id=${postID}`,
610
- {
611
- method: "GET",
612
- headers: {
613
- ...this.defaultHeaders,
614
- Authorization: `Bearer ${this.userToken}`,
615
- },
616
- }
617
- );
618
- const json = await res.json();
619
- return json.post;
620
- } catch (err) {
621
- console.error(err);
622
- throw new SidechatAPIError(`Failed to get post from ID.`);
623
- }
624
- };
625
-
626
- /**
627
- * Fetches the posts or comments that the user has created
628
- * @method
629
- * @since 2.3.5
630
- * @param {"posts"|"comments"} contentType - type of user content to fetch
631
- * @returns {SidechatPostOrComment[]} post object
632
- */
633
- getUserContent = async (contentType) => {
634
- if (!this.userToken) {
635
- throw new SidechatAPIError("User is not authenticated.");
636
- }
637
- if (contentType == "posts") {
638
- contentType = "my_posts";
639
- } else if (contentType == "comments") {
640
- contentType = "my_comments";
641
- }
642
- try {
643
- const res = await fetch(`${this.apiRoot}/v1/posts&type=${contentType}`, {
644
- method: "GET",
645
- headers: {
646
- ...this.defaultHeaders,
647
- Authorization: `Bearer ${this.userToken}`,
648
- },
649
- });
650
- const json = await res.json();
651
- return json.posts;
652
- } catch (err) {
653
- console.error(err);
654
- throw new SidechatAPIError(`Failed to get content from user.`);
655
- }
656
- };
657
-
658
- /**
659
- * Get all the commments on a post
660
- * @method
661
- * @since 2.0.0-alpha.0
662
- * @param {String} postID - post ID to get comments for
663
- * @returns {SidechatPostOrComment[]} list of comments
664
- */
665
- getPostComments = async (postID) => {
666
- if (!this.userToken) {
667
- throw new SidechatAPIError("User is not authenticated.");
668
- }
669
- try {
670
- const res = await fetch(
671
- `${this.apiRoot}/v1/posts/comments/?post_id=${postID}`,
672
- {
673
- method: "GET",
674
- headers: {
675
- ...this.defaultHeaders,
676
- Authorization: `Bearer ${this.userToken}`,
677
- },
678
- }
679
- );
680
- const json = await res.json();
681
- // Function to preprocess the comments and organize them into a nested structure
682
- function preprocessComments(apiComments) {
683
- // Map to store comments by their IDs for efficient lookup
684
- const commentMap = new Map();
685
- // List to store top-level comments
686
- const topLevelComments = [];
687
-
688
- // Iterate through the API comments
689
- apiComments.forEach((comment) => {
690
- // Store the comment in the map with its ID as the key
691
- commentMap.set(comment.id, comment);
692
- // Get the parent comment using the reply_post_id
693
- const parentComment = commentMap.get(comment.reply_post_id);
694
- // Check if the comment is a top-level comment
695
- if (
696
- !parentComment ||
697
- comment.reply_post_id === comment.parent_post_id
698
- ) {
699
- // If it's a top-level comment, push it to the topLevelComments array
700
- topLevelComments.push(comment);
701
- } else {
702
- // If it's a reply, add it to the parent comment's replies array
703
- if (!parentComment.replies) parentComment.replies = [];
704
- parentComment.replies.push(comment);
705
- }
706
- });
707
-
708
- // Flatten the nested structure and return a single list of comments
709
- return flattenComments(topLevelComments);
710
- }
711
-
712
- // Function to flatten nested comments into a single list
713
- function flattenComments(comments) {
714
- // Use reduce to flatten the nested comments array into a single list
715
- return comments.reduce((flatComments, comment) => {
716
- // Push the current comment to the flatComments array
717
- flatComments.push(comment);
718
- // If the current comment has replies, recursively flatten them and push to the flatComments array
719
- if (comment.replies)
720
- flatComments.push(...flattenComments(comment.replies));
721
- // Return the flatComments array
722
- return flatComments;
723
- }, []);
724
- }
725
-
726
- const sortedComments = preprocessComments(json.posts);
727
- return sortedComments;
728
- } catch (err) {
729
- console.error(err);
730
- throw new SidechatAPIError(`Failed to get comments on post.`);
731
- }
732
- };
733
-
734
- /**
735
- * Gets groups to be displayed on the "Explore Groups" page
736
- * @method
737
- * @since 2.0.0-alpha.0
738
- * @param {Boolean} onePage - whether or not results should be returned as a single page
739
- * @returns {SidechatGroup[]}
740
- */
741
- getAvailableGroups = async (onePage = true) => {
742
- if (!this.userToken) {
743
- throw new SidechatAPIError("User is not authenticated.");
744
- }
745
- try {
746
- const res = await fetch(`${this.apiRoot}/v1/groups/explore`, {
747
- method: "GET",
748
- headers: {
749
- ...this.defaultHeaders,
750
- "App-Version": onePage ? "0" : this.defaultHeaders["App-Version"],
751
- Authorization: `Bearer ${this.userToken}`,
752
- },
753
- });
754
- const json = await res.json();
755
- return await json.groups;
756
- } catch (err) {
757
- console.error(err);
758
- throw new SidechatAPIError(`Failed to get groups from explore.`);
759
- }
760
- };
761
-
762
- /**
763
- * Searches for new groups based on a query keyword
764
- * @method
765
- * @since 2.6.0
766
- * @param {String} query - the string to search for. This will be encoded, so strings with spaces and special characters are okay.
767
- * @returns {SidechatGroup[]}
768
- */
769
- searchAvailableGroups = async (query) => {
770
- if (!this.userToken) {
771
- throw new SidechatAPIError("User is not authenticated.");
772
- }
773
- try {
774
- const res = await fetch(`${this.apiRoot}/v1/groups/explore/search?term=${encodeURIComponent(query)}`, {
775
- method: "GET",
776
- headers: {
777
- ...this.defaultHeaders,
778
- Authorization: `Bearer ${this.userToken}`,
779
- },
780
- });
781
- const json = await res.json();
782
- return await json.results;
783
- } catch (err) {
784
- console.error(err);
785
- throw new SidechatAPIError(`Failed to search groups.`);
786
- }
787
- };
788
-
789
- /**
790
- * Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
791
- * @method
792
- * @since 2.0.6
793
- * @returns {SidechatLibraryAsset[]}
794
- */
795
- getAssetLibrary = async () => {
796
- if (!this.userToken) {
797
- throw new SidechatAPIError("User is not authenticated.");
798
- }
799
- try {
800
- const res = await fetch(`${this.apiRoot}/v1/assets/library`, {
801
- method: "GET",
802
- headers: {
803
- ...this.defaultHeaders,
804
- Authorization: `Bearer ${this.userToken}`,
805
- },
806
- });
807
- const json = await res.json();
808
- return await json.items;
809
- } catch (err) {
810
- console.error(err);
811
- throw new SidechatAPIError(`Failed to get asset library.`);
812
- }
813
- };
814
-
815
- /**
816
- * Gets the current authenticated user and a list of the groups of which they are members.
817
- * @method
818
- * @since 2.1.0
819
- * @returns {SidechatCurrentUser}
820
- */
821
- getCurrentUser = async () => {
822
- if (!this.userToken) {
823
- throw new SidechatAPIError("User is not authenticated.");
824
- }
825
- try {
826
- const res = await fetch(`${this.apiRoot}/v1/users/me`, {
827
- method: "GET",
828
- headers: {
829
- ...this.defaultHeaders,
830
- Authorization: `Bearer ${this.userToken}`,
831
- },
832
- });
833
- const json = await res.json();
834
- return await json;
835
- } catch (err) {
836
- console.error(err);
837
- throw new SidechatAPIError(`Failed to get asset library.`);
838
- }
839
- };
840
-
841
- /**
842
- * Gets the metadata of a group from its ID
843
- * @method
844
- * @since 2.1.0
845
- * @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
846
- * @returns {SidechatGroup}
847
- */
848
- getGroupMetadata = async (groupID = "") => {
849
- if (!this.userToken) {
850
- throw new SidechatAPIError("User is not authenticated.");
851
- }
852
- try {
853
- const res = await fetch(`${this.apiRoot}/v1/groups/${groupID}`, {
854
- method: "GET",
855
- headers: {
856
- ...this.defaultHeaders,
857
- Authorization: `Bearer ${this.userToken}`,
858
- },
859
- });
860
- const json = await res.json();
861
- return await json.group;
862
- } catch (err) {
863
- console.error(err);
864
- throw new SidechatAPIError(`Failed to get group metadata.`);
865
- }
866
- };
867
-
868
- /**
869
- * Joins or leaves a group
870
- * @method
871
- * @param {String} groupID - alphanumeric ID of group to join or leave
872
- * @param {Boolean} isMember - whether or not the user should be a member of the group
873
- * @since 2.3.8
874
- */
875
- setGroupMembership = async (groupID, isMember) => {
876
- if (!this.userToken) {
877
- throw new SidechatAPIError("User is not authenticated.");
878
- }
879
- try {
880
- const res = await fetch(
881
- `${this.apiRoot}/v1/groups/${isMember ? "join" : "leave"}`,
882
- {
883
- method: "POST",
884
- headers: {
885
- ...this.defaultHeaders,
886
- Authorization: `Bearer ${this.userToken}`,
887
- },
888
- body: JSON.stringify({
889
- group_id: groupID,
890
- }),
891
- }
892
- );
893
- const json = await res.json();
894
- return await json;
895
- } catch (err) {
896
- console.error(err);
897
- throw new SidechatAPIError(`Failed to modify group membership.`);
898
- }
899
- };
900
-
901
- /**
902
- * Creates a comment on a post
903
- * @method
904
- * @since 2.2.0
905
- * @param {String} parentPostID - alphanumeric ID of post on which this comment is made
906
- * @param {String} text - text content of comment
907
- * @param {String} groupID - alphanumeric ID of group in which the parent post resides
908
- * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
909
- * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
910
- * @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
911
- * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
912
- * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
913
- * @returns {SidechatPostOrComment} created comment
914
- */
915
- createComment = async (
916
- parentPostID,
917
- text,
918
- groupID,
919
- replyCommentID,
920
- topLevelReplyID,
921
- assetList = [],
922
- disableDMs = false,
923
- anonymous = false
924
- ) => {
925
- if (!this.userToken) {
926
- throw new SidechatAPIError("User is not authenticated.");
927
- }
928
- try {
929
- const res = await fetch(`${this.apiRoot}/v1/posts`, {
930
- method: "POST",
931
- headers: {
932
- ...this.defaultHeaders,
933
- Authorization: `Bearer ${this.userToken}`,
934
- },
935
- body: JSON.stringify({
936
- type: "comment",
937
- assets: assetList,
938
- group_ids: [groupID],
939
- text: text,
940
- reply_post_id: topLevelReplyID || replyCommentID || parentPostID,
941
- reply_comment_post_id: replyCommentID || parentPostID,
942
- parent_post_id: parentPostID,
943
- dms_disabled: disableDMs,
944
- using_identity: !anonymous,
945
- }),
946
- });
947
- const json = await res.json();
948
- return await json.comment;
949
- } catch (err) {
950
- console.error(err);
951
- throw new SidechatAPIError(`Failed to post comment.`);
952
- }
953
- };
954
-
955
- /**
956
- * Creates a new post in the specified group
957
- * @method
958
- * @since 2.2.0
959
- * @param {String} text - text content of comment
960
- * @param {String} groupID - alphanumeric ID of group in which the parent post resides
961
- * @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach.
962
- * @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
963
- * @param {Boolean} [disableComments] - whether or not comments should be disabled on post
964
- * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on post
965
- * @returns {SidechatPostOrComment} the created post
966
- */
967
- createPost = async (
968
- text,
969
- groupID,
970
- assetList = [],
971
- disableDMs = false,
972
- disableComments = false,
973
- anonymous = false,
974
- repostId = undefined
975
- ) => {
976
- if (!this.userToken) {
977
- throw new SidechatAPIError("User is not authenticated.");
978
- }
979
- try {
980
- const res = await fetch(`${this.apiRoot}/v1/posts`, {
981
- method: "POST",
982
- headers: {
983
- ...this.defaultHeaders,
984
- Authorization: `Bearer ${this.userToken}`,
985
- },
986
- body: JSON.stringify({
987
- type: "post",
988
- assets: assetList,
989
- group_ids: [groupID],
990
- text: text,
991
- attachments: [],
992
- dms_disabled: disableDMs,
993
- comments_disabled: disableComments,
994
- using_identity: !anonymous,
995
- quote_post_id: repostId
996
- }),
997
- });
998
- const json = await res.json();
999
- return await json.posts[0];
1000
- } catch (err) {
1001
- console.error(err);
1002
- throw new SidechatAPIError(`Failed to make post.`);
1003
- }
1004
- };
1005
-
1006
- /**
1007
- * Deletes a post or comment that the user created
1008
- * @method
1009
- * @since 2.2.0
1010
- * @param {String} postOrCommentID - alphanumeric ID of post to delete
1011
- */
1012
- deletePostOrComment = async (postOrCommentID) => {
1013
- if (!this.userToken) {
1014
- throw new SidechatAPIError("User is not authenticated.");
1015
- }
1016
- try {
1017
- const res = await fetch(`${this.apiRoot}/v1/posts/delete`, {
1018
- method: "POST",
1019
- headers: {
1020
- ...this.defaultHeaders,
1021
- Authorization: `Bearer ${this.userToken}`,
1022
- },
1023
- body: JSON.stringify({
1024
- post_id: postOrCommentID,
1025
- }),
1026
- });
1027
- const json = await res.json();
1028
- return await json;
1029
- } catch (err) {
1030
- console.error(err);
1031
- throw new SidechatAPIError(`Failed to delete post.`);
1032
- }
1033
- };
1034
-
1035
- /**
1036
- * Votes on a poll attached to a post
1037
- * @method
1038
- * @param {String} pollId - alphanumeric ID of poll to vote on
1039
- * @param {Number} choiceIndex - index of the choice to vote on
1040
- * @since 2.5.4
1041
- */
1042
- voteOnPoll = async (pollId, choiceIndex) => {
1043
- if (!this.userToken) {
1044
- throw new SidechatAPIError("User is not authenticated.");
1045
- }
1046
- try {
1047
- const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
1048
- method: "POST",
1049
- headers: {
1050
- ...this.defaultHeaders,
1051
- Authorization: `Bearer ${this.userToken}`,
1052
- },
1053
- body: JSON.stringify({
1054
- poll_id: pollId,
1055
- choice: choiceIndex,
1056
- }),
1057
- });
1058
- const json = await res.json();
1059
- return await json;
1060
- } catch (err) {
1061
- console.error(err);
1062
- throw new SidechatAPIError(`Failed to vote on poll`);
1063
- }
1064
- };
1065
-
1066
- /**
1067
- * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1068
- * @method
1069
- * @param {String} pollId - alphanumeric ID of poll to vote on
1070
- * @since 2.5.4
1071
- */
1072
- viewPollResults = async (pollId) => {
1073
- if (!this.userToken) {
1074
- throw new SidechatAPIError("User is not authenticated.");
1075
- }
1076
- try {
1077
- const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1078
- method: "POST",
1079
- headers: {
1080
- ...this.defaultHeaders,
1081
- Authorization: `Bearer ${this.userToken}`,
1082
- },
1083
- body: JSON.stringify({
1084
- poll_id: pollId,
1085
- }),
1086
- });
1087
- const json = await res.json();
1088
- return await json;
1089
- } catch (err) {
1090
- console.error(err);
1091
- throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1092
- }
1093
- };
1094
-
1095
- /**
1096
- * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
1097
- * @method
1098
- * @param {String} uri - URI of the asset to upload
1099
- * @param {String} mimeType - mimetype of the asset (e.g. "image/png")
1100
- * @param {String} [name] - filename of the asset
1101
- * @returns {String} URL of the uploaded asset
1102
- * @since 2.5.1
1103
- */
1104
- uploadAsset = async (uri, mimeType, name = "") => {
1105
- if (!this.userToken) {
1106
- throw new SidechatAPIError("User is not authenticated.");
1107
- }
1108
-
1109
- let imageType = mimeType.split("/")[1];
1110
- if (!["png", "jpeg", "gif"].includes(imageType)) {
1111
- throw new SidechatAPIError("Unsupported image format.");
1112
- }
1113
-
1114
- const data = new FormData();
1115
- data.append("image", {
1116
- name: name,
1117
- type: mimeType,
1118
- uri: uri,
1119
- });
1120
-
1121
- const urlReq = await this.sendRequest(`/v1/assets/upload_url?content_type=${imageType}`);
1122
- const urlJson = await urlReq.json();
1123
-
1124
- try {
1125
- const uploadReq = await fetch(urlJson.upload_url, {
1126
- body: data.getAll("image")[0],
1127
- method: "PUT",
1128
- headers: {
1129
- "Content-Type": mimeType,
1130
- },
1131
- });
1132
- if (uploadReq.status == 200) {
1133
- return `${this.apiRoot}/v1/assets/library/${urlJson.asset_id}`;
1134
- } else {
1135
- throw new SidechatAPIError(
1136
- `Couldn't upload image - error ${uploadReq.status}`
1137
- );
1138
- }
1139
- } catch (e) {
1140
- throw new SidechatAPIError(e.message);
1141
- }
1142
- };
1143
-
1144
- /**
1145
- * Sets the conversation icon of a user
1146
- * @method
1147
- * @since 2.2.1
1148
- * @param {String} userID - alphanumeric ID of user
1149
- * @param {String} emoji - emoji to set as icon
1150
- * @param {String} primaryColor - hex string (including #) of primary color
1151
- * @param {String} secondaryColor - hex string (including #) of secondary color
1152
- */
1153
- setUserIcon = async (userID, emoji, primaryColor, secondaryColor) => {
1154
- if (!this.userToken) {
1155
- throw new SidechatAPIError("User is not authenticated.");
1156
- }
1157
- try {
1158
- const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1159
- method: "PATCH",
1160
- headers: {
1161
- ...this.defaultHeaders,
1162
- "App-Version": "0",
1163
- Authorization: `Bearer ${this.userToken}`,
1164
- },
1165
- body: JSON.stringify({
1166
- conversation_icon: {
1167
- emoji: emoji,
1168
- secondary_color: secondaryColor,
1169
- is_migrated: true,
1170
- color: primaryColor,
1171
- },
1172
- }),
1173
- });
1174
- const json = await res.json();
1175
- return await json;
1176
- } catch (err) {
1177
- console.error(err);
1178
- throw new SidechatAPIError(`Failed to set icon.`);
1179
- }
1180
- };
1181
-
1182
- /**
1183
- * Sets the bio text of a user
1184
- * @method
1185
- * @since 2.5.6
1186
- * @param {String} userID - alphanumeric ID of user
1187
- * @param {String} bio - text to set as bio
1188
- */
1189
- setUserBio = async (userID, bio) => {
1190
- if (!this.userToken) {
1191
- throw new SidechatAPIError("User is not authenticated.");
1192
- }
1193
- try {
1194
- const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1195
- method: "PATCH",
1196
- headers: {
1197
- ...this.defaultHeaders,
1198
- "App-Version": "5.4.22",
1199
- Authorization: `Bearer ${this.userToken}`,
1200
- },
1201
- body: JSON.stringify({
1202
- bio: bio
1203
- }),
1204
- });
1205
- const json = await res.json();
1206
- return await json;
1207
- } catch (err) {
1208
- console.error(err);
1209
- throw new SidechatAPIError(`Failed to set bio.`);
1210
- }
1211
- };
1212
-
1213
- /**
1214
- * Checks if user can set their username to a string
1215
- * @method
1216
- * @since 2.3.6
1217
- * @param {String} username - string to check
1218
- * @returns {Boolean} whether or not username is valid and unused
1219
- */
1220
- checkUsername = async (username) => {
1221
- if (!this.userToken) {
1222
- throw new SidechatAPIError("User is not authenticated.");
1223
- }
1224
- try {
1225
- const res = await fetch(
1226
- `${this.apiRoot}/v1/users/username?username=${username}`,
1227
- {
1228
- method: "GET",
1229
- headers: {
1230
- ...this.defaultHeaders,
1231
- Authorization: `Bearer ${this.userToken}`,
1232
- },
1233
- }
1234
- );
1235
- if (res?.status == 200 || res?.status == 204) {
1236
- return true;
1237
- } else {
1238
- return false;
1239
- }
1240
- } catch (err) {
1241
- console.error(err);
1242
- throw new SidechatAPIError(`Failed to check username.`);
1243
- }
1244
- };
1245
-
1246
- /**
1247
- * Changes the username of the current user
1248
- * @method
1249
- * @since 2.3.6
1250
- * @param {String} userID - alphanumeric ID of user
1251
- * @param {String} username - new username to set
1252
- */
1253
- setUsername = async (userID, username) => {
1254
- if (!this.userToken) {
1255
- throw new SidechatAPIError("User is not authenticated.");
1256
- }
1257
- try {
1258
- const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1259
- method: "PATCH",
1260
- headers: {
1261
- ...this.defaultHeaders,
1262
- Authorization: `Bearer ${this.userToken}`,
1263
- },
1264
- body: JSON.stringify({
1265
- username: username,
1266
- }),
1267
- });
1268
- const json = await res.json();
1269
- return await json.user;
1270
- } catch (err) {
1271
- console.error(err);
1272
- throw new SidechatAPIError(`Failed to set icon.`);
1273
- }
1274
- };
1275
-
1276
- /**
1277
- * Fetches a public user profile
1278
- * @method
1279
- * @since 2.6.0
1280
- * @param {String} username - username of the user to fetch
1281
- * @returns {SidechatProfile}
1282
- */
1283
- getUserProfile = async (username) => {
1284
- if (!this.userToken) {
1285
- throw new SidechatAPIError("User is not authenticated.");
1286
- }
1287
- try {
1288
- const res = await fetch(`${this.apiRoot}/v1/groups/username?username=${username}`, {
1289
- method: "GET",
1290
- headers: {
1291
- ...this.defaultHeaders,
1292
- Authorization: `Bearer ${this.userToken}`,
1293
- }
1294
- });
1295
- const json = await res.json();
1296
- return await json.group;
1297
- } catch (err) {
1298
- console.error(err);
1299
- throw new SidechatAPIError(`Failed to set icon.`);
1300
- }
1301
- };
1302
-
1303
- /**
1304
- * Fetches a public user's posts
1305
- * @method
1306
- * @since 2.6.0
1307
- * @param {String} username - username of the user to fetch
1308
- * @returns {SidechatPostOrComment[]}
1309
- */
1310
- getUserPosts = async (username) => {
1311
- if (!this.userToken) {
1312
- throw new SidechatAPIError("User is not authenticated.");
1313
- }
1314
- try {
1315
- const res = await fetch(`${this.apiRoot}/v1/users/posts?username=${username}`, {
1316
- method: "GET",
1317
- headers: {
1318
- ...this.defaultHeaders,
1319
- Authorization: `Bearer ${this.userToken}`,
1320
- }
1321
- });
1322
- const json = await res.json();
1323
- return await json.posts;
1324
- } catch (err) {
1325
- console.error(err);
1326
- throw new SidechatAPIError(`Failed to set icon.`);
1327
- }
1328
- };
1329
-
1330
- /**
1331
- * Marks an activity item as read
1332
- * @method
1333
- * @since 2.3.2
1334
- * @param {String} activityID - alphanumeric ID of activity object
1335
- */
1336
- readActivity = async (activityID) => {
1337
- if (!this.userToken) {
1338
- throw new SidechatAPIError("User is not authenticated.");
1339
- }
1340
- try {
1341
- const res = await fetch(`${this.apiRoot}/v1/activity/seen`, {
1342
- method: "POST",
1343
- headers: {
1344
- ...this.defaultHeaders,
1345
- Authorization: `Bearer ${this.userToken}`,
1346
- },
1347
- body: JSON.stringify({
1348
- ids: [activityID],
1349
- }),
1350
- });
1351
- const json = await res.json();
1352
- return await json;
1353
- } catch (err) {
1354
- console.error(err);
1355
- throw new SidechatAPIError(`Failed to mark activity as read.`);
1356
- }
1357
- };
1358
-
1359
- /**
1360
- * Retrieves joinable group chats
1361
- * @method
1362
- * @since 2.3.5
1363
- */
1364
- getGroupChats = async () => {
1365
- if (!this.userToken) {
1366
- throw new SidechatAPIError("User is not authenticated.");
1367
- }
1368
- try {
1369
- const res = await fetch(`${this.apiRoot}/v1/chats/explore`, {
1370
- method: "GET",
1371
- headers: {
1372
- ...this.defaultHeaders,
1373
- Authorization: `Bearer ${this.userToken}`,
1374
- },
1375
- });
1376
- const json = await res.json();
1377
- return await json.chats;
1378
- } catch (err) {
1379
- console.error(err);
1380
- throw new SidechatAPIError(`Failed to get groupchats.`);
1381
- }
1382
- };
1383
-
1384
- /**
1385
- * Joins a group chat. To mimic the official client, use the user's display name and icon by default.
1386
- * @method
1387
- * @param {String} groupChatID - alphanumeric ID of group chat to join
1388
- * @param {String} displayName - display name to use in chat
1389
- * @param {String} emoji - emoji to use as icon
1390
- * @param {String} primaryColor - hex string of primary color
1391
- * @param {String} secondaryColor - hex string of secondary color
1392
- * @since 2.3.5
1393
- */
1394
- joinGroupChat = async (
1395
- groupChatID,
1396
- displayName,
1397
- emoji,
1398
- primaryColor,
1399
- secondaryColor
1400
- ) => {
1401
- if (!this.userToken) {
1402
- throw new SidechatAPIError("User is not authenticated.");
1403
- }
1404
- try {
1405
- const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
1406
- method: "POST",
1407
- headers: {
1408
- ...this.defaultHeaders,
1409
- Authorization: `Bearer ${this.userToken}`,
1410
- },
1411
- body: JSON.stringify({
1412
- chat_id: groupChatID,
1413
- identity: {
1414
- display_name: displayName,
1415
- emoji: emoji,
1416
- secondary_color: secondaryColor,
1417
- color: primaryColor,
1418
- },
1419
- }),
1420
- });
1421
- const json = await res.json();
1422
- return await json;
1423
- } catch (err) {
1424
- console.error(err);
1425
- throw new SidechatAPIError(`Failed to join groupchat.`);
1426
- }
1427
- };
1428
-
1429
- /**
1430
- * Gets a list of the user's direct messages
1431
- * @method
1432
- * @returns {SidechatDirectThread[]}
1433
- * @since 2.4.4
1434
- */
1435
- getDMs = async () => {
1436
- if (!this.userToken) {
1437
- throw new SidechatAPIError("User is not authenticated.");
1438
- }
1439
- try {
1440
- const res = await fetch(`${this.apiRoot}/v1/chats`, {
1441
- method: "GET",
1442
- headers: {
1443
- ...this.defaultHeaders,
1444
- Authorization: `Bearer ${this.userToken}`,
1445
- },
1446
- });
1447
- const json = await res.json();
1448
- const list = await json.chats;
1449
- let r = [];
1450
- list.forEach((o) => {
1451
- r.push(o.chat);
1452
- });
1453
- return await r;
1454
- } catch (err) {
1455
- console.error(err);
1456
- throw new SidechatAPIError(`Failed to fetch DMs.`);
1457
- }
1458
- };
1459
-
1460
- /**
1461
- * Gets a single direct message thread
1462
- * @method
1463
- * @param {String} id - alphanumeric ID of the chat to fetch
1464
- * @returns {SidechatDirectThread}
1465
- * @since 2.4.4
1466
- */
1467
- getDMThread = async (id) => {
1468
- if (!this.userToken) {
1469
- throw new SidechatAPIError("User is not authenticated.");
1470
- }
1471
- try {
1472
- const res = await fetch(
1473
- `${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
1474
- {
1475
- method: "GET",
1476
- headers: {
1477
- ...this.defaultHeaders,
1478
- Authorization: `Bearer ${this.userToken}`,
1479
- },
1480
- }
1481
- );
1482
- const json = await res.json();
1483
- return await json.chat;
1484
- } catch (err) {
1485
- console.error(err);
1486
- throw new SidechatAPIError(`Failed to fetch DM thread.`);
1487
- }
1488
- };
1489
-
1490
- /**
1491
- * Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
1492
- * @method
1493
- * @param {String} chatID - alphanumeric ID of the chat to send to
1494
- * @param {String} text - text content of message
1495
- * @param {String} clientID - alphanumeric device ID
1496
- * @param {SidechatAsset[]} assets - array of assets to send
1497
- * @param {Boolean} anonymous - whether the DM should be sent anonymously
1498
- * @since 2.4.4
1499
- */
1500
- sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
1501
- if (!this.userToken) {
1502
- throw new SidechatAPIError("User is not authenticated.");
1503
- }
1504
- try {
1505
- const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
1506
- method: "POST",
1507
- headers: {
1508
- ...this.defaultHeaders,
1509
- Authorization: `Bearer ${this.userToken}`,
1510
- },
1511
- body: JSON.stringify({
1512
- chat_id: chatID,
1513
- text: text,
1514
- client_id: clientID,
1515
- anonymous: anonymous,
1516
- assets: assets,
1517
- }),
1518
- });
1519
- const json = await res.json();
1520
- return await json;
1521
- } catch (err) {
1522
- console.error(err);
1523
- throw new SidechatAPIError(`Failed to send message.`);
1524
- }
1525
- };
1526
-
1527
- /**
1528
- * Creates a new direct message thread
1529
- * @method
1530
- * @param {String} text - text content of message
1531
- * @param {String} clientID - alphanumeric ID of devide
1532
- * @param {String} postID - alphanumeric ID of post or comment
1533
- * @param {Boolean} anonymous - whether the DM should be sent anonymously
1534
- * @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
1535
- * @since 2.4.4
1536
- */
1537
- startDM = async (
1538
- text,
1539
- clientID,
1540
- postID,
1541
- anonymous = false,
1542
- postContext = "feed"
1543
- ) => {
1544
- if (!this.userToken) {
1545
- throw new SidechatAPIError("User is not authenticated.");
1546
- }
1547
- try {
1548
- const res = await fetch(`${this.apiRoot}/v1/chats/start`, {
1549
- method: "POST",
1550
- headers: {
1551
- ...this.defaultHeaders,
1552
- Authorization: `Bearer ${this.userToken}`,
1553
- },
1554
- body: JSON.stringify({
1555
- text: text,
1556
- client_id: clientID,
1557
- post_id: postID,
1558
- anonymous: anonymous,
1559
- post_context: postContext,
1560
- }),
1561
- });
1562
- const json = await res.json();
1563
- return await json;
1564
- } catch (err) {
1565
- console.error(err);
1566
- throw new SidechatAPIError(`Failed to start DM.`);
1567
- }
1568
- };
220
+ /** @import * as types from "../types/SidechatTypes.js" */
221
+
222
+ /**
223
+ * API client class for making requests to Sidechat's private API. You'll need to [authenticate]{@tutorial Authentication} before using most of the methods.
224
+ * @class
225
+ * @since 2.0.0-alpha.0
226
+ */
227
+ class SidechatAPIClient {
228
+ /**
229
+ * User bearer token
230
+ * @type {types.SidechatAuthToken}
231
+ * */
232
+ userToken;
233
+
234
+ /**
235
+ * Default headers for every API request
236
+ * @type {Object}
237
+ * @static
238
+ * @constant
239
+ */
240
+ defaultHeaders = {
241
+ Accept: "application/json",
242
+ "Content-Type": "application/json",
243
+ "App-Version": "6.0.0",
244
+ Dnt: 1,
245
+ };
246
+
247
+ /**
248
+ * Root URL for every API request
249
+ * @type {String}
250
+ * @default "https://api.sidechat.lol"
251
+ */
252
+ apiRoot = "https://api.sidechat.lol";
253
+
254
+ /**
255
+ * Create a new instance of the API client
256
+ * @param {types.SidechatAuthToken} [token] - user bearer token
257
+ * @param {String} rootUrl - custom API root URL for mocking or using other server
258
+ */
259
+ constructor(token = "", rootUrl = "") {
260
+ if (token) {
261
+ this.userToken = token;
262
+ }
263
+ if (rootUrl) {
264
+ this.apiRoot = rootUrl;
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Manually set the currently signed in user's token. Generally try to avoid this and instead either pass a token to the constructor or login automatically through the auth functions
270
+ * @method
271
+ * @param {types.SidechatAuthToken} token - user bearer token
272
+ */
273
+ setToken = (token) => {
274
+ this.userToken = token;
275
+ };
276
+
277
+ /**
278
+ * Manually set the root URL for all API requests. This can be used for mocking requests or redirecting them to a different server
279
+ * @method
280
+ * @param {String} url - new root URL to set
281
+ * @since 2.3.9
282
+ */
283
+ setAPIRoot = (url) => {
284
+ this.apiRoot = url;
285
+ };
286
+
287
+ /**
288
+ * Run an arbitrary API request using the current client's authentication
289
+ * @method
290
+ * @param {String} endpoint - API endpoint to request (e.g. "/v1/posts")
291
+ * @param {"GET"|"POST"|"PUT"|"DELETE"|"PATCH"|"OPTIONS"} [method] - HTTP method to use
292
+ * @param {Object} [body] - body to send with the request
293
+ * @param {Object} [headers] - custom headers to send with the request
294
+ * @param {Boolean} [stripHeaders] - remove the default headers from the request
295
+ * @since 2.4.9
296
+ */
297
+ sendRequest = (
298
+ endpoint,
299
+ method = "GET",
300
+ body = undefined,
301
+ headers = {},
302
+ stripHeaders = false
303
+ ) => {
304
+ let requestHeaders = this.defaultHeaders;
305
+ if (stripHeaders) {
306
+ headers = {};
307
+ }
308
+ requestHeaders = { ...requestHeaders, ...headers };
309
+ return fetch(`${this.apiRoot}${endpoint}`, {
310
+ headers: { Authorization: `Bearer ${this.userToken}`, ...requestHeaders },
311
+ body: body,
312
+ method: method,
313
+ });
314
+ };
315
+
316
+ /**
317
+ * Initiate the login process with a phone number. Should be followed up with verifySMSCode().
318
+ * @method
319
+ * @since 1.0.0
320
+ * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
321
+ */
322
+ loginViaSMS = async (phoneNumber) => {
323
+ try {
324
+ const res = await fetch(`${this.apiRoot}/v1/login_register`, {
325
+ method: "POST",
326
+ headers: this.defaultHeaders,
327
+ body: JSON.stringify({
328
+ phone_number: `+1${phoneNumber}`,
329
+ version: 3,
330
+ }),
331
+ });
332
+ const json = await res.json();
333
+ return json;
334
+ } catch (err) {
335
+ console.error(err);
336
+ throw new SidechatAPIError("Failed to request SMS verification.");
337
+ }
338
+ };
339
+
340
+ /**
341
+ * Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
342
+ * @method
343
+ * @since 1.0.0
344
+ * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
345
+ * @param {String} code - the verification code
346
+ */
347
+ verifySMSCode = async (phoneNumber, code) => {
348
+ try {
349
+ const res = await fetch(`${this.apiRoot}/v1/verify_phone_number`, {
350
+ method: "POST",
351
+ headers: this.defaultHeaders,
352
+ body: JSON.stringify({
353
+ phone_number: `+1${phoneNumber}`,
354
+ code: code.toUpperCase(),
355
+ }),
356
+ });
357
+ const json = await res.json();
358
+ if (json?.logged_in_user?.token) {
359
+ this.userToken = json.logged_in_user.token;
360
+ }
361
+ return json;
362
+ } catch (err) {
363
+ console.error(err);
364
+ throw new SidechatAPIError("Failed verify this code.");
365
+ }
366
+ };
367
+
368
+ /**
369
+ * Set the user's age. If this function succeeds, the user will be authenticated for future requests.
370
+ * @method
371
+ * @since 1.0.0
372
+ * @param {Number} age - user's age in years
373
+ * @param {String} registrationID - the registration ID generated by verifySMSCode()
374
+ */
375
+ setAge = async (age, registrationID) => {
376
+ if (age < 13) {
377
+ throw new SidechatAPIError("You're too young to use Offsides.");
378
+ }
379
+ try {
380
+ const res = await fetch(`${this.apiRoot}/v1/complete_registration`, {
381
+ method: "POST",
382
+ headers: this.defaultHeaders,
383
+ body: JSON.stringify({
384
+ age: Number(age),
385
+ registration_id: registrationID,
386
+ }),
387
+ });
388
+ const json = await res.json();
389
+ if (json.token) {
390
+ this.userToken = json.token;
391
+ }
392
+ return json;
393
+ } catch (err) {
394
+ console.error(err);
395
+ throw new SidechatAPIError("Failed verify this code.");
396
+ }
397
+ };
398
+
399
+ /**
400
+ * Initiate the email setup process. Should be followed up with checkEmailVerification().
401
+ * @method
402
+ * @since 1.0.0
403
+ * @param {String} email - school email address to send verification code to
404
+ * @tutorial Email Registration
405
+ */
406
+ registerEmail = async (email) => {
407
+ if (!this.userToken) {
408
+ throw new SidechatAPIError("User is not authenticated.");
409
+ }
410
+ try {
411
+ const res = await fetch(`${this.apiRoot}/v2/users/register_email`, {
412
+ method: "POST",
413
+ headers: {
414
+ ...this.defaultHeaders,
415
+ Authorization: `Bearer ${this.userToken}`,
416
+ },
417
+ body: JSON.stringify({
418
+ email: email,
419
+ }),
420
+ });
421
+ const json = await res.json();
422
+ if (json.message) {
423
+ throw new SidechatAPIError(json.message);
424
+ }
425
+ return json;
426
+ } catch (err) {
427
+ console.error(err);
428
+ throw new SidechatAPIError("Failed to request email verification.");
429
+ }
430
+ };
431
+
432
+ /**
433
+ * Check is the user's email is verified.
434
+ * @method
435
+ * @since 1.0.0
436
+ */
437
+ checkEmailVerification = async () => {
438
+ if (!this.userToken) {
439
+ throw new SidechatAPIError("User is not authenticated.");
440
+ }
441
+ try {
442
+ const res = await fetch(`${this.apiRoot}/v1/users/check_email_verified`, {
443
+ method: "GET",
444
+ headers: {
445
+ ...this.defaultHeaders,
446
+ Authorization: `Bearer ${this.userToken}`,
447
+ },
448
+ });
449
+ const json = await res.json();
450
+ if (json.verified_email_updates_response) {
451
+ return json.verified_email_updates_response;
452
+ } else if (json.changing_phone_number_verified_email_user) {
453
+ return json.changing_phone_number_verified_email_user;
454
+ } else {
455
+ throw new SidechatAPIError(json?.message || "Email is not verified.");
456
+ }
457
+ } catch (err) {
458
+ console.error(err);
459
+ throw new SidechatAPIError("Email is not verified.");
460
+ }
461
+ };
462
+
463
+ /**
464
+ * Set the device ID of the current user
465
+ * @method
466
+ * @since 1.0.0
467
+ * @param {String} deviceId - the device ID to set
468
+ */
469
+ setDeviceID = async (deviceID) => {
470
+ if (!this.userToken) {
471
+ throw new SidechatAPIError("User is not authenticated.");
472
+ }
473
+ try {
474
+ const res = await fetch(`${this.apiRoot}/v1/register_device_token`, {
475
+ method: "POST",
476
+ headers: {
477
+ ...this.defaultHeaders,
478
+ Authorization: `Bearer ${this.userToken}`,
479
+ },
480
+ body: JSON.stringify({
481
+ build_type: "release",
482
+ bundle_id: "com.flowerave.sidechat",
483
+ device_token: deviceID,
484
+ }),
485
+ });
486
+ const json = await res.json();
487
+ return json;
488
+ } catch (err) {
489
+ console.error(err);
490
+ throw new SidechatAPIError("Failed verify this code.");
491
+ }
492
+ };
493
+
494
+ /**
495
+ * Get updated status for user and group
496
+ * @method
497
+ * @since 1.0.0
498
+ * @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
499
+ * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
500
+ */
501
+ getUserAndGroup = async (groupID = "") => {
502
+ const json = await this.getUpdates(groupID);
503
+ return json;
504
+ };
505
+
506
+ /**
507
+ * Get updated status for user and group
508
+ * @method
509
+ * @since 2.1.0
510
+ * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
511
+ */
512
+ getUpdates = async (groupID = "") => {
513
+ if (!this.userToken) {
514
+ throw new SidechatAPIError("User is not authenticated.");
515
+ }
516
+ try {
517
+ const res = await fetch(
518
+ `${this.apiRoot}/v1/updates?group_id=${groupID}`,
519
+ {
520
+ method: "GET",
521
+ headers: {
522
+ ...this.defaultHeaders,
523
+ Authorization: `Bearer ${this.userToken}`,
524
+ },
525
+ }
526
+ );
527
+ const json = await res.json();
528
+ return json;
529
+ } catch (err) {
530
+ console.error(err);
531
+ throw new SidechatAPIError(`Failed to get posts from group.`);
532
+ }
533
+ };
534
+
535
+ /**
536
+ * Fetches posts from the specified category in a group
537
+ * @method
538
+ * @since 1.0.0
539
+ * @param {String} groupID - group ID
540
+ * @param {"hot"|"recent"|"top"} category - category to filter posts
541
+ * @param {types.SidechatCursorString} [cursor] - cursor string
542
+ * @returns {Promise<types.SidechatPostsAndCursor>} List of posts and cursor
543
+ */
544
+ getGroupPosts = async (groupID, category = "hot", cursor) => {
545
+ if (!this.userToken) {
546
+ throw new SidechatAPIError("User is not authenticated.");
547
+ }
548
+ try {
549
+ const res = await fetch(
550
+ `${this.apiRoot}/v1/posts?${cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
551
+ }group_id=${groupID}&type=${category}`,
552
+ {
553
+ method: "GET",
554
+ headers: {
555
+ ...this.defaultHeaders,
556
+ Authorization: `Bearer ${this.userToken}`,
557
+ },
558
+ }
559
+ );
560
+ const json = await res.json();
561
+ return json;
562
+ } catch (err) {
563
+ console.error(err);
564
+ throw new SidechatAPIError(`Failed to get posts from group.`);
565
+ }
566
+ };
567
+
568
+ /**
569
+ * Upvote or downvote, or unvote a post
570
+ * @method
571
+ * @since 2.0.0-alpha.0
572
+ * @param {String} postID - post ID to vote on
573
+ * @param {types.SidechatVoteString} action - whether to upvote, downvote, or reset vote
574
+ */
575
+ setVote = async (postID, action) => {
576
+ if (!this.userToken) {
577
+ throw new SidechatAPIError("User is not authenticated.");
578
+ }
579
+ try {
580
+ const res = await fetch(`${this.apiRoot}/v1/posts/set_vote`, {
581
+ method: "POST",
582
+ headers: {
583
+ ...this.defaultHeaders,
584
+ Authorization: `Bearer ${this.userToken}`,
585
+ },
586
+ body: JSON.stringify({
587
+ post_id: postID,
588
+ vote_status: action,
589
+ }),
590
+ });
591
+ const json = await res.json();
592
+ return json;
593
+ } catch (err) {
594
+ console.error(err);
595
+ throw new SidechatAPIError(`Failed to change the vote on post.`);
596
+ }
597
+ };
598
+
599
+ /**
600
+ * Fetches a single post with just its ID
601
+ * @method
602
+ * @since 2.3.0
603
+ * @param {String} postID - ID of post to fetch
604
+ * @param {Boolean} includeDeleted - undocumented
605
+ * @returns {Promise<types.SidechatPostOrComment>} post object
606
+ */
607
+ getPost = async (postID, includeDeleted = false) => {
608
+ if (!this.userToken) {
609
+ throw new SidechatAPIError("User is not authenticated.");
610
+ }
611
+ try {
612
+ const res = await fetch(
613
+ `${this.apiRoot}/v1/posts/get?include_deleted=${includeDeleted}&post_id=${postID}`,
614
+ {
615
+ method: "GET",
616
+ headers: {
617
+ ...this.defaultHeaders,
618
+ Authorization: `Bearer ${this.userToken}`,
619
+ },
620
+ }
621
+ );
622
+ const json = await res.json();
623
+ return json.post;
624
+ } catch (err) {
625
+ console.error(err);
626
+ throw new SidechatAPIError(`Failed to get post from ID.`);
627
+ }
628
+ };
629
+
630
+ /**
631
+ * Fetches the posts or comments that the user has created
632
+ * @method
633
+ * @since 2.3.5
634
+ * @param {"posts"|"comments"} contentType - type of user content to fetch
635
+ * @returns {Promise<types.SidechatPostOrComment[]>} post object
636
+ */
637
+ getUserContent = async (contentType) => {
638
+ if (!this.userToken) {
639
+ throw new SidechatAPIError("User is not authenticated.");
640
+ }
641
+ if (contentType == "posts") {
642
+ contentType = "my_posts";
643
+ } else if (contentType == "comments") {
644
+ contentType = "my_comments";
645
+ }
646
+ try {
647
+ const res = await fetch(`${this.apiRoot}/v1/posts&type=${contentType}`, {
648
+ method: "GET",
649
+ headers: {
650
+ ...this.defaultHeaders,
651
+ Authorization: `Bearer ${this.userToken}`,
652
+ },
653
+ });
654
+ const json = await res.json();
655
+ return json.posts;
656
+ } catch (err) {
657
+ console.error(err);
658
+ throw new SidechatAPIError(`Failed to get content from user.`);
659
+ }
660
+ };
661
+
662
+ /**
663
+ * Get all the commments on a post
664
+ * @method
665
+ * @since 2.0.0-alpha.0
666
+ * @param {String} postID - post ID to get comments for
667
+ * @returns {Promise<types.SidechatPostOrComment[]>} list of comments
668
+ */
669
+ getPostComments = async (postID) => {
670
+ if (!this.userToken) {
671
+ throw new SidechatAPIError("User is not authenticated.");
672
+ }
673
+ try {
674
+ const res = await fetch(
675
+ `${this.apiRoot}/v1/posts/comments/?post_id=${postID}`,
676
+ {
677
+ method: "GET",
678
+ headers: {
679
+ ...this.defaultHeaders,
680
+ Authorization: `Bearer ${this.userToken}`,
681
+ },
682
+ }
683
+ );
684
+ const json = await res.json();
685
+ // Function to preprocess the comments and organize them into a nested structure
686
+ function preprocessComments(apiComments) {
687
+ // Map to store comments by their IDs for efficient lookup
688
+ const commentMap = new Map();
689
+ // List to store top-level comments
690
+ const topLevelComments = [];
691
+
692
+ // Iterate through the API comments
693
+ apiComments.forEach((comment) => {
694
+ // Store the comment in the map with its ID as the key
695
+ commentMap.set(comment.id, comment);
696
+ // Get the parent comment using the reply_post_id
697
+ const parentComment = commentMap.get(comment.reply_post_id);
698
+ // Check if the comment is a top-level comment
699
+ if (
700
+ !parentComment ||
701
+ comment.reply_post_id === comment.parent_post_id
702
+ ) {
703
+ // If it's a top-level comment, push it to the topLevelComments array
704
+ topLevelComments.push(comment);
705
+ } else {
706
+ // If it's a reply, add it to the parent comment's replies array
707
+ if (!parentComment.replies) parentComment.replies = [];
708
+ parentComment.replies.push(comment);
709
+ }
710
+ });
711
+
712
+ // Flatten the nested structure and return a single list of comments
713
+ return flattenComments(topLevelComments);
714
+ }
715
+
716
+ // Function to flatten nested comments into a single list
717
+ function flattenComments(comments) {
718
+ // Use reduce to flatten the nested comments array into a single list
719
+ return comments.reduce((flatComments, comment) => {
720
+ // Push the current comment to the flatComments array
721
+ flatComments.push(comment);
722
+ // If the current comment has replies, recursively flatten them and push to the flatComments array
723
+ if (comment.replies)
724
+ flatComments.push(...flattenComments(comment.replies));
725
+ // Return the flatComments array
726
+ return flatComments;
727
+ }, []);
728
+ }
729
+
730
+ const sortedComments = preprocessComments(json.posts);
731
+ return sortedComments;
732
+ } catch (err) {
733
+ console.error(err);
734
+ throw new SidechatAPIError(`Failed to get comments on post.`);
735
+ }
736
+ };
737
+
738
+ /**
739
+ * Gets groups to be displayed on the "Explore Groups" page
740
+ * @method
741
+ * @since 2.0.0-alpha.0
742
+ * @param {Boolean} onePage - whether or not results should be returned as a single page
743
+ * @returns {Promise<types.SidechatGroup[]>}
744
+ */
745
+ getAvailableGroups = async (onePage = true) => {
746
+ if (!this.userToken) {
747
+ throw new SidechatAPIError("User is not authenticated.");
748
+ }
749
+ try {
750
+ const res = await fetch(`${this.apiRoot}/v1/groups/explore`, {
751
+ method: "GET",
752
+ headers: {
753
+ ...this.defaultHeaders,
754
+ "App-Version": onePage ? "0" : this.defaultHeaders["App-Version"],
755
+ Authorization: `Bearer ${this.userToken}`,
756
+ },
757
+ });
758
+ const json = await res.json();
759
+ return await json.groups;
760
+ } catch (err) {
761
+ console.error(err);
762
+ throw new SidechatAPIError(`Failed to get groups from explore.`);
763
+ }
764
+ };
765
+
766
+ /**
767
+ * Searches for new groups based on a query keyword
768
+ * @method
769
+ * @since 2.6.0
770
+ * @param {String} query - the string to search for. This will be encoded, so strings with spaces and special characters are okay.
771
+ * @returns {Promise<types.SidechatGroup[]>}
772
+ */
773
+ searchAvailableGroups = async (query) => {
774
+ if (!this.userToken) {
775
+ throw new SidechatAPIError("User is not authenticated.");
776
+ }
777
+ try {
778
+ const res = await fetch(`${this.apiRoot}/v1/groups/explore/search?term=${encodeURIComponent(query)}`, {
779
+ method: "GET",
780
+ headers: {
781
+ ...this.defaultHeaders,
782
+ Authorization: `Bearer ${this.userToken}`,
783
+ },
784
+ });
785
+ const json = await res.json();
786
+ return await json.results;
787
+ } catch (err) {
788
+ console.error(err);
789
+ throw new SidechatAPIError(`Failed to search groups.`);
790
+ }
791
+ };
792
+
793
+ /**
794
+ * Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
795
+ * @method
796
+ * @since 2.0.6
797
+ * @returns {Promise<types.SidechatLibraryAsset[]>}
798
+ */
799
+ getAssetLibrary = async () => {
800
+ if (!this.userToken) {
801
+ throw new SidechatAPIError("User is not authenticated.");
802
+ }
803
+ try {
804
+ const res = await fetch(`${this.apiRoot}/v1/assets/library`, {
805
+ method: "GET",
806
+ headers: {
807
+ ...this.defaultHeaders,
808
+ Authorization: `Bearer ${this.userToken}`,
809
+ },
810
+ });
811
+ const json = await res.json();
812
+ return await json.items;
813
+ } catch (err) {
814
+ console.error(err);
815
+ throw new SidechatAPIError(`Failed to get asset library.`);
816
+ }
817
+ };
818
+
819
+ /**
820
+ * Gets the current authenticated user and a list of the groups of which they are members.
821
+ * @method
822
+ * @since 2.1.0
823
+ * @returns {Promise<types.SidechatCurrentUser>}
824
+ */
825
+ getCurrentUser = async () => {
826
+ if (!this.userToken) {
827
+ throw new SidechatAPIError("User is not authenticated.");
828
+ }
829
+ try {
830
+ const res = await fetch(`${this.apiRoot}/v1/users/me`, {
831
+ method: "GET",
832
+ headers: {
833
+ ...this.defaultHeaders,
834
+ Authorization: `Bearer ${this.userToken}`,
835
+ },
836
+ });
837
+ const json = await res.json();
838
+ return await json;
839
+ } catch (err) {
840
+ console.error(err);
841
+ throw new SidechatAPIError(`Failed to get asset library.`);
842
+ }
843
+ };
844
+
845
+ /**
846
+ * Gets the metadata of a group from its ID
847
+ * @method
848
+ * @since 2.1.0
849
+ * @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
850
+ * @returns {Promise<types.SidechatGroup>}
851
+ */
852
+ getGroupMetadata = async (groupID = "") => {
853
+ if (!this.userToken) {
854
+ throw new SidechatAPIError("User is not authenticated.");
855
+ }
856
+ try {
857
+ const res = await fetch(`${this.apiRoot}/v1/groups/${groupID}`, {
858
+ method: "GET",
859
+ headers: {
860
+ ...this.defaultHeaders,
861
+ Authorization: `Bearer ${this.userToken}`,
862
+ },
863
+ });
864
+ const json = await res.json();
865
+ return await json.group;
866
+ } catch (err) {
867
+ console.error(err);
868
+ throw new SidechatAPIError(`Failed to get group metadata.`);
869
+ }
870
+ };
871
+
872
+ /**
873
+ * Joins or leaves a group
874
+ * @method
875
+ * @param {String} groupID - alphanumeric ID of group to join or leave
876
+ * @param {Boolean} isMember - whether or not the user should be a member of the group
877
+ * @since 2.3.8
878
+ */
879
+ setGroupMembership = async (groupID, isMember) => {
880
+ if (!this.userToken) {
881
+ throw new SidechatAPIError("User is not authenticated.");
882
+ }
883
+ try {
884
+ const res = await fetch(
885
+ `${this.apiRoot}/v1/groups/${isMember ? "join" : "leave"}`,
886
+ {
887
+ method: "POST",
888
+ headers: {
889
+ ...this.defaultHeaders,
890
+ Authorization: `Bearer ${this.userToken}`,
891
+ },
892
+ body: JSON.stringify({
893
+ group_id: groupID,
894
+ }),
895
+ }
896
+ );
897
+ const json = await res.json();
898
+ return await json;
899
+ } catch (err) {
900
+ console.error(err);
901
+ throw new SidechatAPIError(`Failed to modify group membership.`);
902
+ }
903
+ };
904
+
905
+ /**
906
+ * Creates a comment on a post
907
+ * @method
908
+ * @since 2.2.0
909
+ * @param {String} parentPostID - alphanumeric ID of post on which this comment is made
910
+ * @param {String} text - text content of comment
911
+ * @param {String} groupID - alphanumeric ID of group in which the parent post resides
912
+ * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
913
+ * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
914
+ * @param {types.SidechatSimpleAsset[]} [assetList] - list of assets to attach
915
+ * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
916
+ * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
917
+ * @returns {Promise<types.SidechatPostOrComment>} created comment
918
+ */
919
+ createComment = async (
920
+ parentPostID,
921
+ text,
922
+ groupID,
923
+ replyCommentID,
924
+ topLevelReplyID,
925
+ assetList = [],
926
+ disableDMs = false,
927
+ anonymous = false
928
+ ) => {
929
+ if (!this.userToken) {
930
+ throw new SidechatAPIError("User is not authenticated.");
931
+ }
932
+ try {
933
+ const res = await fetch(`${this.apiRoot}/v1/posts`, {
934
+ method: "POST",
935
+ headers: {
936
+ ...this.defaultHeaders,
937
+ Authorization: `Bearer ${this.userToken}`,
938
+ },
939
+ body: JSON.stringify({
940
+ type: "comment",
941
+ assets: assetList,
942
+ group_ids: [groupID],
943
+ text: text,
944
+ reply_post_id: topLevelReplyID || replyCommentID || parentPostID,
945
+ reply_comment_post_id: replyCommentID || parentPostID,
946
+ parent_post_id: parentPostID,
947
+ dms_disabled: disableDMs,
948
+ using_identity: !anonymous,
949
+ }),
950
+ });
951
+ const json = await res.json();
952
+ return await json.comment;
953
+ } catch (err) {
954
+ console.error(err);
955
+ throw new SidechatAPIError(`Failed to post comment.`);
956
+ }
957
+ };
958
+
959
+ /**
960
+ * Creates a new post in the specified group
961
+ * @method
962
+ * @since 2.2.0
963
+ * @param {String} text - text content of comment
964
+ * @param {String} groupID - alphanumeric ID of group in which the parent post resides
965
+ * @param {types.SidechatSimpleAsset[]} [assetList] - list of assets to attach.
966
+ * @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
967
+ * @param {Boolean} [disableComments] - whether or not comments should be disabled on post
968
+ * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on post
969
+ * @param {Array<String>} [pollOptions] - List of poll options. If provided, a poll will be created with these options.
970
+ * @returns {Promise<types.SidechatPostOrComment>} the created post
971
+ */
972
+ createPost = async (
973
+ text,
974
+ groupID,
975
+ assetList = [],
976
+ disableDMs = false,
977
+ disableComments = false,
978
+ anonymous = false,
979
+ repostId = undefined,
980
+ pollOptions = undefined
981
+ ) => {
982
+ if (!this.userToken) {
983
+ throw new SidechatAPIError("User is not authenticated.");
984
+ }
985
+ try {
986
+ // Build the request body
987
+ const body = {
988
+ type: "post",
989
+ assets: assetList,
990
+ group_ids: [groupID],
991
+ text: text,
992
+ attachments: [],
993
+ dms_disabled: disableDMs,
994
+ comments_disabled: disableComments,
995
+ using_identity: !anonymous,
996
+ quote_post_id: repostId
997
+ };
998
+ // If pollOptions is provided and is a non-empty array, add poll_request
999
+ if (Array.isArray(pollOptions) && pollOptions.length > 0) {
1000
+ body.poll_request = {
1001
+ allows_view_results: true,
1002
+ choices: pollOptions
1003
+ };
1004
+ }
1005
+ const res = await fetch(`${this.apiRoot}/v1/posts`, {
1006
+ method: "POST",
1007
+ headers: {
1008
+ ...this.defaultHeaders,
1009
+ Authorization: `Bearer ${this.userToken}`,
1010
+ },
1011
+ body: JSON.stringify(body),
1012
+ });
1013
+ const json = await res.json();
1014
+ return await json.posts[0];
1015
+ } catch (err) {
1016
+ console.error(err);
1017
+ throw new SidechatAPIError(`Failed to make post.`);
1018
+ }
1019
+ };
1020
+
1021
+ /**
1022
+ * Deletes a post or comment that the user created
1023
+ * @method
1024
+ * @since 2.2.0
1025
+ * @param {String} postOrCommentID - alphanumeric ID of post to delete
1026
+ */
1027
+ deletePostOrComment = async (postOrCommentID) => {
1028
+ if (!this.userToken) {
1029
+ throw new SidechatAPIError("User is not authenticated.");
1030
+ }
1031
+ try {
1032
+ const res = await fetch(`${this.apiRoot}/v1/posts/delete`, {
1033
+ method: "POST",
1034
+ headers: {
1035
+ ...this.defaultHeaders,
1036
+ Authorization: `Bearer ${this.userToken}`,
1037
+ },
1038
+ body: JSON.stringify({
1039
+ post_id: postOrCommentID,
1040
+ }),
1041
+ });
1042
+ const json = await res.json();
1043
+ return await json;
1044
+ } catch (err) {
1045
+ console.error(err);
1046
+ throw new SidechatAPIError(`Failed to delete post.`);
1047
+ }
1048
+ };
1049
+
1050
+ /**
1051
+ * Votes on a poll attached to a post
1052
+ * @method
1053
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1054
+ * @param {Number} choiceIndex - index of the choice to vote on
1055
+ * @since 2.5.4
1056
+ */
1057
+ voteOnPoll = async (pollId, choiceIndex) => {
1058
+ if (!this.userToken) {
1059
+ throw new SidechatAPIError("User is not authenticated.");
1060
+ }
1061
+ try {
1062
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
1063
+ method: "POST",
1064
+ headers: {
1065
+ ...this.defaultHeaders,
1066
+ Authorization: `Bearer ${this.userToken}`,
1067
+ },
1068
+ body: JSON.stringify({
1069
+ poll_id: pollId,
1070
+ choice: choiceIndex,
1071
+ }),
1072
+ });
1073
+ const json = await res.json();
1074
+ return await json;
1075
+ } catch (err) {
1076
+ console.error(err);
1077
+ throw new SidechatAPIError(`Failed to vote on poll`);
1078
+ }
1079
+ };
1080
+
1081
+ /**
1082
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1083
+ * @method
1084
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1085
+ * @since 2.5.4
1086
+ */
1087
+ viewPollResults = async (pollId) => {
1088
+ if (!this.userToken) {
1089
+ throw new SidechatAPIError("User is not authenticated.");
1090
+ }
1091
+ try {
1092
+ const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1093
+ method: "POST",
1094
+ headers: {
1095
+ ...this.defaultHeaders,
1096
+ Authorization: `Bearer ${this.userToken}`,
1097
+ },
1098
+ body: JSON.stringify({
1099
+ poll_id: pollId,
1100
+ }),
1101
+ });
1102
+ const json = await res.json();
1103
+ return await json;
1104
+ } catch (err) {
1105
+ console.error(err);
1106
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1107
+ }
1108
+ };
1109
+
1110
+ /**
1111
+ * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
1112
+ * @method
1113
+ * @param {String} uri - URI of the asset to upload
1114
+ * @param {String} mimeType - mimetype of the asset (e.g. "image/png")
1115
+ * @param {String} [name] - filename of the asset
1116
+ * @returns {Promise<String>} URL of the uploaded asset
1117
+ * @since 2.5.1
1118
+ */
1119
+ uploadAsset = async (uri, mimeType, name = "") => {
1120
+ if (!this.userToken) {
1121
+ throw new SidechatAPIError("User is not authenticated.");
1122
+ }
1123
+
1124
+ let imageType = mimeType.split("/")[1];
1125
+ if (!["png", "jpeg", "gif"].includes(imageType)) {
1126
+ throw new SidechatAPIError("Unsupported image format.");
1127
+ }
1128
+
1129
+ const data = new FormData();
1130
+ data.append("image", {
1131
+ name: name,
1132
+ type: mimeType,
1133
+ uri: uri,
1134
+ });
1135
+
1136
+ const urlReq = await this.sendRequest(`/v1/assets/upload_url?content_type=${imageType}`);
1137
+ const urlJson = await urlReq.json();
1138
+
1139
+ try {
1140
+ const uploadReq = await fetch(urlJson.upload_url, {
1141
+ body: data.getAll("image")[0],
1142
+ method: "PUT",
1143
+ headers: {
1144
+ "Content-Type": mimeType,
1145
+ },
1146
+ });
1147
+ if (uploadReq.status == 200) {
1148
+ return `${this.apiRoot}/v1/assets/library/${urlJson.asset_id}`;
1149
+ } else {
1150
+ throw new SidechatAPIError(
1151
+ `Couldn't upload image - error ${uploadReq.status}`
1152
+ );
1153
+ }
1154
+ } catch (e) {
1155
+ throw new SidechatAPIError(e.message);
1156
+ }
1157
+ };
1158
+
1159
+ /**
1160
+ * Sets the conversation icon of a user
1161
+ * @method
1162
+ * @since 2.2.1
1163
+ * @param {String} userID - alphanumeric ID of user
1164
+ * @param {String} emoji - emoji to set as icon
1165
+ * @param {String} primaryColor - hex string (including #) of primary color
1166
+ * @param {String} secondaryColor - hex string (including #) of secondary color
1167
+ */
1168
+ setUserIcon = async (userID, emoji, primaryColor, secondaryColor) => {
1169
+ if (!this.userToken) {
1170
+ throw new SidechatAPIError("User is not authenticated.");
1171
+ }
1172
+ try {
1173
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1174
+ method: "PATCH",
1175
+ headers: {
1176
+ ...this.defaultHeaders,
1177
+ "App-Version": "0",
1178
+ Authorization: `Bearer ${this.userToken}`,
1179
+ },
1180
+ body: JSON.stringify({
1181
+ conversation_icon: {
1182
+ emoji: emoji,
1183
+ secondary_color: secondaryColor,
1184
+ is_migrated: true,
1185
+ color: primaryColor,
1186
+ },
1187
+ }),
1188
+ });
1189
+ const json = await res.json();
1190
+ return await json;
1191
+ } catch (err) {
1192
+ console.error(err);
1193
+ throw new SidechatAPIError(`Failed to set icon.`);
1194
+ }
1195
+ };
1196
+
1197
+ /**
1198
+ * Sets the bio text of a user
1199
+ * @method
1200
+ * @since 2.5.6
1201
+ * @param {String} userID - alphanumeric ID of user
1202
+ * @param {String} bio - text to set as bio
1203
+ */
1204
+ setUserBio = async (userID, bio) => {
1205
+ if (!this.userToken) {
1206
+ throw new SidechatAPIError("User is not authenticated.");
1207
+ }
1208
+ try {
1209
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1210
+ method: "PATCH",
1211
+ headers: {
1212
+ ...this.defaultHeaders,
1213
+ "App-Version": "5.4.22",
1214
+ Authorization: `Bearer ${this.userToken}`,
1215
+ },
1216
+ body: JSON.stringify({
1217
+ bio: bio
1218
+ }),
1219
+ });
1220
+ const json = await res.json();
1221
+ return await json;
1222
+ } catch (err) {
1223
+ console.error(err);
1224
+ throw new SidechatAPIError(`Failed to set bio.`);
1225
+ }
1226
+ };
1227
+
1228
+ /**
1229
+ * Checks if user can set their username to a string
1230
+ * @method
1231
+ * @since 2.3.6
1232
+ * @param {String} username - string to check
1233
+ * @returns {Promise<Boolean>} whether or not username is valid and unused
1234
+ */
1235
+ checkUsername = async (username) => {
1236
+ if (!this.userToken) {
1237
+ throw new SidechatAPIError("User is not authenticated.");
1238
+ }
1239
+ try {
1240
+ const res = await fetch(
1241
+ `${this.apiRoot}/v1/users/username?username=${username}`,
1242
+ {
1243
+ method: "GET",
1244
+ headers: {
1245
+ ...this.defaultHeaders,
1246
+ Authorization: `Bearer ${this.userToken}`,
1247
+ },
1248
+ }
1249
+ );
1250
+ if (res?.status == 200 || res?.status == 204) {
1251
+ return true;
1252
+ } else {
1253
+ return false;
1254
+ }
1255
+ } catch (err) {
1256
+ console.error(err);
1257
+ throw new SidechatAPIError(`Failed to check username.`);
1258
+ }
1259
+ };
1260
+
1261
+ /**
1262
+ * Changes the username of the current user
1263
+ * @method
1264
+ * @since 2.3.6
1265
+ * @param {String} userID - alphanumeric ID of user
1266
+ * @param {String} username - new username to set
1267
+ */
1268
+ setUsername = async (userID, username) => {
1269
+ if (!this.userToken) {
1270
+ throw new SidechatAPIError("User is not authenticated.");
1271
+ }
1272
+ try {
1273
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1274
+ method: "PATCH",
1275
+ headers: {
1276
+ ...this.defaultHeaders,
1277
+ Authorization: `Bearer ${this.userToken}`,
1278
+ },
1279
+ body: JSON.stringify({
1280
+ username: username,
1281
+ }),
1282
+ });
1283
+ const json = await res.json();
1284
+ return await json.user;
1285
+ } catch (err) {
1286
+ console.error(err);
1287
+ throw new SidechatAPIError(`Failed to set icon.`);
1288
+ }
1289
+ };
1290
+
1291
+ /**
1292
+ * Fetches a public user profile
1293
+ * @method
1294
+ * @since 2.6.0
1295
+ * @param {String} username - username of the user to fetch
1296
+ * @returns {Promise<types.SidechatProfile>}
1297
+ */
1298
+ getUserProfile = async (username) => {
1299
+ if (!this.userToken) {
1300
+ throw new SidechatAPIError("User is not authenticated.");
1301
+ }
1302
+ try {
1303
+ const res = await fetch(`${this.apiRoot}/v1/groups/username?username=${username}`, {
1304
+ method: "GET",
1305
+ headers: {
1306
+ ...this.defaultHeaders,
1307
+ Authorization: `Bearer ${this.userToken}`,
1308
+ }
1309
+ });
1310
+ const json = await res.json();
1311
+ return await json.group;
1312
+ } catch (err) {
1313
+ console.error(err);
1314
+ throw new SidechatAPIError(`Failed to set icon.`);
1315
+ }
1316
+ };
1317
+
1318
+ /**
1319
+ * Fetches a public user's posts
1320
+ * @method
1321
+ * @since 2.6.0
1322
+ * @param {String} username - username of the user to fetch
1323
+ * @returns {Promise<types.SidechatPostOrComment[]>}
1324
+ */
1325
+ getUserPosts = async (username) => {
1326
+ if (!this.userToken) {
1327
+ throw new SidechatAPIError("User is not authenticated.");
1328
+ }
1329
+ try {
1330
+ const res = await fetch(`${this.apiRoot}/v1/users/posts?username=${username}`, {
1331
+ method: "GET",
1332
+ headers: {
1333
+ ...this.defaultHeaders,
1334
+ Authorization: `Bearer ${this.userToken}`,
1335
+ }
1336
+ });
1337
+ const json = await res.json();
1338
+ return await json.posts;
1339
+ } catch (err) {
1340
+ console.error(err);
1341
+ throw new SidechatAPIError(`Failed to set icon.`);
1342
+ }
1343
+ };
1344
+
1345
+ /**
1346
+ * Marks an activity item as read
1347
+ * @method
1348
+ * @since 2.3.2
1349
+ * @param {String} activityID - alphanumeric ID of activity object
1350
+ */
1351
+ readActivity = async (activityID) => {
1352
+ if (!this.userToken) {
1353
+ throw new SidechatAPIError("User is not authenticated.");
1354
+ }
1355
+ try {
1356
+ const res = await fetch(`${this.apiRoot}/v1/activity/seen`, {
1357
+ method: "POST",
1358
+ headers: {
1359
+ ...this.defaultHeaders,
1360
+ Authorization: `Bearer ${this.userToken}`,
1361
+ },
1362
+ body: JSON.stringify({
1363
+ ids: [activityID],
1364
+ }),
1365
+ });
1366
+ const json = await res.json();
1367
+ return await json;
1368
+ } catch (err) {
1369
+ console.error(err);
1370
+ throw new SidechatAPIError(`Failed to mark activity as read.`);
1371
+ }
1372
+ };
1373
+
1374
+ /**
1375
+ * Retrieves joinable group chats
1376
+ * @method
1377
+ * @since 2.3.5
1378
+ */
1379
+ getGroupChats = async () => {
1380
+ if (!this.userToken) {
1381
+ throw new SidechatAPIError("User is not authenticated.");
1382
+ }
1383
+ try {
1384
+ const res = await fetch(`${this.apiRoot}/v1/chats/explore`, {
1385
+ method: "GET",
1386
+ headers: {
1387
+ ...this.defaultHeaders,
1388
+ Authorization: `Bearer ${this.userToken}`,
1389
+ },
1390
+ });
1391
+ const json = await res.json();
1392
+ return await json.chats;
1393
+ } catch (err) {
1394
+ console.error(err);
1395
+ throw new SidechatAPIError(`Failed to get groupchats.`);
1396
+ }
1397
+ };
1398
+
1399
+ /**
1400
+ * Joins a group chat. To mimic the official client, use the user's display name and icon by default.
1401
+ * @method
1402
+ * @param {String} groupChatID - alphanumeric ID of group chat to join
1403
+ * @param {String} displayName - display name to use in chat
1404
+ * @param {String} emoji - emoji to use as icon
1405
+ * @param {String} primaryColor - hex string of primary color
1406
+ * @param {String} secondaryColor - hex string of secondary color
1407
+ * @since 2.3.5
1408
+ */
1409
+ joinGroupChat = async (
1410
+ groupChatID,
1411
+ displayName,
1412
+ emoji,
1413
+ primaryColor,
1414
+ secondaryColor
1415
+ ) => {
1416
+ if (!this.userToken) {
1417
+ throw new SidechatAPIError("User is not authenticated.");
1418
+ }
1419
+ try {
1420
+ const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
1421
+ method: "POST",
1422
+ headers: {
1423
+ ...this.defaultHeaders,
1424
+ Authorization: `Bearer ${this.userToken}`,
1425
+ },
1426
+ body: JSON.stringify({
1427
+ chat_id: groupChatID,
1428
+ identity: {
1429
+ display_name: displayName,
1430
+ emoji: emoji,
1431
+ secondary_color: secondaryColor,
1432
+ color: primaryColor,
1433
+ },
1434
+ }),
1435
+ });
1436
+ const json = await res.json();
1437
+ return await json;
1438
+ } catch (err) {
1439
+ console.error(err);
1440
+ throw new SidechatAPIError(`Failed to join groupchat.`);
1441
+ }
1442
+ };
1443
+
1444
+ /**
1445
+ * Gets a list of the user's direct messages
1446
+ * @method
1447
+ * @returns {Promise<types.SidechatDirectThread[]>}
1448
+ * @since 2.4.4
1449
+ */
1450
+ getDMs = async () => {
1451
+ if (!this.userToken) {
1452
+ throw new SidechatAPIError("User is not authenticated.");
1453
+ }
1454
+ try {
1455
+ const res = await fetch(`${this.apiRoot}/v1/chats`, {
1456
+ method: "GET",
1457
+ headers: {
1458
+ ...this.defaultHeaders,
1459
+ Authorization: `Bearer ${this.userToken}`,
1460
+ },
1461
+ });
1462
+ const json = await res.json();
1463
+ const list = await json.chats;
1464
+ let r = [];
1465
+ list.forEach((o) => {
1466
+ r.push(o.chat);
1467
+ });
1468
+ return await r;
1469
+ } catch (err) {
1470
+ console.error(err);
1471
+ throw new SidechatAPIError(`Failed to fetch DMs.`);
1472
+ }
1473
+ };
1474
+
1475
+ /**
1476
+ * Gets a single direct message thread
1477
+ * @method
1478
+ * @param {String} id - alphanumeric ID of the chat to fetch
1479
+ * @returns {Promise<types.SidechatDirectThread>}
1480
+ * @since 2.4.4
1481
+ */
1482
+ getDMThread = async (id) => {
1483
+ if (!this.userToken) {
1484
+ throw new SidechatAPIError("User is not authenticated.");
1485
+ }
1486
+ try {
1487
+ const res = await fetch(
1488
+ `${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
1489
+ {
1490
+ method: "GET",
1491
+ headers: {
1492
+ ...this.defaultHeaders,
1493
+ Authorization: `Bearer ${this.userToken}`,
1494
+ },
1495
+ }
1496
+ );
1497
+ const json = await res.json();
1498
+ return await json.chat;
1499
+ } catch (err) {
1500
+ console.error(err);
1501
+ throw new SidechatAPIError(`Failed to fetch DM thread.`);
1502
+ }
1503
+ };
1504
+
1505
+ /**
1506
+ * Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
1507
+ * @method
1508
+ * @param {String} chatID - alphanumeric ID of the chat to send to
1509
+ * @param {String} text - text content of message
1510
+ * @param {String} clientID - alphanumeric device ID
1511
+ * @param {types.SidechatAsset[]} assets - array of assets to send
1512
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1513
+ * @since 2.4.4
1514
+ */
1515
+ sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
1516
+ if (!this.userToken) {
1517
+ throw new SidechatAPIError("User is not authenticated.");
1518
+ }
1519
+ try {
1520
+ const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
1521
+ method: "POST",
1522
+ headers: {
1523
+ ...this.defaultHeaders,
1524
+ Authorization: `Bearer ${this.userToken}`,
1525
+ },
1526
+ body: JSON.stringify({
1527
+ chat_id: chatID,
1528
+ text: text,
1529
+ client_id: clientID,
1530
+ anonymous: anonymous,
1531
+ assets: assets,
1532
+ }),
1533
+ });
1534
+ const json = await res.json();
1535
+ return await json;
1536
+ } catch (err) {
1537
+ console.error(err);
1538
+ throw new SidechatAPIError(`Failed to send message.`);
1539
+ }
1540
+ };
1541
+
1542
+ /**
1543
+ * Creates a new direct message thread
1544
+ * @method
1545
+ * @param {String} text - text content of message
1546
+ * @param {String} clientID - alphanumeric ID of devide
1547
+ * @param {String} postID - alphanumeric ID of post or comment
1548
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1549
+ * @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
1550
+ * @since 2.4.4
1551
+ */
1552
+ startDM = async (
1553
+ text,
1554
+ clientID,
1555
+ postID,
1556
+ anonymous = false,
1557
+ postContext = "feed"
1558
+ ) => {
1559
+ if (!this.userToken) {
1560
+ throw new SidechatAPIError("User is not authenticated.");
1561
+ }
1562
+ try {
1563
+ const res = await fetch(`${this.apiRoot}/v1/chats/start`, {
1564
+ method: "POST",
1565
+ headers: {
1566
+ ...this.defaultHeaders,
1567
+ Authorization: `Bearer ${this.userToken}`,
1568
+ },
1569
+ body: JSON.stringify({
1570
+ text: text,
1571
+ client_id: clientID,
1572
+ post_id: postID,
1573
+ anonymous: anonymous,
1574
+ post_context: postContext,
1575
+ }),
1576
+ });
1577
+ const json = await res.json();
1578
+ return await json;
1579
+ } catch (err) {
1580
+ console.error(err);
1581
+ throw new SidechatAPIError(`Failed to start DM.`);
1582
+ }
1583
+ };
1584
+
1585
+ /**
1586
+ * Hides posts from user
1587
+ * @method
1588
+ * @param {String} postID - alphanumeric ID of post to hide
1589
+ * @since 2.6.2
1590
+ */
1591
+ hidePostsFromUser = async (postID) => {
1592
+ if (!this.userToken) {
1593
+ throw new SidechatAPIError("User is not authenticated.");
1594
+ }
1595
+ try {
1596
+ const res = await fetch(`${this.apiRoot}/v1/posts/hide_posts_from_user`, {
1597
+ method: "POST",
1598
+ headers: {
1599
+ ...this.defaultHeaders,
1600
+ Authorization: `Bearer ${this.userToken}`,
1601
+ },
1602
+ body: JSON.stringify({
1603
+ post_id: postID,
1604
+ post_context: "feed",
1605
+ report: false
1606
+ }),
1607
+ });
1608
+ const json = await res.json();
1609
+ return await json;
1610
+ } catch (err) {
1611
+ console.error(err);
1612
+ throw new SidechatAPIError(`Failed to hide post.`);
1613
+ }
1614
+ };
1615
+
1616
+ /**
1617
+ * Unhides all posts from all users
1618
+ * @method
1619
+ * @since 2.6.2
1620
+ */
1621
+ unhidePostsFromAllUsers = async () => {
1622
+ if (!this.userToken) {
1623
+ throw new SidechatAPIError("User is not authenticated.");
1624
+ }
1625
+ try {
1626
+ const res = await fetch(`${this.apiRoot}/v1/users/unhide_all`, {
1627
+ method: "POST",
1628
+ headers: {
1629
+ ...this.defaultHeaders,
1630
+ Authorization: `Bearer ${this.userToken}`,
1631
+ },
1632
+ body: JSON.stringify({}),
1633
+ });
1634
+ const json = await res.json();
1635
+ return await json;
1636
+ } catch (err) {
1637
+ console.error(err);
1638
+ throw new SidechatAPIError(`Failed to unhide post.`);
1639
+ }
1640
+ };
1569
1641
  }
1570
1642
 
1571
1643
  /**