@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.
Files changed (58) hide show
  1. package/dist/@types/domains/comment.d.ts +2 -2
  2. package/dist/@types/domains/comment.d.ts.map +1 -1
  3. package/dist/@types/domains/content.d.ts +23 -3
  4. package/dist/@types/domains/content.d.ts.map +1 -1
  5. package/dist/@types/domains/feed.d.ts +4 -1
  6. package/dist/@types/domains/feed.d.ts.map +1 -1
  7. package/dist/@types/domains/post.d.ts +11 -0
  8. package/dist/@types/domains/post.d.ts.map +1 -1
  9. package/dist/cache/api/dropFromCache.d.ts.map +1 -1
  10. package/dist/cache/api/pushToCache.d.ts.map +1 -1
  11. package/dist/cache/api/queryCache.d.ts.map +1 -1
  12. package/dist/cache/api/queryCacheByProperty.d.ts +3 -0
  13. package/dist/cache/api/queryCacheByProperty.d.ts.map +1 -0
  14. package/dist/cache/api/tests/queryCache.test.d.ts +2 -0
  15. package/dist/cache/api/tests/queryCache.test.d.ts.map +1 -0
  16. package/dist/cache/utils/cacheIndex.d.ts +15 -0
  17. package/dist/cache/utils/cacheIndex.d.ts.map +1 -0
  18. package/dist/commentRepository/api/createComment.d.ts +1 -1
  19. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  20. package/dist/commentRepository/api/tests/createComment.gif.test.d.ts +2 -0
  21. package/dist/commentRepository/api/tests/createComment.gif.test.d.ts.map +1 -0
  22. package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts +2 -0
  23. package/dist/commentRepository/api/tests/deleteComment.gif.test.d.ts.map +1 -0
  24. package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts +2 -0
  25. package/dist/commentRepository/api/tests/updateComment.gif.test.d.ts.map +1 -0
  26. package/dist/commentRepository/api/updateComment.d.ts +9 -2
  27. package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
  28. package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts +2 -0
  29. package/dist/commentRepository/observers/tests/getComments.gif.test.d.ts.map +1 -0
  30. package/dist/commentRepository/utils/dataTypes.d.ts +2 -0
  31. package/dist/commentRepository/utils/dataTypes.d.ts.map +1 -0
  32. package/dist/index.cjs.js +212 -58
  33. package/dist/index.esm.js +212 -58
  34. package/dist/index.umd.js +1 -1
  35. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  36. package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
  37. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  38. package/dist/postRepository/api/createMixedMediaPost.d.ts +6 -6
  39. package/dist/postRepository/api/createMixedMediaPost.d.ts.map +1 -1
  40. package/dist/postRepository/api/createPost.d.ts +1 -4
  41. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  42. package/dist/postRepository/api/editPost.d.ts +4 -5
  43. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  44. package/dist/postRepository/api/tests/gifPost.test.d.ts +2 -0
  45. package/dist/postRepository/api/tests/gifPost.test.d.ts.map +1 -0
  46. package/dist/postRepository/observers/getPosts.d.ts +4 -0
  47. package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
  48. package/dist/postRepository/utils/attachments.d.ts +8 -0
  49. package/dist/postRepository/utils/attachments.d.ts.map +1 -0
  50. package/dist/utils/gifAttachment.d.ts +5 -0
  51. package/dist/utils/gifAttachment.d.ts.map +1 -0
  52. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  53. package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts +2 -0
  54. package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts.map +1 -0
  55. package/dist/utils/postTypePredicate.d.ts +1 -0
  56. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  57. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  58. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -179,6 +179,7 @@ const PostContentType = Object.freeze({
179
179
  AUDIO: 'audio',
180
180
  ROOM: 'room',
181
181
  EVENT: 'event',
182
+ GIF: 'gif',
182
183
  });
