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