sidechat.js 2.5.3 → 2.5.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 (84) hide show
  1. package/dist/classes/SidechatAPIClient.d.ts +17 -1
  2. package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
  3. package/dist/index.cjs +87 -5
  4. package/dist/index.mjs +87 -5
  5. package/dist/types/SidechatTypes.d.ts +51 -1
  6. package/dist/types/SidechatTypes.d.ts.map +1 -1
  7. package/docs/sidechat.js/2.5.4/SidechatAPIClient.html +3 -0
  8. package/docs/sidechat.js/2.5.4/SidechatAPIError.html +3 -0
  9. package/docs/sidechat.js/2.5.4/SidechatColorList.html +3 -0
  10. package/docs/sidechat.js/2.5.4/classes_SidechatAPIClient.js.html +1240 -0
  11. package/docs/sidechat.js/2.5.4/classes_SidechatAPIError.js.html +16 -0
  12. package/docs/sidechat.js/2.5.4/classes_SidechatColorList.js.html +79 -0
  13. package/docs/sidechat.js/2.5.4/data/search.json +1 -0
  14. package/docs/sidechat.js/2.5.4/fonts/Inconsolata-Regular.ttf +0 -0
  15. package/docs/sidechat.js/2.5.4/fonts/OpenSans-Regular.ttf +0 -0
  16. package/docs/sidechat.js/2.5.4/fonts/WorkSans-Bold.ttf +0 -0
  17. package/docs/sidechat.js/2.5.4/global.html +3 -0
  18. package/docs/sidechat.js/2.5.4/index.html +4 -0
  19. package/docs/sidechat.js/2.5.4/scripts/core.js +726 -0
  20. package/docs/sidechat.js/2.5.4/scripts/core.min.js +23 -0
  21. package/docs/sidechat.js/2.5.4/scripts/resize.js +90 -0
  22. package/docs/sidechat.js/2.5.4/scripts/search.js +265 -0
  23. package/docs/sidechat.js/2.5.4/scripts/search.min.js +6 -0
  24. package/docs/sidechat.js/2.5.4/scripts/third-party/Apache-License-2.0.txt +202 -0
  25. package/docs/sidechat.js/2.5.4/scripts/third-party/fuse.js +9 -0
  26. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num-original.js +369 -0
  27. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num.js +1 -0
  28. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-original.js +5171 -0
  29. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs.js +1 -0
  30. package/docs/sidechat.js/2.5.4/scripts/third-party/popper.js +5 -0
  31. package/docs/sidechat.js/2.5.4/scripts/third-party/tippy.js +1 -0
  32. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.js +672 -0
  33. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.min.js +1 -0
  34. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-base.css +1159 -0
  35. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-dark.css +412 -0
  36. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-light.css +482 -0
  37. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  38. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  39. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme.min.css +1 -0
  40. package/docs/sidechat.js/2.5.4/tutorial-Authentication.html +14 -0
  41. package/docs/sidechat.js/2.5.4/tutorial-Email Registration.html +6 -0
  42. package/docs/sidechat.js/2.5.4/types_SidechatTypes.js.html +180 -0
  43. package/docs/sidechat.js/2.5.5/SidechatAPIClient.html +3 -0
  44. package/docs/sidechat.js/2.5.5/SidechatAPIError.html +3 -0
  45. package/docs/sidechat.js/2.5.5/SidechatColorList.html +3 -0
  46. package/docs/sidechat.js/2.5.5/classes_SidechatAPIClient.js.html +1242 -0
  47. package/docs/sidechat.js/2.5.5/classes_SidechatAPIError.js.html +16 -0
  48. package/docs/sidechat.js/2.5.5/classes_SidechatColorList.js.html +79 -0
  49. package/docs/sidechat.js/2.5.5/data/search.json +1 -0
  50. package/docs/sidechat.js/2.5.5/fonts/Inconsolata-Regular.ttf +0 -0
  51. package/docs/sidechat.js/2.5.5/fonts/OpenSans-Regular.ttf +0 -0
  52. package/docs/sidechat.js/2.5.5/fonts/WorkSans-Bold.ttf +0 -0
  53. package/docs/sidechat.js/2.5.5/global.html +3 -0
  54. package/docs/sidechat.js/2.5.5/index.html +4 -0
  55. package/docs/sidechat.js/2.5.5/scripts/core.js +726 -0
  56. package/docs/sidechat.js/2.5.5/scripts/core.min.js +23 -0
  57. package/docs/sidechat.js/2.5.5/scripts/resize.js +90 -0
  58. package/docs/sidechat.js/2.5.5/scripts/search.js +265 -0
  59. package/docs/sidechat.js/2.5.5/scripts/search.min.js +6 -0
  60. package/docs/sidechat.js/2.5.5/scripts/third-party/Apache-License-2.0.txt +202 -0
  61. package/docs/sidechat.js/2.5.5/scripts/third-party/fuse.js +9 -0
  62. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-line-num-original.js +369 -0
  63. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-line-num.js +1 -0
  64. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs-original.js +5171 -0
  65. package/docs/sidechat.js/2.5.5/scripts/third-party/hljs.js +1 -0
  66. package/docs/sidechat.js/2.5.5/scripts/third-party/popper.js +5 -0
  67. package/docs/sidechat.js/2.5.5/scripts/third-party/tippy.js +1 -0
  68. package/docs/sidechat.js/2.5.5/scripts/third-party/tocbot.js +672 -0
  69. package/docs/sidechat.js/2.5.5/scripts/third-party/tocbot.min.js +1 -0
  70. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-base.css +1159 -0
  71. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-dark.css +412 -0
  72. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-light.css +482 -0
  73. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  74. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  75. package/docs/sidechat.js/2.5.5/styles/clean-jsdoc-theme.min.css +1 -0
  76. package/docs/sidechat.js/2.5.5/tutorial-Authentication.html +14 -0
  77. package/docs/sidechat.js/2.5.5/tutorial-Email Registration.html +6 -0
  78. package/docs/sidechat.js/2.5.5/types_SidechatTypes.js.html +180 -0
  79. package/package.json +4 -4
  80. package/src/classes/SidechatAPIClient.js +66 -4
  81. package/src/tests/commentTest.js +22 -0
  82. package/src/tests/postTest.js +1 -1
  83. package/src/tests/updatesTest.js +19 -0
  84. package/src/types/SidechatTypes.js +21 -1
