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