@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.
Files changed (60) 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/fileRepository/api/uploadImage.d.ts +2 -1
  33. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  34. package/dist/index.cjs.js +217 -58
  35. package/dist/index.esm.js +217 -58
  36. package/dist/index.umd.js +1 -1
  37. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  38. package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
  39. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  40. package/dist/postRepository/api/createMixedMediaPost.d.ts +6 -6
  41. package/dist/postRepository/api/createMixedMediaPost.d.ts.map +1 -1
  42. package/dist/postRepository/api/createPost.d.ts +1 -4
  43. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  44. package/dist/postRepository/api/editPost.d.ts +4 -5
  45. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  46. package/dist/postRepository/api/tests/gifPost.test.d.ts +2 -0
  47. package/dist/postRepository/api/tests/gifPost.test.d.ts.map +1 -0
  48. package/dist/postRepository/observers/getPosts.d.ts +4 -0
  49. package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
  50. package/dist/postRepository/utils/attachments.d.ts +8 -0
  51. package/dist/postRepository/utils/attachments.d.ts.map +1 -0
  52. package/dist/utils/gifAttachment.d.ts +5 -0
  53. package/dist/utils/gifAttachment.d.ts.map +1 -0
  54. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  55. package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts +2 -0
  56. package/dist/utils/linkedObject/tests/channelCachePerformance.test.d.ts.map +1 -0
  57. package/dist/utils/postTypePredicate.d.ts +1 -0
  58. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  59. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  60. 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
