@amityco/ts-sdk-react-native 6.30.4 → 6.31.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 (33) hide show
  1. package/dist/@types/domains/client.d.ts +1 -0
  2. package/dist/@types/domains/client.d.ts.map +1 -1
  3. package/dist/client/api/createClient.d.ts.map +1 -1
  4. package/dist/core/model/index.d.ts +1 -0
  5. package/dist/core/model/index.d.ts.map +1 -1
  6. package/dist/core/model/localReferenceId.d.ts +2 -0
  7. package/dist/core/model/localReferenceId.d.ts.map +1 -0
  8. package/dist/index.cjs.js +122 -27
  9. package/dist/index.esm.js +122 -27
  10. package/dist/index.umd.js +3 -3
  11. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  12. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
  13. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  14. package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
  15. package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts +2 -0
  16. package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts.map +1 -0
  17. package/dist/messageRepository/utils/index.d.ts +1 -0
  18. package/dist/messageRepository/utils/index.d.ts.map +1 -1
  19. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  20. package/dist/utils/event.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/src/@types/domains/client.ts +2 -0
  23. package/src/client/api/createClient.ts +26 -0
  24. package/src/core/model/index.ts +1 -0
  25. package/src/core/model/localReferenceId.ts +12 -0
  26. package/src/messageRepository/api/createMessage.ts +9 -0
  27. package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +1 -0
  28. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +4 -4
  29. package/src/messageRepository/utils/getMessageFromMainDB.ts +9 -6
  30. package/src/messageRepository/utils/getMessageIdentifierIds.ts +37 -0
  31. package/src/messageRepository/utils/index.ts +1 -0
  32. package/src/messageRepository/utils/prepareMessagePayload.ts +22 -18
  33. package/src/utils/event.ts +20 -3
@@ -39,6 +39,7 @@ declare global {
39
39
  getSocialSettings: () => Promise<Amity.SocialSettings>;
40
40
  getMessagePreviewSetting: (refresh?: boolean) => Promise<Amity.MessagePreviewSetting>;
41
41
  getMarkerSyncConsistentMode: () => boolean;
42
+ objectSyncMap: Map<string, string | undefined>;
42
43
  };
