sidechat.js 2.5.2 → 2.5.4

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 (93) hide show
  1. package/dist/classes/SidechatAPIClient.d.ts +15 -0
  2. package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
  3. package/dist/index.cjs +84 -12
  4. package/dist/index.mjs +84 -12
  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.2/SidechatAPIClient.html +1 -1
  8. package/docs/sidechat.js/2.5.2/SidechatAPIError.html +1 -1
  9. package/docs/sidechat.js/2.5.2/SidechatColorList.html +1 -1
  10. package/docs/sidechat.js/2.5.2/classes_SidechatAPIClient.js.html +2 -2
  11. package/docs/sidechat.js/2.5.2/classes_SidechatAPIError.js.html +2 -2
  12. package/docs/sidechat.js/2.5.2/classes_SidechatColorList.js.html +2 -2
  13. package/docs/sidechat.js/2.5.2/global.html +1 -1
  14. package/docs/sidechat.js/2.5.2/index.html +2 -2
  15. package/docs/sidechat.js/2.5.2/tutorial-Authentication.html +2 -2
  16. package/docs/sidechat.js/2.5.2/tutorial-Email Registration.html +2 -2
  17. package/docs/sidechat.js/2.5.2/types_SidechatTypes.js.html +2 -2
  18. package/docs/sidechat.js/2.5.3/SidechatAPIClient.html +3 -0
  19. package/docs/sidechat.js/2.5.3/SidechatAPIError.html +3 -0
  20. package/docs/sidechat.js/2.5.3/SidechatColorList.html +3 -0
  21. package/docs/sidechat.js/2.5.3/classes_SidechatAPIClient.js.html +1180 -0
  22. package/docs/sidechat.js/2.5.3/classes_SidechatAPIError.js.html +16 -0
  23. package/docs/sidechat.js/2.5.3/classes_SidechatColorList.js.html +79 -0
  24. package/docs/sidechat.js/2.5.3/data/search.json +1 -0
  25. package/docs/sidechat.js/2.5.3/fonts/Inconsolata-Regular.ttf +0 -0
  26. package/docs/sidechat.js/2.5.3/fonts/OpenSans-Regular.ttf +0 -0
  27. package/docs/sidechat.js/2.5.3/fonts/WorkSans-Bold.ttf +0 -0
  28. package/docs/sidechat.js/2.5.3/global.html +3 -0
  29. package/docs/sidechat.js/2.5.3/index.html +4 -0
  30. package/docs/sidechat.js/2.5.3/scripts/core.js +726 -0
  31. package/docs/sidechat.js/2.5.3/scripts/core.min.js +23 -0
  32. package/docs/sidechat.js/2.5.3/scripts/resize.js +90 -0
  33. package/docs/sidechat.js/2.5.3/scripts/search.js +265 -0
  34. package/docs/sidechat.js/2.5.3/scripts/search.min.js +6 -0
  35. package/docs/sidechat.js/2.5.3/scripts/third-party/Apache-License-2.0.txt +202 -0
  36. package/docs/sidechat.js/2.5.3/scripts/third-party/fuse.js +9 -0
  37. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-line-num-original.js +369 -0
  38. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-line-num.js +1 -0
  39. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs-original.js +5171 -0
  40. package/docs/sidechat.js/2.5.3/scripts/third-party/hljs.js +1 -0
  41. package/docs/sidechat.js/2.5.3/scripts/third-party/popper.js +5 -0
  42. package/docs/sidechat.js/2.5.3/scripts/third-party/tippy.js +1 -0
  43. package/docs/sidechat.js/2.5.3/scripts/third-party/tocbot.js +672 -0
  44. package/docs/sidechat.js/2.5.3/scripts/third-party/tocbot.min.js +1 -0
  45. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-base.css +1159 -0
  46. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-dark.css +412 -0
  47. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-light.css +482 -0
  48. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  49. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  50. package/docs/sidechat.js/2.5.3/styles/clean-jsdoc-theme.min.css +1 -0
  51. package/docs/sidechat.js/2.5.3/tutorial-Authentication.html +14 -0
  52. package/docs/sidechat.js/2.5.3/tutorial-Email Registration.html +6 -0
  53. package/docs/sidechat.js/2.5.3/types_SidechatTypes.js.html +160 -0
  54. package/docs/sidechat.js/2.5.4/SidechatAPIClient.html +3 -0
  55. package/docs/sidechat.js/2.5.4/SidechatAPIError.html +3 -0
  56. package/docs/sidechat.js/2.5.4/SidechatColorList.html +3 -0
  57. package/docs/sidechat.js/2.5.4/classes_SidechatAPIClient.js.html +1240 -0
  58. package/docs/sidechat.js/2.5.4/classes_SidechatAPIError.js.html +16 -0
  59. package/docs/sidechat.js/2.5.4/classes_SidechatColorList.js.html +79 -0
  60. package/docs/sidechat.js/2.5.4/data/search.json +1 -0
  61. package/docs/sidechat.js/2.5.4/fonts/Inconsolata-Regular.ttf +0 -0
  62. package/docs/sidechat.js/2.5.4/fonts/OpenSans-Regular.ttf +0 -0
  63. package/docs/sidechat.js/2.5.4/fonts/WorkSans-Bold.ttf +0 -0
  64. package/docs/sidechat.js/2.5.4/global.html +3 -0
  65. package/docs/sidechat.js/2.5.4/index.html +4 -0
  66. package/docs/sidechat.js/2.5.4/scripts/core.js +726 -0
  67. package/docs/sidechat.js/2.5.4/scripts/core.min.js +23 -0
  68. package/docs/sidechat.js/2.5.4/scripts/resize.js +90 -0
  69. package/docs/sidechat.js/2.5.4/scripts/search.js +265 -0
  70. package/docs/sidechat.js/2.5.4/scripts/search.min.js +6 -0
  71. package/docs/sidechat.js/2.5.4/scripts/third-party/Apache-License-2.0.txt +202 -0
  72. package/docs/sidechat.js/2.5.4/scripts/third-party/fuse.js +9 -0
  73. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num-original.js +369 -0
  74. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-line-num.js +1 -0
  75. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs-original.js +5171 -0
  76. package/docs/sidechat.js/2.5.4/scripts/third-party/hljs.js +1 -0
  77. package/docs/sidechat.js/2.5.4/scripts/third-party/popper.js +5 -0
  78. package/docs/sidechat.js/2.5.4/scripts/third-party/tippy.js +1 -0
  79. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.js +672 -0
  80. package/docs/sidechat.js/2.5.4/scripts/third-party/tocbot.min.js +1 -0
  81. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-base.css +1159 -0
  82. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-dark.css +412 -0
  83. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-light.css +482 -0
  84. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  85. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  86. package/docs/sidechat.js/2.5.4/styles/clean-jsdoc-theme.min.css +1 -0
  87. package/docs/sidechat.js/2.5.4/tutorial-Authentication.html +14 -0
  88. package/docs/sidechat.js/2.5.4/tutorial-Email Registration.html +6 -0
  89. package/docs/sidechat.js/2.5.4/types_SidechatTypes.js.html +180 -0
  90. package/jsdoc.json +1 -0
  91. package/package.json +1 -1
  92. package/src/classes/SidechatAPIClient.js +63 -11
  93. package/src/types/SidechatTypes.js +21 -1