@@ -201,12 +201,13 @@ declare class SidechatAPIClient {
201
201
  * @param {String} text - text content of comment
202
202
  * @param {String} groupID - alphanumeric ID of group in which the parent post resides
203
203
  * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
204
+ * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
204
205
  * @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
205
206
  * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
206
207
  * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
207
208
  * @returns {SidechatPostOrComment} created comment
208
209
  */
209
- createComment: (parentPostID: string, text: string, groupID: string, replyCommentID?: string, assetList?: SidechatSimpleAsset[], disableDMs?: boolean, anonymous?: boolean) => SidechatPostOrComment;
210
+ createComment: (parentPostID: string, text: string, groupID: string, replyCommentID?: string, topLevelReplyID?: string, assetList?: SidechatSimpleAsset[], disableDMs?: boolean, anonymous?: boolean) => SidechatPostOrComment;
210
211
  /**
211
212
  * Creates a new post in the specified group
212
213
  * @method
@@ -227,6 +228,21 @@ declare class SidechatAPIClient {
227
228
  * @param {String} postOrCommentID - alphanumeric ID of post to delete
228
229
  */
229
230
  deletePostOrComment: (postOrCommentID: string) => Promise<any>;
231
+ /**
232
+ * Votes on a poll attached to a post
233
+ * @method
234
+ * @param {String} pollId - alphanumeric ID of poll to vote on
235
+ * @param {Number} choiceIndex - index of the choice to vote on
236
+ * @since 2.5.4
237
+ */
238
+ voteOnPoll: (pollId: string, choiceIndex: number) => Promise<any>;
239
+ /**
240
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
241
+ * @method
242
+ * @param {String} pollId - alphanumeric ID of poll to vote on
243
+ * @since 2.5.4
244
+ */
245
+ viewPollResults: (pollId: string) => Promise<any>;
230
246
  /**
231
247
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
232
248
  * @method
@@ -1 +1 @@
1
- {"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IA2BE;;;;OAIG;IACH,oBAHW,iBAAiB,oBAU3B;IAtCD;;;SAGK;IACL,WAFU,iBAAiB,CAEjB;IAEV;;;;;OAKG;IACH,oBAKE;IAEF;;;;OAIG;IACH,gBAAqC;IAgBrC;;;;OAIG;IACH,kBAFW,iBAAiB,UAI1B;IAEF;;;;;OAKG;IACH,kCAEE;IAEF;;;;;;;;;OASG;IACH,yCANW,KAAK,GAAC,MAAM,GAAC,KAAK,GAAC,QAAQ,GAAC,OAAO,GAAC,SAAS,0EAuBtD;IAEF;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAmBE;IAEF;;;;;;OAMG;IACH,8DAsBE;IAEF;;;;;;OAMG;IACH,+CAwBE;IAEF;;;;OAIG;IACH,2CAsBE;IAEF;;;;;OAKG;IACH,6CAuBE;IAEF;;;;;;OAMG;IACH,oDAGE;IAEF;;;;;OAKG;IACH,+CAqBE;IAEF;;;;;;;;OAQG;IACH,4CAJW,KAAK,GAAC,QAAQ,GAAC,KAAK,WACpB,oBAAoB,KAClB,sBAAsB,CAyBjC;IAEF;;;;;;OAMG;IACH,kCAFW,kBAAkB,kBAwB3B;IAEF;;;;;;;OAOG;IACH,uDAFa,qBAAqB,CAuBhC;IAEF;;;;;;OAMG;IACH,8BAHW,OAAO,GAAC,UAAU,KAChB,qBAAqB,EAAE,CAyBlC;IAEF;;;;;;OAMG;IACH,qCAFa,qBAAqB,EAAE,CAqElC;IAEF;;;;;;OAMG;IACH,2CAFa,aAAa,EAAE,CAqB1B;IAEF;;;;;OAKG;IACH,uBAFa,oBAAoB,EAAE,CAoBjC;IAEF;;;;;OAKG;IACH,sBAFa,mBAAmB,CAoB9B;IAEF;;;;;;OAMG;IACH,wCAFa,aAAa,CAoBxB;IAEF;;;;;;OAMG;IACH,yEAwBE;IAEF;;;;;;;;;;;;OAYG;IACH,0GALW,mBAAmB,EAAE,gDAGnB,qBAAqB,CAsChC;IAEF;;;;;;;;;;;OAWG;IACH,wDANW,mBAAmB,EAAE,2EAInB,qBAAqB,CAqChC;IAEF;;;;;OAKG;IACH,+DAqBE;IAEF;;;;;;;;OAQG;IACH,sEAyCE;IAEF;;;;;;;;OAQG;IACH,2GA2BE;IAEF;;;;;;OAMG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,gEAqBE;IAEF;;;;;OAKG;IACH,mDAqBE;IAEF;;;;OAIG;IACH,kCAkBE;IAEF;;;;OAIG;IACH,wHAiCE;IAEF;;;;;OAKG;IACH,cAHa,oBAAoB,EAAE,CA0BjC;IAEF;;;;;;OAMG;IACH,6BAHa,oBAAoB,CAwB/B;IAEF;;;;;;;;;OASG;IACH,kEAJW,aAAa,EAAE,uCA6BxB;IAEF;;;;;;;;;OASG;IACH,6FAHW,MAAM,kBAkCf;CACH"}
1
+ {"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IA2BE;;;;OAIG;IACH,oBAHW,iBAAiB,oBAU3B;IAtCD;;;SAGK;IACL,WAFU,iBAAiB,CAEjB;IAEV;;;;;OAKG;IACH,oBAKE;IAEF;;;;OAIG;IACH,gBAAqC;IAgBrC;;;;OAIG;IACH,kBAFW,iBAAiB,UAI1B;IAEF;;;;;OAKG;IACH,kCAEE;IAEF;;;;;;;;;OASG;IACH,yCANW,K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AqBE;IAEF;;;;;OAKG;IACH,mDAqBE;IAEF;;;;OAIG;IACH,kCAkBE;IAEF;;;;OAIG;IACH,wHAiCE;IAEF;;;;;OAKG;IACH,cAHa,oBAAoB,EAAE,CA0BjC;IAEF;;;;;;OAMG;IACH,6BAHa,oBAAoB,CAwB/B;IAEF;;;;;;;;;OASG;IACH,kEAJW,aAAa,EAAE,uCA6BxB;IAEF;;;;;;;;;OASG;IACH,6FAHW,MAAM,kBAkCf;CACH"}
package/dist/index.cjs CHANGED
@@ -18,7 +18,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
18
18
  * @prop {SidechatSimpleAsset[]} assets - array of simple assets attached to post or comment
19
19
  * @prop {Array} attachments - undocumented
20
20
  * @prop {Boolean} dms_disabled - whether or not you can send a DM to creator of post
21
- * @prop {Array} tags - undocumented
21
+ * @prop {String[]} tags - undocumented
22
22
  * @prop {SidechatIdentity} identity - creator's identity information
23
23
  * @prop {Boolean} pinned - undocumented
24
24
  * @prop {Boolean} is_saved - undocumented
@@ -26,6 +26,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
26
26
  * @prop {"group"} [destination] - undocumented
27
27
  * @prop {Number} [comment_count] - number of comments on post (only if type=post)
28
28
  * @prop {Boolean} [comments_disabled] - whether or not you can comment on post (only if type=post)
29
+ * @prop {SidechatPoll} [poll] - poll attached to post (only if the post has a poll)
29
30
  * @prop {String} [parent_post_id] - alphanumeric ID of parent post (only if type=comment)
30
31
  * @prop {String} [reply_post_id] - alphanumeric ID of comment being replied to, falls back to parent_post_id (only if type=comment)
31
32
  * @prop {String} [context] - text content of comment being replied to, falls back to text (only if type=comment)
@@ -158,6 +159,25 @@ var SidechatTypes = {};
158
159
  * @prop {String} chat_id - alphanumeric ID of the thread in which the message resides
159
160
  * @prop {Boolean} authored_by_user - whether or not the current user sent the message
160
161
  * @prop {"message"} type - undocumented
162
+ */
163
+
164
+ /**
165
+ * Represents a poll with choices
166
+ * @typedef {Object} SidechatPoll
167
+ * @prop {String} id - alphanumeric ID of poll
168
+ * @prop {String} post_id - alphanumeric ID of post to which poll is attached
169
+ * @prop {SidechatPollChoice[]} choices - array of poll choices
170
+ * @prop {Boolean} allows_view_results - whether or not poll results are publicly visible
171
+ * @prop {Number} view_results_count - number of users who have viewed poll results
172
+ * @prop {Boolean} participated - whether or not current user has voted in poll
173
+ */
174
+
175
+ /**
176
+ * Represents a poll choice
177
+ * @typedef {Object} SidechatPollChoice
178
+ * @prop {Number} count - number of votes for choice
179
+ * @prop {String} text - user-visible text of choice
180
+ * @prop {Boolean} selected - whether or not current user has voted for choice
161
181
  */
162
182
 
163
183
  /**
@@ -498,8 +518,7 @@ class SidechatAPIClient {
498
518
  }
499
519
  try {
500
520
  const res = await fetch(
501
- `${this.apiRoot}/v1/posts?${
502
- cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
521
+ `${this.apiRoot}/v1/posts?${cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
503
522
  }group_id=${groupID}&type=${category}`,
504
523
  {
505
524
  method: "GET",
@@ -835,6 +854,7 @@ class SidechatAPIClient {
835
854
  * @param {String} text - text content of comment
836
855
  * @param {String} groupID - alphanumeric ID of group in which the parent post resides
837
856
  * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
857
+ * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
838
858
  * @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
839
859
  * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
840
860
  * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
@@ -844,7 +864,8 @@ class SidechatAPIClient {
844
864
  parentPostID,
845
865
  text,
846
866
  groupID,
847
- replyCommentID = parentPostID,
867
+ replyCommentID,
868
+ topLevelReplyID,
848
869
  assetList = [],
849
870
  disableDMs = false,
850
871
  anonymous = false
@@ -864,7 +885,8 @@ class SidechatAPIClient {
864
885
  assets: assetList,
865
886
  group_ids: [groupID],
866
887
  text: text,
867
- reply_post_id: replyCommentID,
888
+ reply_post_id: topLevelReplyID || replyCommentID || parentPostID,
889
+ reply_comment_post_id: replyCommentID || parentPostID,
868
890
  parent_post_id: parentPostID,
869
891
  dms_disabled: disableDMs,
870
892
  using_identity: !anonymous,
@@ -956,6 +978,66 @@ class SidechatAPIClient {
956
978
  }
957
979
  };
958
980
 
981
+ /**
982
+ * Votes on a poll attached to a post
983
+ * @method
984
+ * @param {String} pollId - alphanumeric ID of poll to vote on
985
+ * @param {Number} choiceIndex - index of the choice to vote on
986
+ * @since 2.5.4
987
+ */
988
+ voteOnPoll = async (pollId, choiceIndex) => {
989
+ if (!this.userToken) {
990
+ throw new SidechatAPIError("User is not authenticated.");
991
+ }
992
+ try {
993
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
994
+ method: "POST",
995
+ headers: {
996
+ ...this.defaultHeaders,
997
+ Authorization: `Bearer ${this.userToken}`,
998
+ },
999
+ body: JSON.stringify({
1000
+ poll_id: pollId,
1001
+ choice: choiceIndex,
1002
+ }),
1003
+ });
1004
+ const json = await res.json();
1005
+ return await json;
1006
+ } catch (err) {
1007
+ console.error(err);
1008
+ throw new SidechatAPIError(`Failed to vote on poll`);
1009
+ }
1010
+ };
1011
+
1012
+ /**
1013
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1014
+ * @method
1015
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1016
+ * @since 2.5.4
1017
+ */
1018
+ viewPollResults = async (pollId) => {
1019
+ if (!this.userToken) {
1020
+ throw new SidechatAPIError("User is not authenticated.");
1021
+ }
1022
+ try {
1023
+ const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1024
+ method: "POST",
1025
+ headers: {
1026
+ ...this.defaultHeaders,
1027
+ Authorization: `Bearer ${this.userToken}`,
1028
+ },
1029
+ body: JSON.stringify({
1030
+ poll_id: pollId,
1031
+ }),
1032
+ });
1033
+ const json = await res.json();
1034
+ return await json;
1035
+ } catch (err) {
1036
+ console.error(err);
1037
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1038
+ }
1039
+ };
1040
+
959
1041
  /**
960
1042
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
961
1043
  * @method
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@
14
14
  * @prop {SidechatSimpleAsset[]} assets - array of simple assets attached to post or comment
15
15
  * @prop {Array} attachments - undocumented
16
16
  * @prop {Boolean} dms_disabled - whether or not you can send a DM to creator of post
17
- * @prop {Array} tags - undocumented
17
+ * @prop {String[]} tags - undocumented
18
18
  * @prop {SidechatIdentity} identity - creator's identity information
19
19
  * @prop {Boolean} pinned - undocumented
20
20
  * @prop {Boolean} is_saved - undocumented
@@ -22,6 +22,7 @@
22
22
  * @prop {"group"} [destination] - undocumented
23
23
  * @prop {Number} [comment_count] - number of comments on post (only if type=post)
24
24
  * @prop {Boolean} [comments_disabled] - whether or not you can comment on post (only if type=post)
25
+ * @prop {SidechatPoll} [poll] - poll attached to post (only if the post has a poll)
25
26
  * @prop {String} [parent_post_id] - alphanumeric ID of parent post (only if type=comment)
26
27
  * @prop {String} [reply_post_id] - alphanumeric ID of comment being replied to, falls back to parent_post_id (only if type=comment)
27
28
  * @prop {String} [context] - text content of comment being replied to, falls back to text (only if type=comment)
@@ -154,6 +155,25 @@ var SidechatTypes = {};
154
155
  * @prop {String} chat_id - alphanumeric ID of the thread in which the message resides
155
156
  * @prop {Boolean} authored_by_user - whether or not the current user sent the message
156
157
  * @prop {"message"} type - undocumented
158
+ */
159
+
160
+ /**
161
+ * Represents a poll with choices
162
+ * @typedef {Object} SidechatPoll
163
+ * @prop {String} id - alphanumeric ID of poll
164
+ * @prop {String} post_id - alphanumeric ID of post to which poll is attached
165
+ * @prop {SidechatPollChoice[]} choices - array of poll choices
166
+ * @prop {Boolean} allows_view_results - whether or not poll results are publicly visible
167
+ * @prop {Number} view_results_count - number of users who have viewed poll results
168
+ * @prop {Boolean} participated - whether or not current user has voted in poll
169
+ */
170
+
171
+ /**
172
+ * Represents a poll choice
173
+ * @typedef {Object} SidechatPollChoice
174
+ * @prop {Number} count - number of votes for choice
175
+ * @prop {String} text - user-visible text of choice
176
+ * @prop {Boolean} selected - whether or not current user has voted for choice
157
177
  */