@@ -17649,12 +17765,13 @@ const uploadVideo = async (formData, feedType, onProgress) => {
17649
17765
  * @param formData The data necessary to create a new {@link Amity.File<'image'>}
17650
17766
  * @param onProgress The callback to track the upload progress
17651
17767
  * @param altText The alt text for the image
17768
+ * @param isFullImage Keeps the original image so `size=full` returns it instead of the large copy
17652
17769
  * @returns The newly created {@link Amity.File<'image'>}
17653
17770
  *
17654
17771
  * @category File API
17655
17772
  * @async
17656
17773
  */
17657
- const uploadImage = async (formData, onProgress, altText) => {
17774
+ const uploadImage = async (formData, onProgress, altText, isFullImage) => {
17658
17775
  const client = getActiveClient();
17659
17776
  client.log('file/uploadImage', formData);
17660
17777
  const files = formData.getAll('files');
@@ -17675,6 +17792,10 @@ const uploadImage = async (formData, onProgress, altText) => {
17675
17792
  }
17676
17793
  const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
17677
17794
  formData.append('accessType', accessType);
17795
+ // skip if the caller already appended it, so the old FormData workaround keeps working
17796
+ if (isFullImage && !formData.getAll('fullImage').length) {
17797
+ formData.append('fullImage', 'true');
17798
+ }
17678
17799
  const headers = 'getHeaders' in formData
17679
17800
  ? formData.getHeaders()
17680
17801
  : { 'content-type': 'multipart/form-data' };
@@ -27881,8 +28002,40 @@ getCommentByIds.locally = (commentIds) => {
27881
28002
  };
27882
28003
  };
27883
28004
 
28005
+ const GIF_OPTIONAL_KEYS = ['width', 'height'];
28006
+ /*
28007
+ * The server refuses a GIF attachment that carries `null` or any key it does not know, so the
28008
+ * request keeps `type`, `url` and only the optional fields that have a value. The SDK does not
28009
+ * check the values themselves: the server answers 400 for a bad one.
28010
+ */
28011
+ const toGifAttachmentPayload = (gif) => {
28012
+ const payload = { type: 'gif', url: gif.url };
28013
+ GIF_OPTIONAL_KEYS.forEach(key => {
28014
+ const value = gif[key];
28015
+ if (value !== undefined && value !== null)
28016
+ Object.assign(payload, { [key]: value });
28017
+ });
28018
+ return payload;
28019
+ };
28020
+ /* Builds each GIF from its known keys; every other attachment is sent as the caller gave it. */
28021
+ const toAttachmentsPayload = (attachments) => attachments.map(attachment => attachment.type === 'gif'
28022
+ ? toGifAttachmentPayload(attachment)
28023
+ : attachment);
28024
+
28025
+ /*
28026
+ * The data types the server lists for a comment, known before it answers: one per attachment
28027
+ * type, plus `text` when there is text. Sorted, as the server sorts them.
28028
+ */
28029
+ const commentDataTypesOf = (text, attachments) => {
28030
+ const types = new Set((attachments !== null && attachments !== void 0 ? attachments : []).map(attachment => attachment.type));
28031
+ if (text)
28032
+ types.add('text');
28033
+ return [...types].sort();
28034
+ };
28035
+
27884
28036
  const getLocalCommentId = () => uuid();
27885
28037
  const createCommentOptimistic = (bundle) => {
28038
+ var _a;
27886
28039
  const client = getActiveClient();
27887
28040
  if (!client.cache)
27888
28041
  return;
@@ -27917,6 +28070,7 @@ const createCommentOptimistic = (bundle) => {
27917
28070
  targetId: '',
27918
28071
  targetType: 'community',
27919
28072
  dataType: 'text',
28073
+ dataTypes: commentDataTypesOf((_a = bundle.data) === null || _a === void 0 ? void 0 : _a.text, bundle.attachments),
27920
28074
  syncState: "syncing" /* Amity.SyncState.Syncing */,
27921
28075
  // In a gated community the optimistic object stays out of public collections until the
27922
28076
  // response settles the status; the author's own view still updates through the local event
@@ -27963,12 +28117,15 @@ const createCommentOptimistic = (bundle) => {
27963
28117
  const createComment = async (bundle, isOptimistic = true) => {
27964
28118
  const client = getActiveClient();
27965
28119
  client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
28120
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
28121
+ const request = bundle.attachments
28122
+ ? Object.assign(Object.assign({}, bundle), { attachments: toAttachmentsPayload(bundle.attachments) }) : bundle;
27966
28123
  // Without a local comment the server assigns the id; with one, the same id travels through the
27967
28124
  // optimistic object, the response and every realtime event so each step recognises it.
27968
- const optimisticData = isOptimistic ? createCommentOptimistic(bundle) : undefined;
28125
+ const optimisticData = isOptimistic ? createCommentOptimistic(request) : undefined;
27969
28126
  const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
27970
28127
  try {
27971
- const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
28128
+ const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, request), { commentId }));
27972
28129
  // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
27973
28130
  if (payload.comments.length === 0)
27974
28131
  throw new Error('Comment not created');
@@ -28061,9 +28218,16 @@ const createComment = async (bundle, isOptimistic = true) => {
28061
28218
  * const updated = await CommentRepository.updateComment(commentId, {
28062
28219
  * data: { text: 'hello world' }
28063
28220
  * })
28221
+ *
28222
+ * // Replace the GIF, or remove it and keep the text
28223
+ * await CommentRepository.updateComment(commentId, {
28224
+ * attachments: [{ type: 'gif', url: 'https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif' }],
28225
+ * })
28226
+ * await CommentRepository.updateComment(commentId, { attachments: [] })
28064
28227
  * ```
28065
28228
  *
28066
- * Updates an {@link Amity.Comment}
28229
+ * Updates an {@link Amity.Comment}. `attachments` replaces the current ones, `[]` removes them,
28230
+ * and leaving `attachments` out keeps them as they are.
28067
28231
  *
28068
28232
  * @param commentId The ID of the {@link Amity.Comment} to edit
28069
28233
  * @param patch The patch data to apply
@@ -28077,7 +28241,10 @@ const updateComment = async (commentId, patch) => {
28077
28241
  const client = getActiveClient();
28078
28242
  client.log('user/updateComment', patch);
28079
28243
  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);
28244
+ // A GIF is sent with its known keys only; the server refuses `null` and unknown keys.
28245
+ const body = patch.attachments
28246
+ ? Object.assign(Object.assign({}, patch), { attachments: toAttachmentsPayload(patch.attachments) }) : patch;
28247
+ const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, body);
28081
28248
  const data = prepareCommentPayload(payload);
28082
28249
  const updated = data.comments.find(comment => comment.commentId === commentId);
28083
28250
  const cachedAt = client.cache && Date.now();
@@ -30544,6 +30711,19 @@ getPostByIds.locally = (postIds) => {
30544
30711
  };
30545
30712
  };
30546
30713
 
30714
+ /*
30715
+ * The `attachments` a post create or edit sends. A GIF goes with its known keys only and never
30716
+ * with product tags (both a 400). A file takes its product tags from the map, as before.
30717
+ */
30718
+ const preparePostAttachments = (attachments, attachmentProductTags) => attachments === null || attachments === void 0 ? void 0 : attachments.map(attachment => {
30719
+ if (attachment.type === 'gif') {
30720
+ return toGifAttachmentPayload(attachment);
30721
+ }
30722
+ if (!attachmentProductTags || !attachment.fileId)
30723
+ return attachment;
30724
+ return Object.assign(Object.assign({}, attachment), { productTags: attachmentProductTags.get(attachment.fileId) });
30725
+ });
30726
+
30547
30727
  /* begin_public_function
30548
30728
  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
30729
  */
@@ -30573,17 +30753,7 @@ const createPost = async (bundle) => {
30573
30753
  delete bundle.dataType;
30574
30754
  }
30575
30755
  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;
30756
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
30587
30757
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
30588
30758
  fireEvent('post.created', payload);
30589
30759
  const data = preparePostPayload(payload);
@@ -30609,7 +30779,9 @@ const createPost = async (bundle) => {
30609
30779
  * })
30610
30780
  * ```
30611
30781
  *
30612
- * Updates an {@link Amity.Post}
30782
+ * Updates an {@link Amity.Post}. `attachments` is the full list to keep: a GIF is matched by its
30783
+ * `url`, so send each kept GIF back with its link and size as read from `childrenPosts`; an
30784
+ * attachment left out is deleted, `[]` removes them all, and leaving `attachments` out keeps them.
30613
30785
  *
30614
30786
  * @param postId The ID of the {@link Amity.Post} to edit
30615
30787
  * @param patch The patch data to apply
@@ -30622,17 +30794,7 @@ const editPost = async (postId, patch) => {
30622
30794
  const client = getActiveClient();
30623
30795
  client.log('user/editPost', patch);
30624
30796
  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;
30797
+ const processedAttachments = preparePostAttachments(attachments, patch.attachmentProductTags);
30636
30798
  const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
30637
30799
  const data = prepareMembershipPayload(payload, 'communityUsers');
30638
30800
  const cachedAt = client.cache && Date.now();
@@ -31116,11 +31278,14 @@ const createAudioPost = async (bundle) => {
31116
31278
  * { fileId: "file1", type: "image" },
31117
31279
  * { fileId: "file2", type: "video" },
31118
31280
  * { fileId: "file3", type: "audio" },
31119
- * { fileId: "file4", type: "file" }
31281
+ * { fileId: "file4", type: "file" },
31282
+ * { type: "gif", url: "https://media.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif", width: 480, height: 270 }
31120
31283
  * ],
31121
31284
  * })
31122
31285
  * ```
31123
31286
  *
31287
+ * A post holds 1 to 10 attachments. A GIF is a link, not a file, and takes no product tags.
31288
+ *
31124
31289
  * Creates an {@link Amity.Post}
31125
31290
  *
31126
31291
  * @param bundle The data necessary to create a new {@link Amity.Post}
@@ -31134,17 +31299,7 @@ const createMixedMediaPost = async (bundle) => {
31134
31299
  const client = getActiveClient();
31135
31300
  client.log('post/createMixedMediaPost', bundle);
31136
31301
  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;
31302
+ const processedAttachments = preparePostAttachments(attachments, attachmentProductTags);
31148
31303
  const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
31149
31304
  fireEvent('post.created', payload);
31150
31305
  const data = preparePostPayload(payload);
@@ -31661,6 +31816,10 @@ class PostLiveCollectionController extends LiveCollectionController {
31661
31816
  *
31662
31817
  * Observe all mutations on a list of {@link Amity.Post} for a given target object
31663
31818
  *
31819
+ * GIF posts come back on every API version. This query is on v5, so `dataTypes: ['gif']` filters
31820
+ * them; a post with GIFs beside other media is `mixed` and is hidden unless
31821
+ * `includeMixedStructure` is `true`.
31822
+ *
31664
31823
  * @param params.targetType the type of the target
31665
31824
  * @param params.targetId the ID of the target
31666
31825
  * @param callback the function to call when new data are available