183
184
  const PostStructureType = Object.freeze({
184
185
  TEXT: 'text',
@@ -188,6 +189,8 @@ const PostStructureType = Object.freeze({
188
189
  AUDIO: 'audio',
189
190
  MIXED: 'mixed',
190
191
  EVENT: 'event',
192
+ /** A post that holds only GIFs. GIFs beside other media make the post `mixed`. */
193
+ GIF: 'gif',
191
194
  });
192
195
 
193
196
  var InvitationTypeEnum;
@@ -347,8 +350,8 @@ var AmityLiveViewerCountMode;
347
350
 
348
351
  function getVersion() {
349
352
  try {
350
- // the string ''v7.32.0-esm'' should be replaced by actual value by @rollup/plugin-replace
351
- return 'v7.32.0-esm';
353
+ // the string ''v7.33.0-esm'' should be replaced by actual value by @rollup/plugin-replace
354
+ return 'v7.33.0-esm';
352
355
  }
353
356
  catch (error) {
354
357
  return '__dev__';
@@ -1170,6 +1173,116 @@ const wipeCache = async (storageKey = 'amitySdk') => {
1170
1173
  return true;
1171
1174
  };
1172
1175
 
1176
+ // Indexes never enter persisted cache data. Replacing data (restore/wipe/enable) starts a new index.
1177
+ const indexes = new WeakMap();
1178
+ const prefixesFor = (key) => {
1179
+ if (typeof key[0] !== 'string')
1180
+ return [];
1181
+ const prefixes = [JSON.stringify([key[0]])];
1182
+ if (typeof key[1] === 'string')
1183
+ prefixes.push(JSON.stringify([key[0], key[1]]));
1184
+ return prefixes;
1185
+ };
1186
+ const removePropertyValue = (property, indexed) => {
1187
+ const previous = property.previousValues.get(indexed.encodedKey);
1188
+ if (previous === undefined)
1189
+ return;
1190
+ const matches = property.values.get(previous);
1191
+ matches.delete(indexed);
1192
+ if (!matches.size)
1193
+ property.values.delete(previous);
1194
+ property.previousValues.delete(indexed.encodedKey);
1195
+ };
1196
+ const addPropertyValue = (data, property, indexed) => {
1197
+ var _a;
1198
+ if (!partialMatch(property.prefix, indexed.key))
1199
+ return;
1200
+ const value = (_a = data[indexed.encodedKey].data) === null || _a === void 0 ? void 0 : _a[property.property];
1201
+ if (typeof value !== 'string')
1202
+ return;
1203
+ let matches = property.values.get(value);
1204
+ if (!matches) {
1205
+ matches = new Set();
1206
+ property.values.set(value, matches);
1207
+ }
1208
+ matches.add(indexed);
1209
+ property.previousValues.set(indexed.encodedKey, value);
1210
+ };
1211
+ const addKey = (index, encodedKey) => {
1212
+ const indexed = { encodedKey, key: decodeKey(encodedKey), order: index.nextOrder };
1213
+ index.nextOrder += 1; // eslint-disable-line no-param-reassign
1214
+ index.keys.set(encodedKey, indexed);
1215
+ prefixesFor(indexed.key).forEach(prefix => {
1216
+ let keys = index.prefixes.get(prefix);
1217
+ if (!keys) {
1218
+ keys = new Map();
1219
+ index.prefixes.set(prefix, keys);
1220
+ }
1221
+ keys.set(encodedKey, indexed);
1222
+ });
1223
+ return indexed;
1224
+ };
1225
+ const getIndex = (data) => {
1226
+ let index = indexes.get(data);
1227
+ if (!index) {
1228
+ index = { keys: new Map(), prefixes: new Map(), properties: new Map(), nextOrder: 0 };
1229
+ Object.keys(data).forEach(encodedKey => addKey(index, encodedKey));
1230
+ indexes.set(data, index);
1231
+ }
1232
+ return index;
1233
+ };
1234
+ const candidatesFor = (index, key) => {
1235
+ var _a, _b;
1236
+ const prefixes = prefixesFor(key);
1237
+ if (!prefixes.length)
1238
+ return index.keys.values();
1239
+ return (_b = (_a = index.prefixes.get(prefixes[prefixes.length - 1])) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [];
1240
+ };
1241
+ /** @hidden */
1242
+ const getMatchingCacheKeys = (data, key) => Array.from(candidatesFor(getIndex(data), key)).filter(indexed => partialMatch(key, indexed.key));
1243
+ /** Update only an index that has already been used; writes alone need no index build. @hidden */
1244
+ const updateCacheIndex = (data, encodedKey) => {
1245
+ var _a;
1246
+ const index = indexes.get(data);
1247
+ if (!index)
1248
+ return;
1249
+ const indexed = (_a = index.keys.get(encodedKey)) !== null && _a !== void 0 ? _a : addKey(index, encodedKey);
1250
+ index.properties.forEach(property => {
1251
+ removePropertyValue(property, indexed);
1252
+ addPropertyValue(data, property, indexed);
1253
+ });
1254
+ };
1255
+ /** @hidden */
1256
+ const removeFromCacheIndex = (data, encodedKey) => {
1257
+ const index = indexes.get(data);
1258
+ const indexed = index === null || index === void 0 ? void 0 : index.keys.get(encodedKey);
1259
+ if (!index || !indexed)
1260
+ return;
1261
+ index.properties.forEach(property => removePropertyValue(property, indexed));
1262
+ prefixesFor(indexed.key).forEach(prefix => {
1263
+ const keys = index.prefixes.get(prefix);
1264
+ keys.delete(encodedKey);
1265
+ if (!keys.size)
1266
+ index.prefixes.delete(prefix);
1267
+ });
1268
+ index.keys.delete(encodedKey);
1269
+ };
1270
+ /** Index a string model property within one domain/operation, retaining cache insertion order. @hidden */
1271
+ const getCacheEntriesByProperty = (data, prefix, property, value) => {
1272
+ var _a;
1273
+ const index = getIndex(data);
1274
+ const identity = JSON.stringify([prefix, property]);
1275
+ let propertyIndex = index.properties.get(identity);
1276
+ if (!propertyIndex) {
1277
+ propertyIndex = { prefix, property, values: new Map(), previousValues: new Map() };
1278
+ index.properties.set(identity, propertyIndex);
1279
+ Array.from(candidatesFor(index, prefix)).forEach(indexed => addPropertyValue(data, propertyIndex, indexed));
1280
+ }
1281
+ return Array.from((_a = propertyIndex.values.get(value)) !== null && _a !== void 0 ? _a : [])
1282
+ .sort((a, b) => a.order - b.order)
1283
+ .map(({ encodedKey }) => data[encodedKey]);
1284
+ };
1285
+
1173
1286
  /**
1174
1287
  * ```js
1175
1288
  * import { queryCache } from '@amityco/ts-sdk-react-native'
@@ -1190,12 +1303,7 @@ const queryCache = (key) => {
1190
1303
  if (!cache)
1191
1304
  return;
1192
1305
  log('cache/api/queryCache', { key });
1193
- return Object.keys(cache.data)
1194
- .filter(stringKey => {
1195
- const decodedKey = decodeKey(stringKey);
1196
- return partialMatch(key, decodedKey);
1197
- })
1198
- .map(stringKey => cache.data[stringKey]);
1306
+ return getMatchingCacheKeys(cache.data, key).map(({ encodedKey }) => cache.data[encodedKey]);
1199
1307
  };
1200
1308
 
1201
1309
  /**
@@ -1251,6 +1359,7 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
1251
1359
  }
1252
1360
  const encodedKey = encodeKey(key);
1253
1361
  cache.data[encodedKey] = Object.assign({ key, data }, options);
1362
+ updateCacheIndex(cache.data, encodedKey);
1254
1363
  return true;
1255
1364
  };
1256
1365
 
@@ -1335,15 +1444,14 @@ const dropFromCache = (key, exact = false) => {
1335
1444
  return false;
1336
1445
  log('cache/api/dropFromCache', { key, exact });
1337
1446
  if (!exact) {
1338
- return Object.keys(cache.data)
1339
- .map(stringKey => decodeKey(stringKey))
1340
- .filter(candidate => partialMatch(key, candidate))
1341
- .map(filteredKey => dropFromCache(filteredKey, true))
1447
+ return getMatchingCacheKeys(cache.data, key)
1448
+ .map(({ key: filteredKey }) => dropFromCache(filteredKey, true))
1342
1449
  .every(returned => returned);
1343
1450
  }
1344
1451
  const encodedKey = encodeKey(key);
1345
1452
  if (encodedKey in cache.data) {
1346
1453
  delete cache.data[encodedKey];
1454
+ removeFromCacheIndex(cache.data, encodedKey);
1347
1455
  return true;
1348
1456
  }
1349
1457
  return false;
@@ -3785,13 +3893,20 @@ const getUserMarker = async () => {
3785
3893
  return { data: latestUserMarker, cachedAt };
3786
3894
  };
3787
3895
 
3896
+ /** Internal model lookup; deliberately excluded from the public Cache API. @hidden */
3897
+ const queryCacheByProperty = (prefix, property, value) => {
3898
+ const { cache } = getActiveClient();
3899
+ if (!cache)
3900
+ return;
3901
+ return getCacheEntriesByProperty(cache.data, prefix, property, value);
3902
+ };
3903
+
3788
3904
  const getMessageFromMainDB = (messageId) => {
3789
- var _a, _b;
3905
+ var _a, _b, _c;
3790
3906
  const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
3791
3907
  if (message)
3792
3908
  return message;
3793
- const messages = queryCache(['message', 'get']);
3794
- return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
3909
+ return (_c = (_b = queryCacheByProperty(['message', 'get'], 'messageId', messageId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data;
3795
3910
  };
3796
3911
 
3797
3912
  /** @hidden */
@@ -3933,7 +4048,8 @@ function convertFromRaw$2(_a) {
3933
4048
 
3934
4049
  const mergePayloadWithLocal = (payload) => {
3935
4050
  var _a, _b, _c;
3936
- const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
4051
+ // Cache keys may be local referenceIds even after a server messageId is assigned.
4052
+ 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;
3937
4053
  if (localMessage) {
3938
4054
  return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
3939
4055
  // NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
@@ -5500,9 +5616,9 @@ const channelLinkedObject = (channel) => {
5500
5616
  var _a;
5501
5617
  let previewMembers = [];
5502
5618
  if (['conversation', 'community'].includes(channel.type)) {
5503
- const channelUsers = queryCache(['channelUsers', 'get']);
5619
+ const channelUsers = queryCacheByProperty(['channelUsers', 'get'], 'channelId', channel.channelId);
5504
5620
  if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
5505
- previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.channelId === channel.channelId && data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5621
+ previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.membership !== 'none')) !== null && _a !== void 0 ? _a : [])
5506
5622
  // sort in ascending order by userInternalId
5507
5623
  .sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
5508
5624
  // Select only first 4 members
@@ -14163,7 +14279,7 @@ const getWatchSessionStorage = () => {
14163
14279
  return storageInstance;
14164
14280
  };
14165
14281
 
14166
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
14282
+ 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-----";
14167
14283
  /*
14168
14284
  * The crypto algorithm used for importing key and signing string
14169
14285
  */
@@ -27881,8 +27997,40 @@ getCommentByIds.locally = (commentIds) => {
27881
27997
  };
27882
27998
  };
27883
27999
 
28000
+ const GIF_OPTIONAL_KEYS = ['width', 'height'];
28001
+ /*
28002
+ * The server refuses a GIF attachment that carries `null` or any key it does not know, so the
28003
+ * request keeps `type`, `url` and only the optional fields that have a value. The SDK does not
28004
+ * check the values themselves: the server answers 400 for a bad one.
28005
+ */
28006
+ const toGifAttachmentPayload = (gif) => {
28007
+ const payload = { type: 'gif', url: gif.url };
28008
+ GIF_OPTIONAL_KEYS.forEach(key => {
28009
+ const value = gif[key];
28010
+ if (value !== undefined && value !== null)
28011
+ Object.assign(payload, { [key]: value });
28012
+ });
28013
+ return payload;
28014
+ };
28015
+ /* Builds each GIF from its known keys; every other attachment is sent as the caller gave it. */
28016
+ const toAttachmentsPayload = (attachments) => attachments.map(attachment => attachment.type === 'gif'
28017
+ ? toGifAttachmentPayload(attachment)
28018
+ : attachment);
28019
+
28020
+ /*
28021
+ * The data types the server lists for a comment, known before it answers: one per attachment
28022
+ * type, plus `text` when there is text. Sorted, as the server sorts them.
28023
+ */
28024
+ const commentDataTypesOf = (text, attachments) => {
28025
+ const types = new Set((attachments !== null && attachments !== void 0 ? attachments : []).map(attachment => attachment.type));
28026
+ if (text)
28027
+ types.add('text');
28028
+ return [...types].sort();
28029
+ };
28030
+
27884
28031
  const getLocalCommentId = () => uuid();
27885
28032
  const createCommentOptimistic = (bundle) => {
28033
+ var _a;
27886
28034
  const client = getActiveClient();
27887
28035
  if (!client.cache)
27888
28036
  return;
@@ -27917,6 +28065,7 @@ const createCommentOptimistic = (bundle) => {
27917
28065
  targetId: '',
27918
28066
  targetType: 'community',
27919
28067
  dataType: 'text',
28068
+ dataTypes: commentDataTypesOf((_a = bundle.data) === null || _a === void 0 ? void 0 : _a.text, bundle.attachments),
27920
28069
  syncState: "syncing" /* Amity.SyncState.Syncing */,
27921
28070
  // In a gated community the optimistic object stays out of public collections until the
27922
28071
  // response settles the status; the author's own view still updates through the local event
@@ -27963,12 +28112,15 @@ const createCommentOptimistic = (bundle) => {
27963
28112
  const createComment = async (bundle, isOptimistic = true) => {
27964
28113
  const client = getActiveClient();
27965
28114
  client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
28115
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
28116
+ const request = bundle.attachments
28117
+ ? Object.assign(Object.assign({}, bundle), { attachments: toAttachmentsPayload(bundle.attachments) }) : bundle;
27966
28118
  // Without a local comment the server assigns the id; with one, the same id travels through the
27967
28119
  // optimistic object, the response and every realtime event so each step recognises it.
27968
- const optimisticData = isOptimistic ? createCommentOptimistic(bundle) : undefined;
28120
+ const optimisticData = isOptimistic ? createCommentOptimistic(request) : undefined;
27969
28121
  const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
27970
28122
  try {
27971
- const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
28123
+ const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, request), { commentId }));
27972
28124
  // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
27973
28125
  if (payload.comments.length === 0)
27974
28126
  throw new Error('Comment not created');
@@ -28061,9 +28213,16 @@ const createComment = async (bundle, isOptimistic = true) => {
28061
28213
  * const updated = await CommentRepository.updateComment(commentId, {
28062
28214
  * data: { text: 'hello world' }
28063
28215
  * })
28216
+ *
28217
+ * // Replace the GIF, or remove it and keep the text
28218
+ * await CommentRepository.updateComment(commentId, {
28219
+ * attachments: [{ type: 'gif', url: 'https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif' }],
28220
+ * })
28221
+ * await CommentRepository.updateComment(commentId, { attachments: [] })
28064
28222
  * ```
28065
28223
  *
28066
- * Updates an {@link Amity.Comment}
28224
+ * Updates an {@link Amity.Comment}. `attachments` replaces the current ones, `[]` removes them,
28225
+ * and leaving `attachments` out keeps them as they are.
28067
28226
  *
28068
28227
  * @param commentId The ID of the {@link Amity.Comment} to edit
28069
28228
  * @param patch The patch data to apply
@@ -28077,7 +28236,10 @@ const updateComment = async (commentId, patch) => {
28077
28236
  const client = getActiveClient();
28078
28237
  client.log('user/updateComment', patch);
28079
28238
  const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
28080
- const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
28239
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
28240
+ const body = patch.attachments
28241
+ ? Object.assign(Object.assign({}, patch), { attachments: toAttachmentsPayload(patch.attachments) }) : patch;
28242
+ const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, body);
28081
28243
  const data = prepareCommentPayload(payload);
28082
28244
  const updated = data.comments.find(comment => comment.commentId === commentId);
28083
28245
  const cachedAt = client.cache && Date.now();
@@ -30544,6 +30706,19 @@ getPostByIds.locally = (postIds) => {
30544
30706
  };
30545
30707
  };
30546
30708
 
30709
+ /*
30710
+ * The `attachments` a post create or edit sends. A GIF goes with its known keys only and never
30711
+ * with product tags (both a 400). A file takes its product tags from the map, as before.
30712
+ */
30713
+ const preparePostAttachments = (attachments, attachmentProductTags) => attachments === null || attachments === void 0 ? void 0 : attachments.map(attachment => {
30714
+ if (attachment.type === 'gif') {
30715
+ return toGifAttachmentPayload(attachment);
30716
+ }
30717
+ if (!attachmentProductTags || !attachment.fileId)
30718
+ return attachment;
30719
+ return Object.assign(Object.assign({}, attachment), { productTags: attachmentProductTags.get(attachment.fileId) });
30720
+ });
30721
+
30547
30722
  /* begin_public_function
30548
30723
  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
30549
30724
  */
@@ -30573,17 +30748,7 @@ const createPost = async (bundle) => {
30573
30748
  delete bundle.dataType;
30574
30749
  }
30575
30750
  const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
30576
- const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
30577
- ? attachments.map(attachment => {
30578
- var _a;
30579
- /* c8 ignore next */
30580
- const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
30581
- if (productTags)
30582
- return Object.assign(Object.assign({}, attachment), { productTags });
30583
- /* c8 ignore next */
30584
- return attachment;
30585
- })
30586
- : attachments;
30751
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
30587
30752
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
30588
30753
  fireEvent('post.created', payload);
30589
30754
  const data = preparePostPayload(payload);
@@ -30609,7 +30774,9 @@ const createPost = async (bundle) => {
30609
30774
  * })
30610
30775
  * ```
30611
30776
  *
30612
- * Updates an {@link Amity.Post}
30777
+ * Updates an {@link Amity.Post}. `attachments` is the full list to keep: a GIF is matched by its
30778
+ * `url`, so send each kept GIF back with its link and size as read from `childrenPosts`; an
30779
+ * attachment left out is deleted, `[]` removes them all, and leaving `attachments` out keeps them.
30613
30780
  *
30614
30781
  * @param postId The ID of the {@link Amity.Post} to edit
30615
30782
  * @param patch The patch data to apply
@@ -30622,17 +30789,7 @@ const editPost = async (postId, patch) => {
30622
30789
  const client = getActiveClient();
30623
30790
  client.log('user/editPost', patch);
30624
30791
  const { attachments } = patch;
30625
- const processedAttachments = attachments && attachments.length > 0 && patch.attachmentProductTags
30626
- ? attachments.map(attachment => {
30627
- var _a;
30628
- /* c8 ignore next */
30629
- const productTags = (_a = patch.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
30630
- if (productTags)
30631
- return Object.assign(Object.assign({}, attachment), { productTags });
30632
- /* c8 ignore next */
30633
- return attachment;
30634
- })
30635
- : attachments;
30792
+ const processedAttachments = preparePostAttachments(attachments, patch.attachmentProductTags);
30636
30793
  const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
30637
30794
  const data = prepareMembershipPayload(payload, 'communityUsers');
30638
30795
  const cachedAt = client.cache && Date.now();
@@ -31116,11 +31273,14 @@ const createAudioPost = async (bundle) => {
31116
31273
  * { fileId: "file1", type: "image" },
31117
31274
  * { fileId: "file2", type: "video" },
31118
31275
  * { fileId: "file3", type: "audio" },
31119
- * { fileId: "file4", type: "file" }
31276
+ * { fileId: "file4", type: "file" },
31277
+ * { type: "gif", url: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif", width: 480, height: 270 }
31120
31278
  * ],
31121
31279
  * })
31122
31280
  * ```
31123
31281
  *
31282
+ * A post holds 1 to 10 attachments. A GIF is a link, not a file, and takes no product tags.
31283
+ *
31124
31284
  * Creates an {@link Amity.Post}
31125
31285
  *
31126
31286
  * @param bundle The data necessary to create a new {@link Amity.Post}
@@ -31134,17 +31294,7 @@ const createMixedMediaPost = async (bundle) => {
31134
31294
  const client = getActiveClient();
31135
31295
  client.log('post/createMixedMediaPost', bundle);
31136
31296
  const { attachments, attachmentProductTags } = bundle, rest = __rest(bundle, ["attachments", "attachmentProductTags"]);
31137
- const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
31138
- ? attachments.map(attachment => {
31139
- var _a;
31140
- /* c8 ignore next */
31141
- const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
31142
- if (productTags)
31143
- return Object.assign(Object.assign({}, attachment), { productTags });
31144
- /* c8 ignore next */
31145
- return attachment;
31146
- })
31147
- : /* c8 ignore next */ attachments;
31297
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
31148
31298
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
31149
31299
  fireEvent('post.created', payload);
31150
31300
  const data = preparePostPayload(payload);
@@ -31661,6 +31811,10 @@ class PostLiveCollectionController extends LiveCollectionController {
31661
31811
  *
31662
31812
  * Observe all mutations on a list of {@link Amity.Post} for a given target object
31663
31813
  *
31814
+ * GIF posts come back on every API version. This query is on v5, so `dataTypes: ['gif']` filters
31815
+ * them; a post with GIFs beside other media is `mixed` and is hidden unless
31816
+ * `includeMixedStructure` is `true`.
31817
+ *
31664
31818
  * @param params.targetType the type of the target
31665
31819
  * @param params.targetId the ID of the target
31666
31820
  * @param callback the function to call when new data are available