@amityco/ts-sdk-react-native 7.32.1-52b2a8b.0 → 7.33.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/index.cjs.js +212 -58
- package/dist/index.esm.js +212 -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
|
|
@@ -14182,7 +14298,7 @@ const getWatchSessionStorage = () => {
|
|
|
14182
14298
|
return storageInstance;
|
|
14183
14299
|
};
|
|
14184
14300
|
|
|
14185
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
14301
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
14186
14302
|
/*
|
|
14187
14303
|
* The crypto algorithm used for importing key and signing string
|
|
14188
14304
|
*/
|
|
@@ -27900,8 +28016,40 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
27900
28016
|
};
|
|
27901
28017
|
};
|
|
27902
28018
|
|
|
28019
|
+
const GIF_OPTIONAL_KEYS = ['width', 'height'];
|
|
28020
|
+
/*
|
|
28021
|
+
* The server refuses a GIF attachment that carries `null` or any key it does not know, so the
|
|
28022
|
+
* request keeps `type`, `url` and only the optional fields that have a value. The SDK does not
|
|
28023
|
+
* check the values themselves: the server answers 400 for a bad one.
|
|
28024
|
+
*/
|
|
28025
|
+
const toGifAttachmentPayload = (gif) => {
|
|
28026
|
+
const payload = { type: 'gif', url: gif.url };
|
|
28027
|
+
GIF_OPTIONAL_KEYS.forEach(key => {
|
|
28028
|
+
const value = gif[key];
|
|
28029
|
+
if (value !== undefined && value !== null)
|
|
28030
|
+
Object.assign(payload, { [key]: value });
|
|
28031
|
+
});
|
|
28032
|
+
return payload;
|
|
28033
|
+
};
|
|
28034
|
+
/* Builds each GIF from its known keys; every other attachment is sent as the caller gave it. */
|
|
28035
|
+
const toAttachmentsPayload = (attachments) => attachments.map(attachment => attachment.type === 'gif'
|
|
28036
|
+
? toGifAttachmentPayload(attachment)
|
|
28037
|
+
: attachment);
|
|
28038
|
+
|
|
28039
|
+
/*
|
|
28040
|
+
* The data types the server lists for a comment, known before it answers: one per attachment
|
|
28041
|
+
* type, plus `text` when there is text. Sorted, as the server sorts them.
|
|
28042
|
+
*/
|
|
28043
|
+
const commentDataTypesOf = (text, attachments) => {
|
|
28044
|
+
const types = new Set((attachments !== null && attachments !== void 0 ? attachments : []).map(attachment => attachment.type));
|
|
28045
|
+
if (text)
|
|
28046
|
+
types.add('text');
|
|
28047
|
+
return [...types].sort();
|
|
28048
|
+
};
|
|
28049
|
+
|
|
27903
28050
|
const getLocalCommentId = () => uuid();
|
|
27904
28051
|
const createCommentOptimistic = (bundle) => {
|
|
28052
|
+
var _a;
|
|
27905
28053
|
const client = getActiveClient();
|
|
27906
28054
|
if (!client.cache)
|
|
27907
28055
|
return;
|
|
@@ -27936,6 +28084,7 @@ const createCommentOptimistic = (bundle) => {
|
|
|
27936
28084
|
targetId: '',
|
|
27937
28085
|
targetType: 'community',
|
|
27938
28086
|
dataType: 'text',
|
|
28087
|
+
dataTypes: commentDataTypesOf((_a = bundle.data) === null || _a === void 0 ? void 0 : _a.text, bundle.attachments),
|
|
27939
28088
|
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
27940
28089
|
// In a gated community the optimistic object stays out of public collections until the
|
|
27941
28090
|
// response settles the status; the author's own view still updates through the local event
|
|
@@ -27982,12 +28131,15 @@ const createCommentOptimistic = (bundle) => {
|
|
|
27982
28131
|
const createComment = async (bundle, isOptimistic = true) => {
|
|
27983
28132
|
const client = getActiveClient();
|
|
27984
28133
|
client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
|
|
28134
|
+
// A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
|
|
28135
|
+
const request = bundle.attachments
|
|
28136
|
+
? Object.assign(Object.assign({}, bundle), { attachments: toAttachmentsPayload(bundle.attachments) }) : bundle;
|
|
27985
28137
|
// Without a local comment the server assigns the id; with one, the same id travels through the
|
|
27986
28138
|
// optimistic object, the response and every realtime event so each step recognises it.
|
|
27987
|
-
const optimisticData = isOptimistic ? createCommentOptimistic(
|
|
28139
|
+
const optimisticData = isOptimistic ? createCommentOptimistic(request) : undefined;
|
|
27988
28140
|
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
27989
28141
|
try {
|
|
27990
|
-
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({},
|
|
28142
|
+
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, request), { commentId }));
|
|
27991
28143
|
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
27992
28144
|
if (payload.comments.length === 0)
|
|
27993
28145
|
throw new Error('Comment not created');
|
|
@@ -28080,9 +28232,16 @@ const createComment = async (bundle, isOptimistic = true) => {
|
|
|
28080
28232
|
* const updated = await CommentRepository.updateComment(commentId, {
|
|
28081
28233
|
* data: { text: 'hello world' }
|
|
28082
28234
|
* })
|
|
28235
|
+
*
|
|
28236
|
+
* // Replace the GIF, or remove it and keep the text
|
|
28237
|
+
* await CommentRepository.updateComment(commentId, {
|
|
28238
|
+
* attachments: [{ type: 'gif', url: 'https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif' }],
|
|
28239
|
+
* })
|
|
28240
|
+
* await CommentRepository.updateComment(commentId, { attachments: [] })
|
|
28083
28241
|
* ```
|
|
28084
28242
|
*
|
|
28085
|
-
* Updates an {@link Amity.Comment}
|
|
28243
|
+
* Updates an {@link Amity.Comment}. `attachments` replaces the current ones, `[]` removes them,
|
|
28244
|
+
* and leaving `attachments` out keeps them as they are.
|
|
28086
28245
|
*
|
|
28087
28246
|
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
28088
28247
|
* @param patch The patch data to apply
|
|
@@ -28096,7 +28255,10 @@ const updateComment = async (commentId, patch) => {
|
|
|
28096
28255
|
const client = getActiveClient();
|
|
28097
28256
|
client.log('user/updateComment', patch);
|
|
28098
28257
|
const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28099
|
-
|
|
28258
|
+
// A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
|
|
28259
|
+
const body = patch.attachments
|
|
28260
|
+
? Object.assign(Object.assign({}, patch), { attachments: toAttachmentsPayload(patch.attachments) }) : patch;
|
|
28261
|
+
const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, body);
|
|
28100
28262
|
const data = prepareCommentPayload(payload);
|
|
28101
28263
|
const updated = data.comments.find(comment => comment.commentId === commentId);
|
|
28102
28264
|
const cachedAt = client.cache && Date.now();
|
|
@@ -30563,6 +30725,19 @@ getPostByIds.locally = (postIds) => {
|
|
|
30563
30725
|
};
|
|
30564
30726
|
};
|
|
30565
30727
|
|
|
30728
|
+
/*
|
|
30729
|
+
* The `attachments` a post create or edit sends. A GIF goes with its known keys only and never
|
|
30730
|
+
* with product tags (both a 400). A file takes its product tags from the map, as before.
|
|
30731
|
+
*/
|
|
30732
|
+
const preparePostAttachments = (attachments, attachmentProductTags) => attachments === null || attachments === void 0 ? void 0 : attachments.map(attachment => {
|
|
30733
|
+
if (attachment.type === 'gif') {
|
|
30734
|
+
return toGifAttachmentPayload(attachment);
|
|
30735
|
+
}
|
|
30736
|
+
if (!attachmentProductTags || !attachment.fileId)
|
|
30737
|
+
return attachment;
|
|
30738
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachmentProductTags.get(attachment.fileId) });
|
|
30739
|
+
});
|
|
30740
|
+
|
|
30566
30741
|
/* begin_public_function
|
|
30567
30742
|
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
30743
|
*/
|
|
@@ -30592,17 +30767,7 @@ const createPost = async (bundle) => {
|
|
|
30592
30767
|
delete bundle.dataType;
|
|
30593
30768
|
}
|
|
30594
30769
|
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;
|
|
30770
|
+
const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
|
|
30606
30771
|
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
30607
30772
|
fireEvent('post.created', payload);
|
|
30608
30773
|
const data = preparePostPayload(payload);
|
|
@@ -30628,7 +30793,9 @@ const createPost = async (bundle) => {
|
|
|
30628
30793
|
* })
|
|
30629
30794
|
* ```
|
|
30630
30795
|
*
|
|
30631
|
-
* Updates an {@link Amity.Post}
|
|
30796
|
+
* Updates an {@link Amity.Post}. `attachments` is the full list to keep: a GIF is matched by its
|
|
30797
|
+
* `url`, so send each kept GIF back with its link and size as read from `childrenPosts`; an
|
|
30798
|
+
* attachment left out is deleted, `[]` removes them all, and leaving `attachments` out keeps them.
|
|
30632
30799
|
*
|
|
30633
30800
|
* @param postId The ID of the {@link Amity.Post} to edit
|
|
30634
30801
|
* @param patch The patch data to apply
|
|
@@ -30641,17 +30808,7 @@ const editPost = async (postId, patch) => {
|
|
|
30641
30808
|
const client = getActiveClient();
|
|
30642
30809
|
client.log('user/editPost', patch);
|
|
30643
30810
|
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;
|
|
30811
|
+
const processedAttachments = preparePostAttachments(attachments, patch.attachmentProductTags);
|
|
30655
30812
|
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
30656
30813
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30657
30814
|
const cachedAt = client.cache && Date.now();
|
|
@@ -31135,11 +31292,14 @@ const createAudioPost = async (bundle) => {
|
|
|
31135
31292
|
* { fileId: "file1", type: "image" },
|
|
31136
31293
|
* { fileId: "file2", type: "video" },
|
|
31137
31294
|
* { fileId: "file3", type: "audio" },
|
|
31138
|
-
* { fileId: "file4", type: "file" }
|
|
31295
|
+
* { fileId: "file4", type: "file" },
|
|
31296
|
+
* { type: "gif", url: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif", width: 480, height: 270 }
|
|
31139
31297
|
* ],
|
|
31140
31298
|
* })
|
|
31141
31299
|
* ```
|
|
31142
31300
|
*
|
|
31301
|
+
* A post holds 1 to 10 attachments. A GIF is a link, not a file, and takes no product tags.
|
|
31302
|
+
*
|
|
31143
31303
|
* Creates an {@link Amity.Post}
|
|
31144
31304
|
*
|
|
31145
31305
|
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
@@ -31153,17 +31313,7 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
31153
31313
|
const client = getActiveClient();
|
|
31154
31314
|
client.log('post/createMixedMediaPost', bundle);
|
|
31155
31315
|
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;
|
|
31316
|
+
const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
|
|
31167
31317
|
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
31168
31318
|
fireEvent('post.created', payload);
|
|
31169
31319
|
const data = preparePostPayload(payload);
|
|
@@ -31680,6 +31830,10 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
31680
31830
|
*
|
|
31681
31831
|
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
31682
31832
|
*
|
|
31833
|
+
* GIF posts come back on every API version. This query is on v5, so `dataTypes: ['gif']` filters
|
|
31834
|
+
* them; a post with GIFs beside other media is `mixed` and is hidden unless
|
|
31835
|
+
* `includeMixedStructure` is `true`.
|
|
31836
|
+
*
|
|
31683
31837
|
* @param params.targetType the type of the target
|
|
31684
31838
|
* @param params.targetId the ID of the target
|
|
31685
31839
|
* @param callback the function to call when new data are available
|