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