@amityco/ts-sdk-react-native 7.32.1-52b2a8b.0 → 7.33.1-0d1d5d54.0
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/@types/domains/comment.d.ts +2 -2
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +23 -3
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +4 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +11 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/cache/api/dropFromCache.d.ts.map +1 -1
- package/dist/cache/api/pushToCache.d.ts.map +1 -1
- package/dist/cache/api/queryCache.d.ts.map +1 -1
- package/dist/cache/api/queryCacheByProperty.d.ts +3 -0
- package/dist/cache/api/queryCacheByProperty.d.ts.map +1 -0
- package/dist/cache/api/tests/queryCache.test.d.ts +2 -0
- package/dist/cache/api/tests/queryCache.test.d.ts.map +1 -0
- package/dist/cache/utils/cacheIndex.d.ts +15 -0
- package/dist/cache/utils/cacheIndex.d.ts.map +1 -0
- package/dist/commentRepository/api/createComment.d.ts +1 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/tests/createComment.gif.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/createComment.gif.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts.map +1 -0
- package/dist/commentRepository/api/updateComment.d.ts +9 -2
- package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts.map +1 -0
- package/dist/commentRepository/utils/dataTypes.d.ts +2 -0
- package/dist/commentRepository/utils/dataTypes.d.ts.map +1 -0
- package/dist/fileRepository/api/uploadImage.d.ts +2 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/index.cjs.js +217 -58
- package/dist/index.esm.js +217 -58
- package/dist/index.umd.js +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/postRepository/api/createMixedMediaPost.d.ts +6 -6
- package/dist/postRepository/api/createMixedMediaPost.d.ts.map +1 -1
- package/dist/postRepository/api/createPost.d.ts +1 -4
- package/dist/postRepository/api/createPost.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +4 -5
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/api/tests/gifPost.test.d.ts +2 -0
- package/dist/postRepository/api/tests/gifPost.test.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts.d.ts +4 -0
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/postRepository/utils/attachments.d.ts +8 -0
- package/dist/postRepository/utils/attachments.d.ts.map +1 -0
- package/dist/utils/gifAttachment.d.ts +5 -0
- package/dist/utils/gifAttachment.d.ts.map +1 -0
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts +2 -0
- package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts.map +1 -0
- package/dist/utils/postTypePredicate.d.ts +1 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -214,6 +214,7 @@ const PostContentType = Object.freeze({
|
|
|
214
214
|
AUDIO: 'audio',
|
|
215
215
|
ROOM: 'room',
|
|
216
216
|
EVENT: 'event',
|
|
217
|
+
GIF: 'gif',
|
|
217
218
|
});
|
|
218
219
|
const PostStructureType = Object.freeze({
|
|
219
220
|
TEXT: 'text',
|
|
@@ -223,6 +224,8 @@ const PostStructureType = Object.freeze({
|
|
|
223
224
|
AUDIO: 'audio',
|
|
224
225
|
MIXED: 'mixed',
|
|
225
226
|
EVENT: 'event',
|
|
227
|
+
/** A post that holds only GIFs. GIFs beside other media make the post `mixed`. */
|
|
228
|
+
GIF: 'gif',
|
|
226
229
|
});
|
|
227
230
|
|
|
228
231
|
exports.InvitationTypeEnum = void 0;
|
|
@@ -382,8 +385,8 @@ exports.AmityLiveViewerCountMode = void 0;
|
|
|
382
385
|
|
|
383
386
|
function getVersion() {
|
|
384
387
|
try {
|
|
385
|
-
// the string ''v7.
|
|
386
|
-
return 'v7.
|
|
388
|
+
// the string ''v7.33.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
389
|
+
return 'v7.33.0-cjs';
|
|
387
390
|
}
|
|
388
391
|
catch (error) {
|
|
389
392
|
return '__dev__';
|
|
@@ -1205,6 +1208,116 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
1205
1208
|
return true;
|
|
1206
1209
|
};
|
|
1207
1210
|
|
|
1211
|
+
// Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
|
|
1212
|
+
const indexes = new WeakMap();
|
|
1213
|
+
const prefixesFor = (key) => {
|
|
1214
|
+
if (typeof key[0] !== 'string')
|
|
1215
|
+
return [];
|
|
1216
|
+
const prefixes = [JSON.stringify([key[0]])];
|
|
1217
|
+
if (typeof key[1] === 'string')
|
|
1218
|
+
prefixes.push(JSON.stringify([key[0], key[1]]));
|
|
1219
|
+
return prefixes;
|
|
1220
|
+
};
|
|
1221
|
+
const removePropertyValue = (property, indexed) => {
|
|
1222
|
+
const previous = property.previousValues.get(indexed.encodedKey);
|
|
1223
|
+
if (previous === undefined)
|
|
1224
|
+
return;
|
|
1225
|
+
const matches = property.values.get(previous);
|
|
1226
|
+
matches.delete(indexed);
|
|
1227
|
+
if (!matches.size)
|
|
1228
|
+
property.values.delete(previous);
|
|
1229
|
+
property.previousValues.delete(indexed.encodedKey);
|
|
1230
|
+
};
|
|
1231
|
+
const addPropertyValue = (data, property, indexed) => {
|
|
1232
|
+
var _a;
|
|
1233
|
+
if (!partialMatch(property.prefix, indexed.key))
|
|
1234
|
+
return;
|
|
1235
|
+
const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
|
|
1236
|
+
if (typeof value !== 'string')
|
|
1237
|
+
return;
|
|
1238
|
+
let matches = property.values.get(value);
|
|
1239
|
+
if (!matches) {
|
|
1240
|
+
matches = new Set();
|
|
1241
|
+
property.values.set(value, matches);
|
|
1242
|
+
}
|
|
1243
|
+
matches.add(indexed);
|
|
1244
|
+
property.previousValues.set(indexed.encodedKey, value);
|
|
1245
|
+
};
|
|
1246
|
+
const addKey = (index, encodedKey) => {
|
|
1247
|
+
const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
|
|
1248
|
+
index.nextOrder += 1; // eslint-disable-line no-param-reassign
|
|
1249
|
+
index.keys.set(encodedKey, indexed);
|
|
1250
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1251
|
+
let keys = index.prefixes.get(prefix);
|
|
1252
|
+
if (!keys) {
|
|
1253
|
+
keys = new Map();
|
|
1254
|
+
index.prefixes.set(prefix, keys);
|
|
1255
|
+
}
|
|
1256
|
+
keys.set(encodedKey, indexed);
|
|
1257
|
+
});
|
|
1258
|
+
return indexed;
|
|
1259
|
+
};
|
|
1260
|
+
const getIndex = (data) => {
|
|
1261
|
+
let index = indexes.get(data);
|
|
1262
|
+
if (!index) {
|
|
1263
|
+
index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
|
|
1264
|
+
Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
|
|
1265
|
+
indexes.set(data, index);
|
|
1266
|
+
}
|
|
1267
|
+
return index;
|
|
1268
|
+
};
|
|
1269
|
+
const candidatesFor = (index, key) => {
|
|
1270
|
+
var _a, _b;
|
|
1271
|
+
const prefixes = prefixesFor(key);
|
|
1272
|
+
if (!prefixes.length)
|
|
1273
|
+
return index.keys.values();
|
|
1274
|
+
return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
|
|
1275
|
+
};
|
|
1276
|
+
/** @hidden */
|
|
1277
|
+
const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
|
|
1278
|
+
/** Update only an index that has already been used; writes alone need no index build. @hidden */
|
|
1279
|
+
const updateCacheIndex = (data, encodedKey) => {
|
|
1280
|
+
var _a;
|
|
1281
|
+
const index = indexes.get(data);
|
|
1282
|
+
if (!index)
|
|
1283
|
+
return;
|
|
1284
|
+
const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
|
|
1285
|
+
index.properties.forEach(property => {
|
|
1286
|
+
removePropertyValue(property, indexed);
|
|
1287
|
+
addPropertyValue(data, property, indexed);
|
|
1288
|
+
});
|
|
1289
|
+
};
|
|
1290
|
+
/** @hidden */
|
|
1291
|
+
const removeFromCacheIndex = (data, encodedKey) => {
|
|
1292
|
+
const index = indexes.get(data);
|
|
1293
|
+
const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
|
|
1294
|
+
if (!index || !indexed)
|
|
1295
|
+
return;
|
|
1296
|
+
index.properties.forEach(property => removePropertyValue(property, indexed));
|
|
1297
|
+
prefixesFor(indexed.key).forEach(prefix => {
|
|
1298
|
+
const keys = index.prefixes.get(prefix);
|
|
1299
|
+
keys.delete(encodedKey);
|
|
1300
|
+
if (!keys.size)
|
|
1301
|
+
index.prefixes.delete(prefix);
|
|
1302
|
+
});
|
|
1303
|
+
index.keys.delete(encodedKey);
|
|
1304
|
+
};
|
|
1305
|
+
/** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
|
|
1306
|
+
const getCacheEntriesByProperty = (data, prefix, property, value) => {
|
|
1307
|
+
var _a;
|
|
1308
|
+
const index = getIndex(data);
|
|
1309
|
+
const identity = JSON.stringify([prefix, property]);
|
|
1310
|
+
let propertyIndex = index.properties.get(identity);
|
|
1311
|
+
if (!propertyIndex) {
|
|
1312
|
+
propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
|
|
1313
|
+
index.properties.set(identity, propertyIndex);
|
|
1314
|
+
Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
|
|
1315
|
+
}
|
|
1316
|
+
return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
|
|
1317
|
+
.sort((a, b) => a.order - b.order)
|
|
1318
|
+
.map(({ encodedKey }) => data[encodedKey]);
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1208
1321
|
/**
|
|
1209
1322
|
* ```js
|
|
1210
1323
|
* import { queryCache } from '@amityco/ts-sdk-react-native'
|
|
@@ -1225,12 +1338,7 @@ const queryCache = (key) => {
|
|
|
1225
1338
|
if (!cache)
|
|
1226
1339
|
return;
|
|
1227
1340
|
log('cache/api/queryCache', { key });
|
|
1228
|
-
return
|
|
1229
|
-
.filter(stringKey => {
|
|
1230
|
-
const decodedKey = decodeKey(stringKey);
|
|
1231
|
-
return partialMatch(key, decodedKey);
|
|
1232
|
-
})
|
|
1233
|
-
.map(stringKey => cache.data[stringKey]);
|
|
1341
|
+
return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
|
|
1234
1342
|
};
|
|
1235
1343
|
|
|
1236
1344
|
/**
|
|
@@ -1286,6 +1394,7 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
1286
1394
|
}
|
|
1287
1395
|
const encodedKey = encodeKey(key);
|
|
1288
1396
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
1397
|
+
updateCacheIndex(cache.data, encodedKey);
|
|
1289
1398
|
return true;
|
|
1290
1399
|
};
|
|
1291
1400
|
|
|
@@ -1370,15 +1479,14 @@ const dropFromCache = (key, exact = false) => {
|
|
|
1370
1479
|
return false;
|
|
1371
1480
|
log('cache/api/dropFromCache', { key, exact });
|
|
1372
1481
|
if (!exact) {
|
|
1373
|
-
return
|
|
1374
|
-
.map(
|
|
1375
|
-
.filter(candidate => partialMatch(key, candidate))
|
|
1376
|
-
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
1482
|
+
return getMatchingCacheKeys(cache.data, key)
|
|
1483
|
+
.map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
|
|
1377
1484
|
.every(returned => returned);
|
|
1378
1485
|
}
|
|
1379
1486
|
const encodedKey = encodeKey(key);
|
|
1380
1487
|
if (encodedKey in cache.data) {
|
|
1381
1488
|
delete cache.data[encodedKey];
|
|
1489
|
+
removeFromCacheIndex(cache.data, encodedKey);
|
|
1382
1490
|
return true;
|
|
1383
1491
|
}
|
|
1384
1492
|
return false;
|
|
@@ -3804,13 +3912,20 @@ const getUserMarker = async () => {
|
|
|
3804
3912
|
return { data: latestUserMarker, cachedAt };
|
|
3805
3913
|
};
|
|
3806
3914
|
|
|
3915
|
+
/** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
|
|
3916
|
+
const queryCacheByProperty = (prefix, property, value) => {
|
|
3917
|
+
const { cache } = getActiveClient();
|
|
3918
|
+
if (!cache)
|
|
3919
|
+
return;
|
|
3920
|
+
return getCacheEntriesByProperty(cache.data, prefix, property, value);
|
|
3921
|
+
};
|
|
3922
|
+
|
|
3807
3923
|
const getMessageFromMainDB = (messageId) => {
|
|
3808
|
-
var _a, _b;
|
|
3924
|
+
var _a, _b, _c;
|
|
3809
3925
|
const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3810
3926
|
if (message)
|
|
3811
3927
|
return message;
|
|
3812
|
-
|
|
3813
|
-
return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
3928
|
+
return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
|
|
3814
3929
|
};
|
|
3815
3930
|
|
|
3816
3931
|
/** @hidden */
|
|
@@ -3952,7 +4067,8 @@ function convertFromRaw$2(_a) {
|
|
|
3952
4067
|
|
|
3953
4068
|
const mergePayloadWithLocal = (payload) => {
|
|
3954
4069
|
var _a, _b, _c;
|
|
3955
|
-
|
|
4070
|
+
// Cache keys may be local referenceIds even after a server messageId is assigned.
|
|
4071
|
+
const localMessage = (_b = (_a = queryCacheByProperty(['message', 'get'], 'messageId', payload.messageId)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data;
|
|
3956
4072
|
if (localMessage) {
|
|
3957
4073
|
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
3958
4074
|
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
@@ -5519,9 +5635,9 @@ const channelLinkedObject = (channel) => {
|
|
|
5519
5635
|
var _a;
|
|
5520
5636
|
let previewMembers = [];
|
|
5521
5637
|
if (['conversation', 'community'].includes(channel.type)) {
|
|
5522
|
-
const channelUsers =
|
|
5638
|
+
const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
|
|
5523
5639
|
if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
|
|
5524
|
-
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.
|
|
5640
|
+
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
|
|
5525
5641
|
// sort in ascending order by userInternalId
|
|
5526
5642
|
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
5527
5643
|
// Select only first 4 members
|
|
@@ -17668,12 +17784,13 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
17668
17784
|
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
17669
17785
|
* @param onProgress The callback to track the upload progress
|
|
17670
17786
|
* @param altText The alt text for the image
|
|
17787
|
+
* @param isFullImage Keeps the original image so `size=full` returns it instead of the large copy
|
|
17671
17788
|
* @returns The newly created {@link Amity.File<'image'>}
|
|
17672
17789
|
*
|
|
17673
17790
|
* @category File API
|
|
17674
17791
|
* @async
|
|
17675
17792
|
*/
|
|
17676
|
-
const uploadImage = async (formData, onProgress, altText) => {
|
|
17793
|
+
const uploadImage = async (formData, onProgress, altText, isFullImage) => {
|
|
17677
17794
|
const client = getActiveClient();
|
|
17678
17795
|
client.log('file/uploadImage', formData);
|
|
17679
17796
|
const files = formData.getAll('files');
|
|
@@ -17694,6 +17811,10 @@ const uploadImage = async (formData, onProgress, altText) => {
|
|
|
17694
17811
|
}
|
|
17695
17812
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
17696
17813
|
formData.append('accessType', accessType);
|
|
17814
|
+
// skip if the caller already appended it, so the old FormData workaround keeps working
|
|
17815
|
+
if (isFullImage && !formData.getAll('fullImage').length) {
|
|
17816
|
+
formData.append('fullImage', 'true');
|
|
17817
|
+
}
|
|
17697
17818
|
const headers = 'getHeaders' in formData
|
|
17698
17819
|
? formData.getHeaders()
|
|
17699
17820
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -27900,8 +28021,40 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
27900
28021
|
};
|
|
27901
28022
|
};
|
|
27902
28023
|
|
|
28024
|
+
const GIF_OPTIONAL_KEYS = ['width', 'height'];
|
|
28025
|
+
/*
|
|
28026
|
+
* The server refuses a GIF attachment that carries `null` or any key it does not know, so the
|
|
28027
|
+
* request keeps `type`, `url` and only the optional fields that have a value. The SDK does not
|
|
28028
|
+
* check the values themselves: the server answers 400 for a bad one.
|
|
28029
|
+
*/
|
|
28030
|
+
const toGifAttachmentPayload = (gif) => {
|
|
28031
|
+
const payload = { type: 'gif', url: gif.url };
|
|
28032
|
+
GIF_OPTIONAL_KEYS.forEach(key => {
|
|
28033
|
+
const value = gif[key];
|
|
28034
|
+
if (value !== undefined && value !== null)
|
|
28035
|
+
Object.assign(payload, { [key]: value });
|
|
28036
|
+
});
|
|
28037
|
+
return payload;
|
|
28038
|
+
};
|
|
28039
|
+
/* Builds each GIF from its known keys; every other attachment is sent as the caller gave it. */
|
|
28040
|
+
const toAttachmentsPayload = (attachments) => attachments.map(attachment => attachment.type === 'gif'
|
|
28041
|
+
? toGifAttachmentPayload(attachment)
|
|
28042
|
+
: attachment);
|
|
28043
|
+
|
|
28044
|
+
/*
|
|
28045
|
+
* The data types the server lists for a comment, known before it answers: one per attachment
|
|
28046
|
+
* type, plus `text` when there is text. Sorted, as the server sorts them.
|
|
28047
|
+
*/
|
|
28048
|
+
const commentDataTypesOf = (text, attachments) => {
|
|
28049
|
+
const types = new Set((attachments !== null && attachments !== void 0 ? attachments : []).map(attachment => attachment.type));
|
|
28050
|
+
if (text)
|
|
28051
|
+
types.add('text');
|
|
28052
|
+
return [...types].sort();
|
|
28053
|
+
};
|
|
28054
|
+
|
|
27903
28055
|
const getLocalCommentId = () => uuid();
|
|
27904
28056
|
const createCommentOptimistic = (bundle) => {
|
|
28057
|
+
var _a;
|
|
27905
28058
|
const client = getActiveClient();
|
|
27906
28059
|
if (!client.cache)
|
|
27907
28060
|
return;
|
|
@@ -27936,6 +28089,7 @@ const createCommentOptimistic = (bundle) => {
|
|
|
27936
28089
|
targetId: '',
|
|
27937
28090
|
targetType: 'community',
|
|
27938
28091
|
dataType: 'text',
|
|
28092
|
+
dataTypes: commentDataTypesOf((_a = bundle.data) === null || _a === void 0 ? void 0 : _a.text, bundle.attachments),
|
|
27939
28093
|
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
27940
28094
|
// In a gated community the optimistic object stays out of public collections until the
|
|
27941
28095
|
// response settles the status; the author's own view still updates through the local event
|
|
@@ -27982,12 +28136,15 @@ const createCommentOptimistic = (bundle) => {
|
|
|
27982
28136
|
const createComment = async (bundle, isOptimistic = true) => {
|
|
27983
28137
|
const client = getActiveClient();
|
|
27984
28138
|
client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
|
|
28139
|
+
// A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
|
|
28140
|
+
const request = bundle.attachments
|
|
28141
|
+
? Object.assign(Object.assign({}, bundle), { attachments: toAttachmentsPayload(bundle.attachments) }) : bundle;
|
|
27985
28142
|
// Without a local comment the server assigns the id; with one, the same id travels through the
|
|
27986
28143
|
// optimistic object, the response and every realtime event so each step recognises it.
|
|
27987
|
-
const optimisticData = isOptimistic ? createCommentOptimistic(
|
|
28144
|
+
const optimisticData = isOptimistic ? createCommentOptimistic(request) : undefined;
|
|
27988
28145
|
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
27989
28146
|
try {
|
|
27990
|
-
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({},
|
|
28147
|
+
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, request), { commentId }));
|
|
27991
28148
|
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
27992
28149
|
if (payload.comments.length === 0)
|
|
27993
28150
|
throw new Error('Comment not created');
|
|
@@ -28080,9 +28237,16 @@ const createComment = async (bundle, isOptimistic = true) => {
|
|
|
28080
28237
|
* const updated = await CommentRepository.updateComment(commentId, {
|
|
28081
28238
|
* data: { text: 'hello world' }
|
|
28082
28239
|
* })
|
|
28240
|
+
*
|
|
28241
|
+
* // Replace the GIF, or remove it and keep the text
|
|
28242
|
+
* await CommentRepository.updateComment(commentId, {
|
|
28243
|
+
* attachments: [{ type: 'gif', url: 'https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif' }],
|
|
28244
|
+
* })
|
|
28245
|
+
* await CommentRepository.updateComment(commentId, { attachments: [] })
|
|
28083
28246
|
* ```
|
|
28084
28247
|
*
|
|
28085
|
-
* Updates an {@link Amity.Comment}
|
|
28248
|
+
* Updates an {@link Amity.Comment}. `attachments` replaces the current ones, `[]` removes them,
|
|
28249
|
+
* and leaving `attachments` out keeps them as they are.
|
|
28086
28250
|
*
|
|
28087
28251
|
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
28088
28252
|
* @param patch The patch data to apply
|
|
@@ -28096,7 +28260,10 @@ const updateComment = async (commentId, patch) => {
|
|
|
28096
28260
|
const client = getActiveClient();
|
|
28097
28261
|
client.log('user/updateComment', patch);
|
|
28098
28262
|
const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28099
|
-
|
|
28263
|
+
// A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
|
|
28264
|
+
const body = patch.attachments
|
|
28265
|
+
? Object.assign(Object.assign({}, patch), { attachments: toAttachmentsPayload(patch.attachments) }) : patch;
|
|
28266
|
+
const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, body);
|
|
28100
28267
|
const data = prepareCommentPayload(payload);
|
|
28101
28268
|
const updated = data.comments.find(comment => comment.commentId === commentId);
|
|
28102
28269
|
const cachedAt = client.cache && Date.now();
|
|
@@ -30563,6 +30730,19 @@ getPostByIds.locally = (postIds) => {
|
|
|
30563
30730
|
};
|
|
30564
30731
|
};
|
|
30565
30732
|
|
|
30733
|
+
/*
|
|
30734
|
+
* The `attachments` a post create or edit sends. A GIF goes with its known keys only and never
|
|
30735
|
+
* with product tags (both a 400). A file takes its product tags from the map, as before.
|
|
30736
|
+
*/
|
|
30737
|
+
const preparePostAttachments = (attachments, attachmentProductTags) => attachments === null || attachments === void 0 ? void 0 : attachments.map(attachment => {
|
|
30738
|
+
if (attachment.type === 'gif') {
|
|
30739
|
+
return toGifAttachmentPayload(attachment);
|
|
30740
|
+
}
|
|
30741
|
+
if (!attachmentProductTags || !attachment.fileId)
|
|
30742
|
+
return attachment;
|
|
30743
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachmentProductTags.get(attachment.fileId) });
|
|
30744
|
+
});
|
|
30745
|
+
|
|
30566
30746
|
/* begin_public_function
|
|
30567
30747
|
id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
|
|
30568
30748
|
*/
|
|
@@ -30592,17 +30772,7 @@ const createPost = async (bundle) => {
|
|
|
30592
30772
|
delete bundle.dataType;
|
|
30593
30773
|
}
|
|
30594
30774
|
const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
|
|
30595
|
-
const processedAttachments = attachments
|
|
30596
|
-
? attachments.map(attachment => {
|
|
30597
|
-
var _a;
|
|
30598
|
-
/* c8 ignore next */
|
|
30599
|
-
const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
30600
|
-
if (productTags)
|
|
30601
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
30602
|
-
/* c8 ignore next */
|
|
30603
|
-
return attachment;
|
|
30604
|
-
})
|
|
30605
|
-
: attachments;
|
|
30775
|
+
const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
|
|
30606
30776
|
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
30607
30777
|
fireEvent('post.created', payload);
|
|
30608
30778
|
const data = preparePostPayload(payload);
|
|
@@ -30628,7 +30798,9 @@ const createPost = async (bundle) => {
|
|
|
30628
30798
|
* })
|
|
30629
30799
|
* ```
|
|
30630
30800
|
*
|
|
30631
|
-
* Updates an {@link Amity.Post}
|
|
30801
|
+
* Updates an {@link Amity.Post}. `attachments` is the full list to keep: a GIF is matched by its
|
|
30802
|
+
* `url`, so send each kept GIF back with its link and size as read from `childrenPosts`; an
|
|
30803
|
+
* attachment left out is deleted, `[]` removes them all, and leaving `attachments` out keeps them.
|
|
30632
30804
|
*
|
|
30633
30805
|
* @param postId The ID of the {@link Amity.Post} to edit
|
|
30634
30806
|
* @param patch The patch data to apply
|
|
@@ -30641,17 +30813,7 @@ const editPost = async (postId, patch) => {
|
|
|
30641
30813
|
const client = getActiveClient();
|
|
30642
30814
|
client.log('user/editPost', patch);
|
|
30643
30815
|
const { attachments } = patch;
|
|
30644
|
-
const processedAttachments = attachments
|
|
30645
|
-
? attachments.map(attachment => {
|
|
30646
|
-
var _a;
|
|
30647
|
-
/* c8 ignore next */
|
|
30648
|
-
const productTags = (_a = patch.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
30649
|
-
if (productTags)
|
|
30650
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
30651
|
-
/* c8 ignore next */
|
|
30652
|
-
return attachment;
|
|
30653
|
-
})
|
|
30654
|
-
: attachments;
|
|
30816
|
+
const processedAttachments = preparePostAttachments(attachments, patch.attachmentProductTags);
|
|
30655
30817
|
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
30656
30818
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30657
30819
|
const cachedAt = client.cache && Date.now();
|
|
@@ -31135,11 +31297,14 @@ const createAudioPost = async (bundle) => {
|
|
|
31135
31297
|
* { fileId: "file1", type: "image" },
|
|
31136
31298
|
* { fileId: "file2", type: "video" },
|
|
31137
31299
|
* { fileId: "file3", type: "audio" },
|
|
31138
|
-
* { fileId: "file4", type: "file" }
|
|
31300
|
+
* { fileId: "file4", type: "file" },
|
|
31301
|
+
* { type: "gif", url: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif", width: 480, height: 270 }
|
|
31139
31302
|
* ],
|
|
31140
31303
|
* })
|
|
31141
31304
|
* ```
|
|
31142
31305
|
*
|
|
31306
|
+
* A post holds 1 to 10 attachments. A GIF is a link, not a file, and takes no product tags.
|
|
31307
|
+
*
|
|
31143
31308
|
* Creates an {@link Amity.Post}
|
|
31144
31309
|
*
|
|
31145
31310
|
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
@@ -31153,17 +31318,7 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
31153
31318
|
const client = getActiveClient();
|
|
31154
31319
|
client.log('post/createMixedMediaPost', bundle);
|
|
31155
31320
|
const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
|
|
31156
|
-
const processedAttachments = attachments
|
|
31157
|
-
? attachments.map(attachment => {
|
|
31158
|
-
var _a;
|
|
31159
|
-
/* c8 ignore next */
|
|
31160
|
-
const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
31161
|
-
if (productTags)
|
|
31162
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
31163
|
-
/* c8 ignore next */
|
|
31164
|
-
return attachment;
|
|
31165
|
-
})
|
|
31166
|
-
: /* c8 ignore next */ attachments;
|
|
31321
|
+
const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
|
|
31167
31322
|
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
31168
31323
|
fireEvent('post.created', payload);
|
|
31169
31324
|
const data = preparePostPayload(payload);
|
|
@@ -31680,6 +31835,10 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
31680
31835
|
*
|
|
31681
31836
|
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
31682
31837
|
*
|
|
31838
|
+
* GIF posts come back on every API version. This query is on v5, so `dataTypes: ['gif']` filters
|
|
31839
|
+
* them; a post with GIFs beside other media is `mixed` and is hidden unless
|
|
31840
|
+
* `includeMixedStructure` is `true`.
|
|
31841
|
+
*
|
|
31683
31842
|
* @param params.targetType the type of the target
|
|
31684
31843
|
* @param params.targetId the ID of the target
|
|
31685
31844
|
* @param callback the function to call when new data are available
|