sidechat.js 2.4.2 → 2.4.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.
- package/dist/classes/SidechatAPIClient.d.ts +37 -0
- package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
- package/dist/index.cjs +169 -2
- package/dist/index.mjs +169 -2
- package/dist/types/SidechatTypes.d.ts +74 -0
- package/dist/types/SidechatTypes.d.ts.map +1 -1
- package/docs/sidechat.js/2.4.4/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.4.4/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.4.4/SidechatColorList.html +3 -0
- package/docs/sidechat.js/2.4.4/classes_SidechatAPIClient.js.html +1100 -0
- package/docs/sidechat.js/2.4.4/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.4.4/classes_SidechatColorList.js.html +79 -0
- package/docs/sidechat.js/2.4.4/data/search.json +1 -0
- package/docs/sidechat.js/2.4.4/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.4.4/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.4.4/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.4.4/global.html +3 -0
- package/docs/sidechat.js/2.4.4/index.html +4 -0
- package/docs/sidechat.js/2.4.4/scripts/core.js +726 -0
- package/docs/sidechat.js/2.4.4/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.4.4/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.4.4/scripts/search.js +265 -0
- package/docs/sidechat.js/2.4.4/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.4.4/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-base.css +1161 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.4.4/tutorial-Authentication.html +14 -0
- package/docs/sidechat.js/2.4.4/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.4.4/types_SidechatTypes.js.html +160 -0
- package/package.json +1 -1
- package/src/classes/SidechatAPIClient.js +142 -1
- package/src/tests/directMessageTest.js +23 -0
- package/src/types/SidechatTypes.js +26 -0
|
@@ -261,5 +261,42 @@ declare class SidechatAPIClient {
|
|
|
261
261
|
* @since 2.3.5
|
|
262
262
|
*/
|
|
263
263
|
joinGroupChat: (groupChatID: any, displayName: any, emoji: any, primaryColor: any, secondaryColor: any) => Promise<any>;
|
|
264
|
+
/**
|
|
265
|
+
* Gets a list of the user's direct messages
|
|
266
|
+
* @method
|
|
267
|
+
* @returns {SidechatDirectThread[]}
|
|
268
|
+
* @since 2.4.4
|
|
269
|
+
*/
|
|
270
|
+
getDMs: () => SidechatDirectThread[];
|
|
271
|
+
/**
|
|
272
|
+
* Gets a single direct message thread
|
|
273
|
+
* @method
|
|
274
|
+
* @param {String} id - alphanumeric ID of the chat to fetch
|
|
275
|
+
* @returns {SidechatDirectThread}
|
|
276
|
+
* @since 2.4.4
|
|
277
|
+
*/
|
|
278
|
+
getDMThread: (id: string) => SidechatDirectThread;
|
|
279
|
+
/**
|
|
280
|
+
* Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
|
|
281
|
+
* @method
|
|
282
|
+
* @param {String} chatID - alphanumeric ID of the chat to send to
|
|
283
|
+
* @param {String} text - text content of message
|
|
284
|
+
* @param {String} clientID - alphanumeric device ID
|
|
285
|
+
* @param {SidechatAsset[]} - array of assets to send
|
|
286
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
287
|
+
* @since 2.4.4
|
|
288
|
+
*/
|
|
289
|
+
sendDM: (chatID: string, text: string, clientID: string, assets?: any[], anonymous?: boolean) => Promise<any>;
|
|
290
|
+
/**
|
|
291
|
+
* Creates a new direct message thread
|
|
292
|
+
* @method
|
|
293
|
+
* @param {String} text - text content of message
|
|
294
|
+
* @param {String} clientID - alphanumeric ID of devide
|
|
295
|
+
* @param {String} postID - alphanumeric ID of post or comment
|
|
296
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
297
|
+
* @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
|
|
298
|
+
* @since 2.4.4
|
|
299
|
+
*/
|
|
300
|
+
startDM: (text: string, clientID: string, postID: string, anonymous?: boolean, postContext?: "feed") => Promise<any>;
|
|
264
301
|
}
|
|
265
302
|
//# sourceMappingURL=SidechatAPIClient.d.ts.map
|
|
@@ -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;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAmBE;IAEF;;;;;;OAMG;IACH,8DAsBE;IAEF;;;;;;OAMG;IACH,+CAwBE;IAEF;;;;OAIG;IACH,2CAsBE;IAEF;;;;;OAKG;IACH,6CAwBE;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,2GA2BE;IAEF;;;;;;OAMG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,gEAqBE;IAEF;;;;;OAKG;IACH,mDAqBE;IAEF;;;;OAIG;IACH,kCAkBE;IAEF;;;;OAIG;IACH,wHAiCE;CACH"}
|
|
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,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FAHW,MAAM,kBAkCf;CACH"}
|
package/dist/index.cjs
CHANGED
|
@@ -132,7 +132,33 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
132
132
|
* @prop {SidechatCursorString} cursor
|
|
133
133
|
*/
|
|
134
134
|
|
|
135
|
-
var SidechatTypes = {};
|
|
135
|
+
var SidechatTypes = {};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A direct message thread
|
|
139
|
+
* @typedef {Object} SidechatDirectThread
|
|
140
|
+
* @prop {String} id - alphanumeric ID of thread
|
|
141
|
+
* @prop {String} group_id - alphanumeric ID of group in which the thread exists
|
|
142
|
+
* @prop {String} updated_at - date string of when the last message in the chat was sent
|
|
143
|
+
* @prop {String} post_id - post or comment from which the thread was originally sent
|
|
144
|
+
* @prop {String} post_context - the context of the DM thread (only "feed" is known at the moment)
|
|
145
|
+
* @prop {"accepted"} accept_status - whether or not the other user has accepted this DM
|
|
146
|
+
* @prop {"post"|"comment"} type - the type of the content from which the DM was originally sent
|
|
147
|
+
* @prop {SidechatDirectMessage[]} messages - array of direct message objects
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A single direct message
|
|
152
|
+
* @typedef {Object} SidechatDirectMessage
|
|
153
|
+
* @prop {String} created_at - time at which the message was sent
|
|
154
|
+
* @prop {String} client_id - alphanumeric ID of the device the message was sent on
|
|
155
|
+
* @prop {String} obfuscatedUserId - obfuscated version of the sender's alphanumeric ID
|
|
156
|
+
* @prop {String} text - body text of the message
|
|
157
|
+
* @prop {String} id - alphanumeric ID of the message
|
|
158
|
+
* @prop {String} chat_id - alphanumeric ID of the thread in which the message resides
|
|
159
|
+
* @prop {Boolean} authored_by_user - whether or not the current user sent the message
|
|
160
|
+
* @prop {"message"} type - undocumented
|
|
161
|
+
*/
|
|
136
162
|
|
|
137
163
|
/**
|
|
138
164
|
* Throwable error caused by the Sidechat API
|
|
@@ -1074,7 +1100,7 @@ class SidechatAPIClient {
|
|
|
1074
1100
|
}
|
|
1075
1101
|
try {
|
|
1076
1102
|
const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
|
|
1077
|
-
method: "
|
|
1103
|
+
method: "POST",
|
|
1078
1104
|
headers: {
|
|
1079
1105
|
...this.defaultHeaders,
|
|
1080
1106
|
Authorization: `Bearer ${this.userToken}`,
|
|
@@ -1096,6 +1122,147 @@ class SidechatAPIClient {
|
|
|
1096
1122
|
throw new SidechatAPIError(`Failed to join groupchat.`);
|
|
1097
1123
|
}
|
|
1098
1124
|
};
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Gets a list of the user's direct messages
|
|
1128
|
+
* @method
|
|
1129
|
+
* @returns {SidechatDirectThread[]}
|
|
1130
|
+
* @since 2.4.4
|
|
1131
|
+
*/
|
|
1132
|
+
getDMs = async () => {
|
|
1133
|
+
if (!this.userToken) {
|
|
1134
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1135
|
+
}
|
|
1136
|
+
try {
|
|
1137
|
+
const res = await fetch(`${this.apiRoot}/v1/chats`, {
|
|
1138
|
+
method: "GET",
|
|
1139
|
+
headers: {
|
|
1140
|
+
...this.defaultHeaders,
|
|
1141
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1142
|
+
},
|
|
1143
|
+
});
|
|
1144
|
+
const json = await res.json();
|
|
1145
|
+
const list = await json.chats;
|
|
1146
|
+
let r = [];
|
|
1147
|
+
list.forEach((o) => {
|
|
1148
|
+
r.push(o.chat);
|
|
1149
|
+
});
|
|
1150
|
+
return await r;
|
|
1151
|
+
} catch (err) {
|
|
1152
|
+
console.error(err);
|
|
1153
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Gets a single direct message thread
|
|
1159
|
+
* @method
|
|
1160
|
+
* @param {String} id - alphanumeric ID of the chat to fetch
|
|
1161
|
+
* @returns {SidechatDirectThread}
|
|
1162
|
+
* @since 2.4.4
|
|
1163
|
+
*/
|
|
1164
|
+
getDMThread = async (id) => {
|
|
1165
|
+
if (!this.userToken) {
|
|
1166
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1167
|
+
}
|
|
1168
|
+
try {
|
|
1169
|
+
const res = await fetch(
|
|
1170
|
+
`${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
|
|
1171
|
+
{
|
|
1172
|
+
method: "GET",
|
|
1173
|
+
headers: {
|
|
1174
|
+
...this.defaultHeaders,
|
|
1175
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1176
|
+
},
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1179
|
+
const json = await res.json();
|
|
1180
|
+
return await json.chat;
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
console.error(err);
|
|
1183
|
+
throw new SidechatAPIError(`Failed to fetch DM thread.`);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
|
|
1189
|
+
* @method
|
|
1190
|
+
* @param {String} chatID - alphanumeric ID of the chat to send to
|
|
1191
|
+
* @param {String} text - text content of message
|
|
1192
|
+
* @param {String} clientID - alphanumeric device ID
|
|
1193
|
+
* @param {SidechatAsset[]} - array of assets to send
|
|
1194
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
1195
|
+
* @since 2.4.4
|
|
1196
|
+
*/
|
|
1197
|
+
sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
|
|
1198
|
+
if (!this.userToken) {
|
|
1199
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1200
|
+
}
|
|
1201
|
+
try {
|
|
1202
|
+
const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
|
|
1203
|
+
method: "POST",
|
|
1204
|
+
headers: {
|
|
1205
|
+
...this.defaultHeaders,
|
|
1206
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1207
|
+
},
|
|
1208
|
+
body: JSON.stringify({
|
|
1209
|
+
chat_id: chatID,
|
|
1210
|
+
text: text,
|
|
1211
|
+
client_id: clientID,
|
|
1212
|
+
anonymous: anonymous,
|
|
1213
|
+
assets: assets,
|
|
1214
|
+
}),
|
|
1215
|
+
});
|
|
1216
|
+
const json = await res.json();
|
|
1217
|
+
return await json;
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
console.error(err);
|
|
1220
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Creates a new direct message thread
|
|
1226
|
+
* @method
|
|
1227
|
+
* @param {String} text - text content of message
|
|
1228
|
+
* @param {String} clientID - alphanumeric ID of devide
|
|
1229
|
+
* @param {String} postID - alphanumeric ID of post or comment
|
|
1230
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
1231
|
+
* @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
|
|
1232
|
+
* @since 2.4.4
|
|
1233
|
+
*/
|
|
1234
|
+
startDM = async (
|
|
1235
|
+
text,
|
|
1236
|
+
clientID,
|
|
1237
|
+
postID,
|
|
1238
|
+
anonymous = false,
|
|
1239
|
+
postContext = "feed"
|
|
1240
|
+
) => {
|
|
1241
|
+
if (!this.userToken) {
|
|
1242
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1243
|
+
}
|
|
1244
|
+
try {
|
|
1245
|
+
const res = await fetch(`${this.apiRoot}/v1/chats/start`, {
|
|
1246
|
+
method: "POST",
|
|
1247
|
+
headers: {
|
|
1248
|
+
...this.defaultHeaders,
|
|
1249
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1250
|
+
},
|
|
1251
|
+
body: JSON.stringify({
|
|
1252
|
+
text: text,
|
|
1253
|
+
client_id: clientID,
|
|
1254
|
+
post_id: postID,
|
|
1255
|
+
anonymous: anonymous,
|
|
1256
|
+
post_context: postContext,
|
|
1257
|
+
}),
|
|
1258
|
+
});
|
|
1259
|
+
const json = await res.json();
|
|
1260
|
+
return await json;
|
|
1261
|
+
} catch (err) {
|
|
1262
|
+
console.error(err);
|
|
1263
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1099
1266
|
}
|
|
1100
1267
|
|
|
1101
1268
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -128,7 +128,33 @@
|
|
|
128
128
|
* @prop {SidechatCursorString} cursor
|
|
129
129
|
*/
|
|
130
130
|
|
|
131
|
-
var SidechatTypes = {};
|
|
131
|
+
var SidechatTypes = {};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A direct message thread
|
|
135
|
+
* @typedef {Object} SidechatDirectThread
|
|
136
|
+
* @prop {String} id - alphanumeric ID of thread
|
|
137
|
+
* @prop {String} group_id - alphanumeric ID of group in which the thread exists
|
|
138
|
+
* @prop {String} updated_at - date string of when the last message in the chat was sent
|
|
139
|
+
* @prop {String} post_id - post or comment from which the thread was originally sent
|
|
140
|
+
* @prop {String} post_context - the context of the DM thread (only "feed" is known at the moment)
|
|
141
|
+
* @prop {"accepted"} accept_status - whether or not the other user has accepted this DM
|
|
142
|
+
* @prop {"post"|"comment"} type - the type of the content from which the DM was originally sent
|
|
143
|
+
* @prop {SidechatDirectMessage[]} messages - array of direct message objects
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A single direct message
|
|
148
|
+
* @typedef {Object} SidechatDirectMessage
|
|
149
|
+
* @prop {String} created_at - time at which the message was sent
|
|
150
|
+
* @prop {String} client_id - alphanumeric ID of the device the message was sent on
|
|
151
|
+
* @prop {String} obfuscatedUserId - obfuscated version of the sender's alphanumeric ID
|
|
152
|
+
* @prop {String} text - body text of the message
|
|
153
|
+
* @prop {String} id - alphanumeric ID of the message
|
|
154
|
+
* @prop {String} chat_id - alphanumeric ID of the thread in which the message resides
|
|
155
|
+
* @prop {Boolean} authored_by_user - whether or not the current user sent the message
|
|
156
|
+
* @prop {"message"} type - undocumented
|
|
157
|
+
*/
|
|
132
158
|
|
|
133
159
|
/**
|
|
134
160
|
* Throwable error caused by the Sidechat API
|
|
@@ -1070,7 +1096,7 @@ class SidechatAPIClient {
|
|
|
1070
1096
|
}
|
|
1071
1097
|
try {
|
|
1072
1098
|
const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
|
|
1073
|
-
method: "
|
|
1099
|
+
method: "POST",
|
|
1074
1100
|
headers: {
|
|
1075
1101
|
...this.defaultHeaders,
|
|
1076
1102
|
Authorization: `Bearer ${this.userToken}`,
|
|
@@ -1092,6 +1118,147 @@ class SidechatAPIClient {
|
|
|
1092
1118
|
throw new SidechatAPIError(`Failed to join groupchat.`);
|
|
1093
1119
|
}
|
|
1094
1120
|
};
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Gets a list of the user's direct messages
|
|
1124
|
+
* @method
|
|
1125
|
+
* @returns {SidechatDirectThread[]}
|
|
1126
|
+
* @since 2.4.4
|
|
1127
|
+
*/
|
|
1128
|
+
getDMs = async () => {
|
|
1129
|
+
if (!this.userToken) {
|
|
1130
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1131
|
+
}
|
|
1132
|
+
try {
|
|
1133
|
+
const res = await fetch(`${this.apiRoot}/v1/chats`, {
|
|
1134
|
+
method: "GET",
|
|
1135
|
+
headers: {
|
|
1136
|
+
...this.defaultHeaders,
|
|
1137
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1138
|
+
},
|
|
1139
|
+
});
|
|
1140
|
+
const json = await res.json();
|
|
1141
|
+
const list = await json.chats;
|
|
1142
|
+
let r = [];
|
|
1143
|
+
list.forEach((o) => {
|
|
1144
|
+
r.push(o.chat);
|
|
1145
|
+
});
|
|
1146
|
+
return await r;
|
|
1147
|
+
} catch (err) {
|
|
1148
|
+
console.error(err);
|
|
1149
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Gets a single direct message thread
|
|
1155
|
+
* @method
|
|
1156
|
+
* @param {String} id - alphanumeric ID of the chat to fetch
|
|
1157
|
+
* @returns {SidechatDirectThread}
|
|
1158
|
+
* @since 2.4.4
|
|
1159
|
+
*/
|
|
1160
|
+
getDMThread = async (id) => {
|
|
1161
|
+
if (!this.userToken) {
|
|
1162
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1163
|
+
}
|
|
1164
|
+
try {
|
|
1165
|
+
const res = await fetch(
|
|
1166
|
+
`${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
|
|
1167
|
+
{
|
|
1168
|
+
method: "GET",
|
|
1169
|
+
headers: {
|
|
1170
|
+
...this.defaultHeaders,
|
|
1171
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1172
|
+
},
|
|
1173
|
+
}
|
|
1174
|
+
);
|
|
1175
|
+
const json = await res.json();
|
|
1176
|
+
return await json.chat;
|
|
1177
|
+
} catch (err) {
|
|
1178
|
+
console.error(err);
|
|
1179
|
+
throw new SidechatAPIError(`Failed to fetch DM thread.`);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
|
|
1185
|
+
* @method
|
|
1186
|
+
* @param {String} chatID - alphanumeric ID of the chat to send to
|
|
1187
|
+
* @param {String} text - text content of message
|
|
1188
|
+
* @param {String} clientID - alphanumeric device ID
|
|
1189
|
+
* @param {SidechatAsset[]} - array of assets to send
|
|
1190
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
1191
|
+
* @since 2.4.4
|
|
1192
|
+
*/
|
|
1193
|
+
sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
|
|
1194
|
+
if (!this.userToken) {
|
|
1195
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1196
|
+
}
|
|
1197
|
+
try {
|
|
1198
|
+
const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
|
|
1199
|
+
method: "POST",
|
|
1200
|
+
headers: {
|
|
1201
|
+
...this.defaultHeaders,
|
|
1202
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1203
|
+
},
|
|
1204
|
+
body: JSON.stringify({
|
|
1205
|
+
chat_id: chatID,
|
|
1206
|
+
text: text,
|
|
1207
|
+
client_id: clientID,
|
|
1208
|
+
anonymous: anonymous,
|
|
1209
|
+
assets: assets,
|
|
1210
|
+
}),
|
|
1211
|
+
});
|
|
1212
|
+
const json = await res.json();
|
|
1213
|
+
return await json;
|
|
1214
|
+
} catch (err) {
|
|
1215
|
+
console.error(err);
|
|
1216
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Creates a new direct message thread
|
|
1222
|
+
* @method
|
|
1223
|
+
* @param {String} text - text content of message
|
|
1224
|
+
* @param {String} clientID - alphanumeric ID of devide
|
|
1225
|
+
* @param {String} postID - alphanumeric ID of post or comment
|
|
1226
|
+
* @param {Boolean} anonymous - whether the DM should be sent anonymously
|
|
1227
|
+
* @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
|
|
1228
|
+
* @since 2.4.4
|
|
1229
|
+
*/
|
|
1230
|
+
startDM = async (
|
|
1231
|
+
text,
|
|
1232
|
+
clientID,
|
|
1233
|
+
postID,
|
|
1234
|
+
anonymous = false,
|
|
1235
|
+
postContext = "feed"
|
|
1236
|
+
) => {
|
|
1237
|
+
if (!this.userToken) {
|
|
1238
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
1239
|
+
}
|
|
1240
|
+
try {
|
|
1241
|
+
const res = await fetch(`${this.apiRoot}/v1/chats/start`, {
|
|
1242
|
+
method: "POST",
|
|
1243
|
+
headers: {
|
|
1244
|
+
...this.defaultHeaders,
|
|
1245
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
1246
|
+
},
|
|
1247
|
+
body: JSON.stringify({
|
|
1248
|
+
text: text,
|
|
1249
|
+
client_id: clientID,
|
|
1250
|
+
post_id: postID,
|
|
1251
|
+
anonymous: anonymous,
|
|
1252
|
+
post_context: postContext,
|
|
1253
|
+
}),
|
|
1254
|
+
});
|
|
1255
|
+
const json = await res.json();
|
|
1256
|
+
return await json;
|
|
1257
|
+
} catch (err) {
|
|
1258
|
+
console.error(err);
|
|
1259
|
+
throw new SidechatAPIError(`Failed to fetch DMs.`);
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1095
1262
|
}
|
|
1096
1263
|
|
|
1097
1264
|
/**
|
|
@@ -312,4 +312,78 @@ export type SidechatPostsAndCursor = {
|
|
|
312
312
|
posts: SidechatPostOrComment[];
|
|
313
313
|
cursor: SidechatCursorString;
|
|
314
314
|
};
|
|
315
|
+
/**
|
|
316
|
+
* A direct message thread
|
|
317
|
+
*/
|
|
318
|
+
export type SidechatDirectThread = {
|
|
319
|
+
/**
|
|
320
|
+
* - alphanumeric ID of thread
|
|
321
|
+
*/
|
|
322
|
+
id: string;
|
|
323
|
+
/**
|
|
324
|
+
* - alphanumeric ID of group in which the thread exists
|
|
325
|
+
*/
|
|
326
|
+
group_id: string;
|
|
327
|
+
/**
|
|
328
|
+
* - date string of when the last message in the chat was sent
|
|
329
|
+
*/
|
|
330
|
+
updated_at: string;
|
|
331
|
+
/**
|
|
332
|
+
* - post or comment from which the thread was originally sent
|
|
333
|
+
*/
|
|
334
|
+
post_id: string;
|
|
335
|
+
/**
|
|
336
|
+
* - the context of the DM thread (only "feed" is known at the moment)
|
|
337
|
+
*/
|
|
338
|
+
post_context: string;
|
|
339
|
+
/**
|
|
340
|
+
* - whether or not the other user has accepted this DM
|
|
341
|
+
*/
|
|
342
|
+
accept_status: "accepted";
|
|
343
|
+
/**
|
|
344
|
+
* - the type of the content from which the DM was originally sent
|
|
345
|
+
*/
|
|
346
|
+
type: "post" | "comment";
|
|
347
|
+
/**
|
|
348
|
+
* - array of direct message objects
|
|
349
|
+
*/
|
|
350
|
+
messages: SidechatDirectMessage[];
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* A single direct message
|
|
354
|
+
*/
|
|
355
|
+
export type SidechatDirectMessage = {
|
|
356
|
+
/**
|
|
357
|
+
* - time at which the message was sent
|
|
358
|
+
*/
|
|
359
|
+
created_at: string;
|
|
360
|
+
/**
|
|
361
|
+
* - alphanumeric ID of the device the message was sent on
|
|
362
|
+
*/
|
|
363
|
+
client_id: string;
|
|
364
|
+
/**
|
|
365
|
+
* - obfuscated version of the sender's alphanumeric ID
|
|
366
|
+
*/
|
|
367
|
+
obfuscatedUserId: string;
|
|
368
|
+
/**
|
|
369
|
+
* - body text of the message
|
|
370
|
+
*/
|
|
371
|
+
text: string;
|
|
372
|
+
/**
|
|
373
|
+
* - alphanumeric ID of the message
|
|
374
|
+
*/
|
|
375
|
+
id: string;
|
|
376
|
+
/**
|
|
377
|
+
* - alphanumeric ID of the thread in which the message resides
|
|
378
|
+
*/
|
|
379
|
+
chat_id: string;
|
|
380
|
+
/**
|
|
381
|
+
* - whether or not the current user sent the message
|
|
382
|
+
*/
|
|
383
|
+
authored_by_user: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* - undocumented
|
|
386
|
+
*/
|
|
387
|
+
type: "message";
|
|
388
|
+
};
|
|
315
389
|
//# 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,eAA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