@@ -227,6 +227,21 @@ declare class SidechatAPIClient {
227
227
  * @param {String} postOrCommentID - alphanumeric ID of post to delete
228
228
  */
229
229
  deletePostOrComment: (postOrCommentID: string) => Promise<any>;
230
+ /**
231
+ * Votes on a poll attached to a post
232
+ * @method
233
+ * @param {String} pollId - alphanumeric ID of poll to vote on
234
+ * @param {Number} choiceIndex - index of the choice to vote on
235
+ * @since 2.5.4
236
+ */
237
+ voteOnPoll: (pollId: string, choiceIndex: number) => Promise<any>;
238
+ /**
239
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
240
+ * @method
241
+ * @param {String} pollId - alphanumeric ID of poll to vote on
242
+ * @since 2.5.4
243
+ */
244
+ viewPollResults: (pollId: string) => Promise<any>;
230
245
  /**
231
246
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
232
247
  * @method
@@ -1 +1 @@
1
- {"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IA2BE;;;;OAIG;IACH,yDAOC;IAtCD;;;SAGK;IACL,6BAAU;IAEV;;;;;OAKG;IACH,oBAKE;IAEF;;;;OAIG;IACH,gBAAqC;IAgBrC;;;;OAIG;IACH,6CAEE;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,2DA2B7B;IAEF;;;;;;OAMG;IACH,sEAsBE;IAEF;;;;;;;OAOG;IACH,6EAqBE;IAEF;;;;;;OAMG;IACH,8BAHW,OAAO,GAAC,UAAU,KAChB,uBAAuB,CAyBlC;IAEF;;;;;;OAMG;IACH,qCAFa,uBAAuB,CAqElC;IAEF;;;;;;OAMG;IACH,2CAFa,eAAe,CAqB1B;IAEF;;;;;OAKG;IACH,uBAFa,sBAAsB,CAoBjC;IAEF;;;;;OAKG;IACH,0CAkBE;IAEF;;;;;;OAMG;IACH,sDAkBE;IAEF;;;;;;OAMG;IACH,yEAwBE;IAEF;;;;;;;;;;;;OAYG;IACH,0GALW,qBAAqB,sEAyC9B;IAEF;;;;;;;;;;;OAWG;IACH,wDANW,qBAAqB,iGAyC9B;IAEF;;;;;OAKG;IACH,+DAqBE;IAEF;;;;;;;;OAQG;IACH,sEAiDE;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,sBAAsB,CA0BjC;IAEF;;;;;;OAMG;IACH,kDAqBE;IAEF;;;;;;;;;OASG;IACH,kEAJW,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,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;;;;;;OAMG;IACH,kEAsBE;IAEF;;;;;OAKG;IACH,kDAqBE;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"}
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
  /**
@@ -956,6 +976,66 @@ class SidechatAPIClient {
956
976
  }
957
977
  };
958
978
 
979
+ /**
980
+ * Votes on a poll attached to a post
981
+ * @method
982
+ * @param {String} pollId - alphanumeric ID of poll to vote on
983
+ * @param {Number} choiceIndex - index of the choice to vote on
984
+ * @since 2.5.4
985
+ */
986
+ voteOnPoll = async (pollId, choiceIndex) => {
987
+ if (!this.userToken) {
988
+ throw new SidechatAPIError("User is not authenticated.");
989
+ }
990
+ try {
991
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
992
+ method: "POST",
993
+ headers: {
994
+ ...this.defaultHeaders,
995
+ Authorization: `Bearer ${this.userToken}`,
996
+ },
997
+ body: JSON.stringify({
998
+ poll_id: pollId,
999
+ choice: choiceIndex,
1000
+ }),
1001
+ });
1002
+ const json = await res.json();
1003
+ return await json;
1004
+ } catch (err) {
1005
+ console.error(err);
1006
+ throw new SidechatAPIError(`Failed to vote on poll`);
1007
+ }
1008
+ };
1009
+
1010
+ /**
1011
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1012
+ * @method
1013
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1014
+ * @since 2.5.4
1015
+ */
1016
+ viewPollResults = async (pollId) => {
1017
+ if (!this.userToken) {
1018
+ throw new SidechatAPIError("User is not authenticated.");
1019
+ }
1020
+ try {
1021
+ const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1022
+ method: "POST",
1023
+ headers: {
1024
+ ...this.defaultHeaders,
1025
+ Authorization: `Bearer ${this.userToken}`,
1026
+ },
1027
+ body: JSON.stringify({
1028
+ poll_id: pollId,
1029
+ }),
1030
+ });
1031
+ const json = await res.json();
1032
+ return await json;
1033
+ } catch (err) {
1034
+ console.error(err);
1035
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1036
+ }
1037
+ };
1038
+
959
1039
  /**
960
1040
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
961
1041
  * @method
@@ -970,20 +1050,12 @@ class SidechatAPIClient {
970
1050
  throw new SidechatAPIError("User is not authenticated.");
971
1051
  }
972
1052
 
973
- let imageType;
974
- switch (mimeType) {
975
- case "image/png":
976
- imageType = "png";
977
- break;
978
- case "image/jpeg":
979
- imageType = "jpeg";
980
- break;
981
- default:
982
- throw new SidechatAPIError("Unsupported image format.");
1053
+ let imageType = mimeType.split("/")[1];
1054
+ if (!["png", "jpeg", "gif"].includes(imageType)) {
1055
+ throw new SidechatAPIError("Unsupported image format.");
983
1056
  }
984
1057
 
985
1058
  const data = new FormData();
986
-
987
1059
  data.append("image", {
988
1060
  name: name,
989
1061
  type: mimeType,
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
  /**
@@ -952,6 +972,66 @@ class SidechatAPIClient {
952
972
  }
953
973
  };
954
974
 
975
+ /**
976
+ * Votes on a poll attached to a post
977
+ * @method
978
+ * @param {String} pollId - alphanumeric ID of poll to vote on
979
+ * @param {Number} choiceIndex - index of the choice to vote on
980
+ * @since 2.5.4
981
+ */
982
+ voteOnPoll = async (pollId, choiceIndex) => {
983
+ if (!this.userToken) {
984
+ throw new SidechatAPIError("User is not authenticated.");
985
+ }
986
+ try {
987
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
988
+ method: "POST",
989
+ headers: {
990
+ ...this.defaultHeaders,
991
+ Authorization: `Bearer ${this.userToken}`,
992
+ },
993
+ body: JSON.stringify({
994
+ poll_id: pollId,
995
+ choice: choiceIndex,
996
+ }),
997
+ });
998
+ const json = await res.json();
999
+ return await json;
1000
+ } catch (err) {
1001
+ console.error(err);
1002
+ throw new SidechatAPIError(`Failed to vote on poll`);
1003
+ }
1004
+ };
1005
+
1006
+ /**
1007
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
1008
+ * @method
1009
+ * @param {String} pollId - alphanumeric ID of poll to vote on
1010
+ * @since 2.5.4
1011
+ */
1012
+ viewPollResults = async (pollId) => {
1013
+ if (!this.userToken) {
1014
+ throw new SidechatAPIError("User is not authenticated.");
1015
+ }
1016
+ try {
1017
+ const res = await fetch(`${this.apiRoot}/v1/polls/view_results`, {
1018
+ method: "POST",
1019
+ headers: {
1020
+ ...this.defaultHeaders,
1021
+ Authorization: `Bearer ${this.userToken}`,
1022
+ },
1023
+ body: JSON.stringify({
1024
+ poll_id: pollId,
1025
+ }),
1026
+ });
1027
+ const json = await res.json();
1028
+ return await json;
1029
+ } catch (err) {
1030
+ console.error(err);
1031
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
1032
+ }
1033
+ };
1034
+
955
1035
  /**
956
1036
  * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
957
1037
  * @method
@@ -966,20 +1046,12 @@ class SidechatAPIClient {
966
1046
  throw new SidechatAPIError("User is not authenticated.");
967
1047
  }
968
1048
 
969
- let imageType;
970
- switch (mimeType) {
971
- case "image/png":
972
- imageType = "png";
973
- break;
974
- case "image/jpeg":
975
- imageType = "jpeg";
976
- break;
977
- default:
978
- throw new SidechatAPIError("Unsupported image format.");
1049
+ let imageType = mimeType.split("/")[1];
1050
+ if (!["png", "jpeg", "gif"].includes(imageType)) {
1051
+ throw new SidechatAPIError("Unsupported image format.");
979
1052
  }
980
1053
 
981
1054
  const data = new FormData();
982
-
983
1055
  data.append("image", {
984
1056
  name: name,
985
1057
  type: mimeType,
@@ -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;;;;;;;;;;;;;;;;cAIrB,gBAAgB;;;;;;;;;;;;mBAGhB,WAAW,GAAC,eAAe;;;;kBAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAcP,YAAY,GAAC,QAAQ;;;;;;;;qBAErB,MAAM,GAAC,QAAQ,GAAC,cAAc;;;;sBAC9B,SAAS,GAAC,eAAe,GAAC,mBAAmB;;;;8BAC7C,MAAM,GAAC,MAAM;;;;;;;;;;;;eAGb,uBAAuB;;;;;;;;;;;;;;;;;;;;;UASvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;UAGlB,uBAAuB;;;;;;;;;;;;;;;;;cAQvB,qBAAqB;;;;SACrB,uBAAuB;;;;;;;;;;;;;;;;;UAQvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBlB,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAyBjB,QAAQ,GAAC,UAAU,GAAC,MAAM;;;;;;;;;WAW7B,qBAAqB,EAAE;YACvB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAapB,UAAU;;;;UACV,MAAM,GAAC,SAAS;;;;cAChB,qBAAqB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAavB,SAAS"}
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;;;;;;;;;;;;UAGrB,QAAQ;;;;cACR,gBAAgB;;;;;;;;;;;;mBAGhB,WAAW,GAAC,eAAe;;;;kBAC3B,OAAO;;;;;;;;;;;;WAGP,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAYZ,YAAY,GAAC,QAAQ;;;;;;;;qBAErB,MAAM,GAAC,QAAQ,GAAC,cAAc;;;;sBAC9B,SAAS,GAAC,eAAe,GAAC,mBAAmB;;;;8BAC7C,MAAM,GAAC,MAAM;;;;;;;;;;;;eAGb,uBAAuB;;;;;;;;;;;;;;;;;;;;;UASvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;UAGlB,uBAAuB;;;;;;;;;;;;;;;;;cAQvB,qBAAqB;;;;SACrB,uBAAuB;;;;;;;;;;;;;;;;;UAQvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBlB,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAyBjB,QAAQ,GAAC,UAAU,GAAC,MAAM;;;;;;;;;WAW7B,qBAAqB,EAAE;YACvB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAapB,UAAU;;;;UACV,MAAM,GAAC,SAAS;;;;cAChB,qBAAqB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAavB,SAAS;;;;;;;;;;;;;;;;;aAQT,kBAAkB,EAAE"}