43
44
  type Device = {
44
45
  deviceId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAEtD,WAAW,sBAAsB;YAC/B,UAAU,cAAc;YACxB,YAAY,gBAAgB;YAC5B,YAAY,iBAAiB;SAC9B;QAED,WAAW,aAAa;YACtB,aAAa,gBAAgB;YAE7B,YAAY,iBAAiB;YAC7B,WAAW,gBAAgB;YAE3B,aAAa,iBAAiB;YAW9B,UAAU,eAAe;SAC1B;QAED,KAAK,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC;YAEhB,GAAG,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,aAAa,CAAC;YACpB,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC;YACvB,EAAE,EAAE,cAAc,CAAC,MAAM,CAAC;YAC1B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAE/B,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,KAAK,CAAC,iBAAiB,CAAC;YAC/D,YAAY,EAAE,CAAC,I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AU,CAAC,CAAC;SACrC,CAAC;QAEF,KAAK,mBAAmB,GAAG;YACzB,UAAU,EAAE,OAAO,CAAC;SACrB,CAAC;QAEF,KAAK,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,aAAa,CAAC,CAAC;QAEtF,KAAK,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG;YACxD;;eAEG;YACH,YAAY,EAAE,OAAO,CAAC;YACtB,WAAW,EAAE,OAAO,CAAC;SACtB,CAAC;KACH;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/createClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAc,MAAM,0BAA0B,CAAC;AAsBnE;;;;;;;;;;;;;;;KAeK;AACL,eAAO,MAAM,YAAY,WACf,MAAM,cACH,CAAA,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;;;;;;MAQtD,MAAM,MA4ER,CAAC"}
1
+ {"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/createClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAc,MAAM,0BAA0B,CAAC;AAsBnE;;;;;;;;;;;;;;;KAeK;AACL,eAAO,MAAM,YAAY,WACf,MAAM,cACH,CAAA,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;;;;;;MAQtD,MAAM,MAsGR,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './idResolvers';
2
2
  export * from './identifyModel';
3
+ export * from './localReferenceId';
3
4
  /**
4
5
  * A map of v3 response keys to a store name.
5
6
  * @hidden
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CA+CtD,CAAC;AAEF,aAAa;AACb,eAAO,MAAM,UAAU,2DAA0D,OAMhF,CAAC;AAEF,aAAa;AACb,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEzF;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CA+CtD,CAAC;AAEF,aAAa;AACb,eAAO,MAAM,UAAU,2DAA0D,OAMhF,CAAC;AAEF,aAAa;AACb,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEzF;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEvF"}
@@ -0,0 +1,2 @@
1
+ export declare const isLocalId: (id: string) => boolean;
2
+ //# sourceMappingURL=localReferenceId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localReferenceId.d.ts","sourceRoot":"","sources":["../../../src/core/model/localReferenceId.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,OAAQ,MAAM,YAEnC,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -123,8 +123,8 @@ const PostContentType = Object.freeze({
123
123
 
124
124
  function getVersion() {
125
125
  try {
126
- // the string ''v6.30.4-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
- return 'v6.30.4-cjs';
126
+ // the string ''v6.31.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
+ return 'v6.31.0-cjs';
128
128
  }
129
129
  catch (error) {
130
130
  return '__dev__';
@@ -572,6 +572,18 @@ const idResolvers = {
572
572
  */
573
573
  const getResolver = (name) => idResolvers[name];
574
574
 
575
+ /*
576
+ * To check if an id is a local referenceId, the id must start with 'LOCAL_'.
577
+ *
578
+ * Example: LOCAL_155f5158-281a-4a9d-a445-9243138d2041
579
+ *
580
+ * @param id as string
581
+ * @returns true if the id is a local referenceId, false otherwise
582
+ */
583
+ const isLocalId = (id) => {
584
+ return id.startsWith('LOCAL_');
585
+ };
586
+
575
587
  /**
576
588
  * A map of v3 response keys to a store name.
577
589
  * @hidden
@@ -6829,21 +6841,26 @@ function convertFromRaw$1(_a) {
6829
6841
  } }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$1({ channelType }) });
6830
6842
  }
6831
6843
 
6832
- const mergePayloadWithLocal = (payload) => {
6833
- var _a, _b, _c;
6834
- 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;
6835
- if (localMessage) {
6836
- return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
6837
- // NOTE: referenceId is missing in the payload. If we have local message data with referenceId, use it instead.
6838
- // TODO: Remove this logic when BE fixes the payload
6839
- referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
6840
- }
6841
- return payload;
6844
+ const addLocalReferenceId = (payload) => {
6845
+ const client = getActiveClient();
6846
+ const { objectSyncMap } = client;
6847
+ return Object.assign(Object.assign({}, payload), {
6848
+ /* NOTE: This logic is used to get local referenceId for each message.
6849
+ *
6850
+ * if messageId is a local reference id, use it as referenceId else get referenceId from objectSyncMap.
6851
+ * if find referenceId in objectSyncMap, this means this message is a local created message. The referenceId will be local reference id.
6852
+ * if cannot find referenceId in objectSyncMap, referenceId will be undefined.
6853
+ *
6854
+ * The referenceId is undefined means this message is not a local created message (optimistic creation message).
6855
+ */
6856
+ referenceId: isLocalId(payload.messageId)
6857
+ ? payload.messageId
6858
+ : objectSyncMap.get(payload.messageId) });
6842
6859
  };
