@amityco/ts-sdk-react-native 6.30.5-d50bb81.0 → 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.
- package/.env +26 -26
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +1 -0
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/model/localReferenceId.d.ts +2 -0
- package/dist/core/model/localReferenceId.d.ts.map +1 -0
- package/dist/index.cjs.js +123 -28
- package/dist/index.esm.js +123 -28
- package/dist/index.umd.js +3 -3
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts +2 -0
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts.map +1 -0
- package/dist/messageRepository/utils/index.d.ts +1 -0
- package/dist/messageRepository/utils/index.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/utils/event.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/client.ts +2 -0
- package/src/client/api/createClient.ts +26 -0
- package/src/core/model/index.ts +1 -0
- package/src/core/model/localReferenceId.ts +12 -0
- package/src/messageRepository/api/createMessage.ts +9 -0
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +1 -0
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +4 -4
- package/src/messageRepository/utils/getMessageFromMainDB.ts +9 -6
- package/src/messageRepository/utils/getMessageIdentifierIds.ts +37 -0
- package/src/messageRepository/utils/index.ts +1 -0
- package/src/messageRepository/utils/prepareMessagePayload.ts +22 -18
- package/src/utils/event.ts +20 -3
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.
|
|
93
|
-
return 'v6.
|
|
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
|
|
22906
|
-
|
|
22907
|
-
const
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
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
|
|
22919
|
-
const { 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
|
|
31089
|
-
const
|
|
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
|
|
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
|
|
32341
|
-
: [...new Set([...response.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
|
|
32416
|
-
|
|
32417
|
-
|
|
32418
|
-
|
|
32419
|
-
|
|
32420
|
-
return (_b =
|
|
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
|
/**
|
|
@@ -40813,7 +40908,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
40813
40908
|
getPoll: getPoll
|
|
40814
40909
|
});
|
|
40815
40910
|
|
|
40816
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
40911
|
+
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-----";
|
|
40817
40912
|
/*
|
|
40818
40913
|
* The crypto algorithm used for importing key and signing string
|
|
40819
40914
|
*/
|