158
178
 
159
179
  /**
@@ -494,8 +514,7 @@ class SidechatAPIClient {
494
514
  }
495
515
  try {
496
516
  const res = await fetch(
497
- `${this.apiRoot}/v1/posts?${
498
- cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
517
+ `${this.apiRoot}/v1/posts?${cursor ? "cursor=" + encodeURIComponent(cursor) + "&" : ""
499
518
  }group_id=${groupID}&type=${category}`,
500
519
  {
501
520
  method: "GET",
@@ -831,6 +850,7 @@ class SidechatAPIClient {
831
850
  * @param {String} text - text content of comment
832
851
  * @param {String} groupID - alphanumeric ID of group in which the parent post resides
833
852
  * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
853
+ * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
834
854
  * @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
835
855
  * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
836
856
  * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
@@ -840,7 +860,8 @@ class SidechatAPIClient {
840
860
  parentPostID,
841
861
  text,
842
862
  groupID,
843
- replyCommentID = parentPostID,
863
+ replyCommentID,
864
+ topLevelReplyID,
844
865
  assetList = [],
845
866
  disableDMs = false,
846
867
  anonymous = false
@@ -860,7 +881,8 @@ class SidechatAPIClient {
860
881
  assets: assetList,
861
882
  group_ids: [groupID],
862
883
  text: text,
863
- reply_post_id: replyCommentID,
884
+ reply_post_id: topLevelReplyID || replyCommentID || parentPostID,
885
+ reply_comment_post_id: replyCommentID || parentPostID,
864
886
  parent_post_id: parentPostID,
865
887
  dms_disabled: disableDMs,
866
888
  using_identity: !anonymous,
@@ -952,6 +974,66 @@ class SidechatAPIClient {
952
974
  }
953
975
  };
954
976
 
977
+ /**
978
+ * Votes on a poll attached to a post
979
+ * @method
980
+ * @param {String} pollId - alphanumeric ID of poll to vote on
981
+ * @param {Number} choiceIndex - index of the choice to vote on
982
+ * @since 2.5.4
983
+ */
984
+ voteOnPoll = async (pollId, choiceIndex) => {
985
+ if (!this.userToken) {
986
+ throw new SidechatAPIError("User is not authenticated.");
987
+ }
988
+ try {
989
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
990
+ method: "POST",
991
+ headers: {
992
+ ...this.defaultHeaders,
993
+ Authorization: `Bearer ${this.userToken}`,
994
+ },
995
+ body: JSON.stringify({
996
+ poll_id: pollId,
997
+ choice: choiceIndex,
998
+ }),
999
+ });
1000
+ const json = await res.json();
1001
+ return await json;
1002
+ } catch (err) {
1003
+ console.error(err);
1004
+ throw new SidechatAPIError(`Failed to vote on poll`);
1005
+ }
1006
+ };
1007
+
1008
+ /**
1009
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1010
+ * @method
1011
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1012
+ * @since 2.5.4
1013
+ */
1014
+ viewPollResults = async (pollId) => {
1015
+ if (!this.userToken) {
1016
+ throw new SidechatAPIError("User is not authenticated.");
1017
+ }
1018
+ try {
1019
+ const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1020
+ method: "POST",
1021
+ headers: {
1022
+ ...this.defaultHeaders,
1023
+ Authorization: `Bearer ${this.userToken}`,
1024
+ },
1025
+ body: JSON.stringify({
1026
+ poll_id: pollId,
1027
+ }),
1028
+ });
1029
+ const json = await res.json();
1030
+ return await json;
1031
+ } catch (err) {
1032
+ console.error(err);
1033
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1034
+ }
1035
+ };
1036
+
955
1037
  /**
956
1038
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
957
1039
  * @method
@@ -59,7 +59,7 @@ export type SidechatPostOrComment = {
59
59
  /**
60
60
  * - undocumented
61
61
  */