6843
6860
  function convertFromRaw(message, reactors, event) {
6844
6861
  var _a;
6845
- const mergeMessage = mergePayloadWithLocal(message);
6846
- const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
6862
+ const messageWithReferenceId = addLocalReferenceId(message);
6863
+ const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = messageWithReferenceId, rest = __rest(messageWithReferenceId, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
6847
6864
  let cache;
6848
6865
  if (referenceId) {
6849
6866
  cache = pullFromCache(['message', 'get', referenceId]);
@@ -8660,6 +8677,42 @@ const updateSubChannelUnreadFromMessage = (message) => {
8660
8677
  pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
8661
8678
  };
8662
8679
 
8680
+ /*
8681
+ * To get message identifier ids used as a cache key for the each message.
8682
+ * These ids are used to store in the query stream and use to get messages from cache.
8683
+ *
8684
+ * The query stream data keeps the message identifier ids as follows:
8685
+ * ['server_message_id_1', 'server_message_id_2', 'LOCAL_message_id_1', 'LOCAL_message_id_2']
8686
+ *
8687
+ * Example use case: Message created locally and then created on the server.
8688
+ *
8689
+ * 1. Message created locally has `LOCAL_message_id_2` as referenceId.
8690
+ * 2. The `message.created` event will be fired from server with message payload that has no the referenceId.
8691
+ * 3. SDK use this function to find indentifer id for each message in the payload. If the message is created locally, the identifier id will be the local reference id.
8692
+ * 4. The SDK use this identifier ids to check if the message is already in the query stream before appending it.
8693
+ *
8694
+ * @param The raw message payload from server response
8695
+ * @returns The identifier ids of the messages
8696
+ */
8697
+ function getMessageIdentifierIds(messages) {
8698
+ const client = getActiveClient();
8699
+ const { objectSyncMap } = client;
8700
+ return messages
8701
+ .map(message => {
8702
+ var _a;
8703
+ /* NOTE: This logic is used to get identifier id for each message.
8704
+ *
8705
+ * if messageId is a local id, use it as identifier id else get identifier id from objectSyncMap.
8706
+ * if find referenceId in objectSyncMap, this means this message is a local created message. The identifier id will be local message id.
8707
+ * if cannot find identifier id in objectSyncMap, this means this message is not a local created message. The identifier id will be server message id.
8708
+ */
8709
+ if (isLocalId(message.messageId))
8710
+ return message.messageId;
8711
+ return (_a = objectSyncMap.get(message.messageId)) !== null && _a !== void 0 ? _a : message.messageId;
8712
+ })
8713
+ .filter(Boolean);
8714
+ }
8715
+
8663
8716
  /**
8664
8717
  * ```js
8665
8718
  * import { onMessageCreated } from '@amityco/ts-sdk-react-native'
@@ -9360,6 +9413,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9360
9413
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
9361
9414
  const sessionHandler = undefined;
9362
9415
  const isUnreadCountEnabled = false;
9416
+ const objectSyncMap = new Map();
9363
9417
  const client = {
9364
9418
  version: `${VERSION}`,
9365
9419
  apiKey,
@@ -9390,6 +9444,29 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9390
9444
  use: () => setActiveClient(client),
9391
9445
  isUnreadCountEnabled,
9392
9446
  getMarkerSyncConsistentMode,
9447
+ /*
9448
+ * The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
9449
+ *
9450
+ * For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
9451
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object through ObjectSyncMap.
9452
+ *
9453
+ * This is useful for syncing updates to the object, as the SDK can find the local ID from the server ID and update the object in the cache correctly.
9454
+ *
9455
+ * Example:
9456
+ * In the case of message optimistically creation. The referenceId is created locally.
9457
+ *
9458
+ * 1. When creating a message optimistically, a local referenceId is created. The objectSyncMap will have the following structure.
9459
+ * {
9460
+ * "LOCAL_uuid": undefined,
9461
+ * }
9462
+ *
9463
+ * 2. After the message was created on the server and SDK received the response from server, the objectSyncMap will be updated to
9464
+ * {
9465
+ * "LOCAL_uuid": "server_message_id",
9466
+ * "server_message_id": "LOCAL_uuid"
9467
+ * }
9468
+ */
9469
+ objectSyncMap,
9393
9470
  };
9394
9471
  try {
9395
9472
  const activeClient = getActiveClient();
@@ -15008,12 +15085,24 @@ const unmuteChannel = async (channelId) => {
15008
15085
  /* end_public_function */
15009
15086
 
15010
15087
  const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
15011
- var _a;
15088
+ var _a, _b;
15012
15089
  if (!sourceModel) {
15013
15090
  return sourceModel;
15014
15091
  }
15015
- const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
15016
- const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
15092
+ const client = getActiveClient();
15093
+ const { objectSyncMap } = client;
15094
+ /*
15095
+ * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
15096
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
15097
+ */
15098
+ const resolvedId = isLocalId(sourceModel[sourceModelProp])
15099
+ ? sourceModel[sourceModelProp]
15100
+ : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
15101
+ const model = (_b = pullFromCache([
15102
+ destinationDomain,
15103
+ 'get',
15104
+ `${resolvedId}`,
15105
+ ])) === null || _b === void 0 ? void 0 : _b.data;
15017
15106
  if (!model)
15018
15107
  return;
15019
15108
  return callback(model);
@@ -15441,6 +15530,7 @@ let uniqueId;
15441
15530
  const createMessageOptimistic = (bundle) => {
15442
15531
  var _a, _b;
15443
15532
  const client = getActiveClient();
15533
+ const { objectSyncMap } = client;
15444
15534
  if (!client.cache)
15445
15535
  return;
15446
15536
  /*
@@ -15469,6 +15559,7 @@ const createMessageOptimistic = (bundle) => {
15469
15559
  const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
15470
15560
  const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
15471
15561
  pushToCache(['message', 'get', message.messageId], message, { cachedAt });
15562
+ objectSyncMap.set(message.messageId, undefined);
15472
15563
  fireEvent('local.message.created', { messages: [message] });
15473
15564
  return message;
15474
15565
  };
@@ -15496,12 +15587,15 @@ const createMessageOptimistic = (bundle) => {
15496
15587
  */
15497
15588
  const createMessage = async (bundle) => {
15498
15589
  const client = getActiveClient();
15590
+ const { objectSyncMap } = client;
15499
15591
  client.log('message/createMessage', bundle);
15500
15592
  const optimisticData = createMessageOptimistic(bundle);
15501
15593
  const referenceId = bundle.referenceId || uniqueId || getLocalId();
15502
15594
  uniqueId = undefined;
15503
15595
  try {
15504
15596
  const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
15597
+ objectSyncMap.set(referenceId, payload.messages[0].messageId);
15598
+ objectSyncMap.set(payload.messages[0].messageId, referenceId);
15505
15599
  const data = await prepareMessagePayload(payload);
15506
15600
  const { messages } = data;
15507
15601
  const cachedAt = client.cache && Date.now();
@@ -16256,7 +16350,7 @@ class MessageQueryStreamController extends QueryStreamController {
16256
16350
  var _a, _b;
16257
16351
  if (refresh) {
16258
16352
  pushToCache(this.cacheKey, {
16259
- data: response.messages.map(getResolver('message')),
16353
+ data: getMessageIdentifierIds(response.messages),
16260
16354
  query: this.query,
16261
16355
  });
16262
16356
  }
@@ -16264,8 +16358,8 @@ class MessageQueryStreamController extends QueryStreamController {
16264
16358
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
16265
16359
  const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
16266
16360
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
16267
- ? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
16268
- : [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
16361
+ ? [...new Set([...messages, ...getMessageIdentifierIds(response.messages)])]
16362
+ : [...new Set([...getMessageIdentifierIds(response.messages), ...messages])] }));
16269
16363
  }
16270
16364
  }
16271
16365
  reactor(action) {
@@ -16339,12 +16433,12 @@ class MessagePaginationController extends PaginationController {
16339
16433
 
16340
16434
  const getMessageFromMainDB = (messageId) => {
16341
16435
  var _a, _b;
16342
- const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
16343
- if (message)
16344
- return message;
16345
- // If message is not found by messageId as a key, query all messages in cache and find the message by messageId
16346
- const messages = queryCache(['message', 'get']);
16347
- return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
16436
+ const client = getActiveClient();
16437
+ const { objectSyncMap } = client;
16438
+ const resolvedMessageId = isLocalId(messageId)
16439
+ ? messageId
16440
+ : (_a = objectSyncMap.get(messageId)) !== null && _a !== void 0 ? _a : messageId;
16441
+ return (_b = pullFromCache(['message', 'get', resolvedMessageId])) === null || _b === void 0 ? void 0 : _b.data;
16348
16442
  };
16349
16443
 
16350
16444
  class MessageLiveCollectionController extends LiveCollectionController {
@@ -16684,7 +16778,8 @@ var index$g = /*#__PURE__*/Object.freeze({
16684
16778
  convertFromRaw: convertFromRaw,
16685
16779
  prepareMessagePayload: prepareMessagePayload,
16686
16780
  convertParams: convertParams,
16687
- convertQueryParams: convertQueryParams$1
16781
+ convertQueryParams: convertQueryParams$1,
16782
+ getMessageIdentifierIds: getMessageIdentifierIds
16688
16783
  });
16689
16784
 
16690
16785
  /**
package/dist/index.esm.js CHANGED
@@ -89,8 +89,8 @@ const PostContentType = Object.freeze({
89
89
 
90
90
  function getVersion() {
91
91
  try {
92
- // the string ''v6.30.4-esm'' should be replaced by actual value by @rollup/plugin-replace
93
- return 'v6.30.4-esm';
92
+ // the string ''v6.31.0-esm'' should be replaced by actual value by @rollup/plugin-replace
93
+ return 'v6.31.0-esm';
94
94
  }
95
95
  catch (error) {
96
96
  return '__dev__';
@@ -538,6 +538,18 @@ const idResolvers = {
538
538
  */
539
539
  const getResolver = (name) => idResolvers[name];
540
540
 
541
+ /*
542
+ * To check if an id is a local referenceId, the id must start with 'LOCAL_'.
543
+ *
544
+ * Example: LOCAL_155f5158-281a-4a9d-a445-9243138d2041
545
+ *
546
+ * @param id as string
547
+ * @returns true if the id is a local referenceId, false otherwise
548
+ */
549
+ const isLocalId = (id) => {
550
+ return id.startsWith('LOCAL_');
551
+ };
552
+
541
553
  /**
542
554
  * A map of v3 response keys to a store name.
543
555
  * @hidden
@@ -22902,21 +22914,26 @@ function convertFromRaw$1(_a) {
22902
22914
  } }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$1({ channelType }) });
22903
22915
  }
22904
22916
 
22905
- const mergePayloadWithLocal = (payload) => {
22906
- var _a, _b, _c;
22907
- 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;
22908
- if (localMessage) {
22909
- return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
22910
- // NOTE: referenceId is missing in the payload. If we have local message data with referenceId, use it instead.
22911
- // TODO: Remove this logic when BE fixes the payload
22912
- referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
22913
- }
22914
- return payload;
22917
+ const addLocalReferenceId = (payload) => {
22918
+ const client = getActiveClient();
22919
+ const { objectSyncMap } = client;
22920
+ return Object.assign(Object.assign({}, payload), {
22921
+ /* NOTE: This logic is used to get local referenceId for each message.
22922
+ *
22923
+ * if messageId is a local reference id, use it as referenceId else get referenceId from objectSyncMap.
22924
+ * if find referenceId in objectSyncMap, this means this message is a local created message. The referenceId will be local reference id.
22925
+ * if cannot find referenceId in objectSyncMap, referenceId will be undefined.
22926
+ *
22927
+ * The referenceId is undefined means this message is not a local created message (optimistic creation message).
22928
+ */
22929
+ referenceId: isLocalId(payload.messageId)
22930
+ ? payload.messageId
22931
+ : objectSyncMap.get(payload.messageId) });
22915
22932
  };
22916
22933
  function convertFromRaw(message, reactors, event) {
22917
22934
  var _a;
22918
- const mergeMessage = mergePayloadWithLocal(message);
22919
- const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
22935
+ const messageWithReferenceId = addLocalReferenceId(message);
22936
+ const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = messageWithReferenceId, rest = __rest(messageWithReferenceId, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
22920
22937
  let cache;
22921
22938
  if (referenceId) {
22922
22939
  cache = pullFromCache(['message', 'get', referenceId]);
@@ -24733,6 +24750,42 @@ const updateSubChannelUnreadFromMessage = (message) => {
24733
24750
  pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
24734
24751
  };
24735
24752
 
24753
+ /*
24754
+ * To get message identifier ids used as a cache key for the each message.
24755
+ * These ids are used to store in the query stream and use to get messages from cache.
24756
+ *
24757
+ * The query stream data keeps the message identifier ids as follows:
24758
+ * ['server_message_id_1', 'server_message_id_2', 'LOCAL_message_id_1', 'LOCAL_message_id_2']
24759
+ *
24760
+ * Example use case: Message created locally and then created on the server.
24761
+ *
24762
+ * 1. Message created locally has `LOCAL_message_id_2` as referenceId.
24763
+ * 2. The `message.created` event will be fired from server with message payload that has no the referenceId.
24764
+ * 3. SDK use this function to find indentifer id for each message in the payload. If the message is created locally, the identifier id will be the local reference id.
24765
+ * 4. The SDK use this identifier ids to check if the message is already in the query stream before appending it.
24766
+ *
24767
+ * @param The raw message payload from server response
24768
+ * @returns The identifier ids of the messages
24769
+ */
24770
+ function getMessageIdentifierIds(messages) {
24771
+ const client = getActiveClient();
24772
+ const { objectSyncMap } = client;
24773
+ return messages
24774
+ .map(message => {
24775
+ var _a;
24776
+ /* NOTE: This logic is used to get identifier id for each message.
24777
+ *
24778
+ * if messageId is a local id, use it as identifier id else get identifier id from objectSyncMap.
24779
+ * if find referenceId in objectSyncMap, this means this message is a local created message. The identifier id will be local message id.
24780
+ * if cannot find identifier id in objectSyncMap, this means this message is not a local created message. The identifier id will be server message id.
24781
+ */
24782
+ if (isLocalId(message.messageId))
24783
+ return message.messageId;
24784
+ return (_a = objectSyncMap.get(message.messageId)) !== null && _a !== void 0 ? _a : message.messageId;
24785
+ })
24786
+ .filter(Boolean);
24787
+ }
24788
+
24736
24789
  /**
24737
24790
  * ```js
24738
24791
  * import { onMessageCreated } from '@amityco/ts-sdk-react-native'
@@ -25433,6 +25486,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25433
25486
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25434
25487
  const sessionHandler = undefined;
25435
25488
  const isUnreadCountEnabled = false;
25489
+ const objectSyncMap = new Map();
25436
25490
  const client = {
25437
25491
  version: `${VERSION}`,
25438
25492
  apiKey,
@@ -25463,6 +25517,29 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25463
25517
  use: () => setActiveClient(client),
25464
25518
  isUnreadCountEnabled,
25465
25519
  getMarkerSyncConsistentMode,
25520
+ /*
25521
+ * The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
25522
+ *
25523
+ * For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
25524
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object through ObjectSyncMap.
25525
+ *
25526
+ * This is useful for syncing updates to the object, as the SDK can find the local ID from the server ID and update the object in the cache correctly.
25527
+ *
25528
+ * Example:
25529
+ * In the case of message optimistically creation. The referenceId is created locally.
25530
+ *
25531
+ * 1. When creating a message optimistically, a local referenceId is created. The objectSyncMap will have the following structure.
25532
+ * {
25533
+ * "LOCAL_uuid": undefined,
25534
+ * }
25535
+ *
25536
+ * 2. After the message was created on the server and SDK received the response from server, the objectSyncMap will be updated to
25537
+ * {
25538
+ * "LOCAL_uuid": "server_message_id",
25539
+ * "server_message_id": "LOCAL_uuid"
25540
+ * }
25541
+ */
25542
+ objectSyncMap,
25466
25543
  };
25467
25544
  try {
25468
25545
  const activeClient = getActiveClient();
@@ -31081,12 +31158,24 @@ const unmuteChannel = async (channelId) => {
31081
31158
  /* end_public_function */
31082
31159
 
31083
31160
  const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
31084
- var _a;
31161
+ var _a, _b;
31085
31162
  if (!sourceModel) {
31086
31163
  return sourceModel;
31087
31164
  }
31088
- const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
31089
- const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31165
+ const client = getActiveClient();
31166
+ const { objectSyncMap } = client;
31167
+ /*
31168
+ * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
31169
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
31170
+ */
31171
+ const resolvedId = isLocalId(sourceModel[sourceModelProp])
31172
+ ? sourceModel[sourceModelProp]
31173
+ : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
31174
+ const model = (_b = pullFromCache([
31175
+ destinationDomain,
31176
+ 'get',
31177
+ `${resolvedId}`,
31178
+ ])) === null || _b === void 0 ? void 0 : _b.data;
31090
31179
  if (!model)
31091
31180
  return;
31092
31181
  return callback(model);
@@ -31514,6 +31603,7 @@ let uniqueId;
31514
31603
  const createMessageOptimistic = (bundle) => {
31515
31604
  var _a, _b;
31516
31605
  const client = getActiveClient();
31606
+ const { objectSyncMap } = client;
31517
31607
  if (!client.cache)
31518
31608
  return;
31519
31609
  /*
@@ -31542,6 +31632,7 @@ const createMessageOptimistic = (bundle) => {
31542
31632
  const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
31543
31633
  const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
31544
31634
  pushToCache(['message', 'get', message.messageId], message, { cachedAt });
31635
+ objectSyncMap.set(message.messageId, undefined);
31545
31636
  fireEvent('local.message.created', { messages: [message] });
31546
31637
  return message;
31547
31638
  };
@@ -31569,12 +31660,15 @@ const createMessageOptimistic = (bundle) => {
31569
31660
  */
31570
31661
  const createMessage = async (bundle) => {
31571
31662
  const client = getActiveClient();
31663
+ const { objectSyncMap } = client;
31572
31664
  client.log('message/createMessage', bundle);
31573
31665
  const optimisticData = createMessageOptimistic(bundle);
31574
31666
  const referenceId = bundle.referenceId || uniqueId || getLocalId();
31575
31667
  uniqueId = undefined;
31576
31668
  try {
31577
31669
  const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
31670
+ objectSyncMap.set(referenceId, payload.messages[0].messageId);
31671
+ objectSyncMap.set(payload.messages[0].messageId, referenceId);
31578
31672
  const data = await prepareMessagePayload(payload);
31579
31673
  const { messages } = data;
31580
31674
  const cachedAt = client.cache && Date.now();
@@ -32329,7 +32423,7 @@ class MessageQueryStreamController extends QueryStreamController {
32329
32423
  var _a, _b;
32330
32424
  if (refresh) {
32331
32425
  pushToCache(this.cacheKey, {
32332
- data: response.messages.map(getResolver('message')),
32426
+ data: getMessageIdentifierIds(response.messages),
32333
32427
  query: this.query,
32334
32428
  });
32335
32429
  }
@@ -32337,8 +32431,8 @@ class MessageQueryStreamController extends QueryStreamController {
32337
32431
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
32338
32432
  const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
32339
32433
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
32340
- ? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
32341
- : [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
32434
+ ? [...new Set([...messages, ...getMessageIdentifierIds(response.messages)])]
32435
+ : [...new Set([...getMessageIdentifierIds(response.messages), ...messages])] }));
32342
32436
  }
32343
32437
  }
32344
32438
  reactor(action) {
@@ -32412,12 +32506,12 @@ class MessagePaginationController extends PaginationController {
32412
32506
 
32413
32507
  const getMessageFromMainDB = (messageId) => {
32414
32508
  var _a, _b;
32415
- const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
32416
- if (message)
32417
- return message;
32418
- // If message is not found by messageId as a key, query all messages in cache and find the message by messageId
32419
- const messages = queryCache(['message', 'get']);
32420
- return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
32509
+ const client = getActiveClient();
32510
+ const { objectSyncMap } = client;
32511
+ const resolvedMessageId = isLocalId(messageId)
32512
+ ? messageId
32513
+ : (_a = objectSyncMap.get(messageId)) !== null && _a !== void 0 ? _a : messageId;
32514
+ return (_b = pullFromCache(['message', 'get', resolvedMessageId])) === null || _b === void 0 ? void 0 : _b.data;
32421
32515
  };
32422
32516
 
32423
32517
  class MessageLiveCollectionController extends LiveCollectionController {
@@ -32757,7 +32851,8 @@ var index$g = /*#__PURE__*/Object.freeze({
32757
32851
  convertFromRaw: convertFromRaw,
32758
32852
  prepareMessagePayload: prepareMessagePayload,
32759
32853
  convertParams: convertParams,
32760
- convertQueryParams: convertQueryParams$1
32854
+ convertQueryParams: convertQueryParams$1,
32855
+ getMessageIdentifierIds: getMessageIdentifierIds
32761
32856
  });
32762
32857
 
32763
32858
  /**