62
- tags: any[];
62
+ tags: string[];
63
63
  /**
64
64
  * - creator's identity information
65
65
  */
@@ -88,6 +88,10 @@ export type SidechatPostOrComment = {
88
88
  * - whether or not you can comment on post (only if type=post)
89
89
  */
90
90
  comments_disabled?: boolean;
91
+ /**
92
+ * - poll attached to post (only if the post has a poll)
93
+ */
94
+ poll?: SidechatPoll;
91
95
  /**
92
96
  * - alphanumeric ID of parent post (only if type=comment)
93
97
  */
@@ -386,4 +390,50 @@ export type SidechatDirectMessage = {
386
390
  */
387
391
  type: "message";
388
392
  };
393
+ /**
394
+ * Represents a poll with choices
395
+ */
396
+ export type SidechatPoll = {
397
+ /**
398
+ * - alphanumeric ID of poll
399
+ */
400
+ id: string;
401
+ /**
402
+ * - alphanumeric ID of post to which poll is attached
403
+ */
404
+ post_id: string;
405
+ /**
406
+ * - array of poll choices
407
+ */
408
+ choices: SidechatPollChoice[];
409
+ /**
410
+ * - whether or not poll results are publicly visible
411
+ */
412
+ allows_view_results: boolean;
413
+ /**
414
+ * - number of users who have viewed poll results
415
+ */
416
+ view_results_count: number;
417
+ /**
418
+ * - whether or not current user has voted in poll
419
+ */
420
+ participated: boolean;
421
+ };
422
+ /**
423
+ * Represents a poll choice
424
+ */
425
+ export type SidechatPollChoice = {
426
+ /**
427
+ * - number of votes for choice
428
+ */
429
+ count: number;
430
+ /**
431
+ * - user-visible text of choice
432
+ */
433
+ text: string;
434
+ /**
435
+ * - whether or not current user has voted for choice
436
+ */
437
+ selected: boolean;
438
+ };
389
439
  //# sourceMappingURL=SidechatTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SidechatTypes.d.ts","sourceRoot":"","sources":["../../src/types/SidechatTypes.js"],"names":[],"mappings":";;;;;;;;;UAGU,MAAM,GAAC,SAAS;;;;;;;;;;;;;;;;;;;;WAKhB,aAAa;;;;;;;;;;;;;;;;iBAIb,kBAAkB;;;;YAClB,mBAAmB,EAAE;;;;;;;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