@amityco/ts-sdk-react-native 7.0.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/linkPreview.d.ts +12 -0
- package/dist/@types/core/linkPreview.d.ts.map +1 -0
- package/dist/@types/domains/client.d.ts +0 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/fetchLinkPreview.d.ts +14 -0
- package/dist/client/api/fetchLinkPreview.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +0 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +48 -122
- package/dist/index.esm.js +48 -122
- package/dist/index.umd.js +3 -3
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/index.d.ts +0 -1
- 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/core/linkPreview.ts +12 -0
- package/src/@types/domains/client.ts +0 -2
- package/src/client/api/createClient.ts +0 -26
- package/src/client/api/fetchLinkPreview.ts +30 -0
- package/src/client/api/index.ts +1 -0
- package/src/core/model/index.ts +0 -1
- package/src/messageRepository/api/createMessage.ts +0 -7
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +4 -4
- package/src/messageRepository/utils/getMessageFromMainDB.ts +5 -9
- package/src/messageRepository/utils/index.ts +0 -1
- package/src/messageRepository/utils/prepareMessagePayload.ts +17 -22
- package/src/utils/event.ts +2 -19
- package/dist/core/model/localReferenceId.d.ts +0 -2
- package/dist/core/model/localReferenceId.d.ts.map +0 -1
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts +0 -2
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts.map +0 -1
- package/src/core/model/localReferenceId.ts +0 -12
- package/src/messageRepository/utils/getMessageIdentifierIds.ts +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/createMessage.ts"],"names":[],"mappings":"AAmBA,aAAK,kBAAkB,CAAC,CAAC,SAAS,KAAK,CAAC,kBAAkB,IAAI,IAAI,CAChE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAChB,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAC9E,GAAG;IACF,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;
|
|
1
|
+
{"version":3,"file":"createMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/createMessage.ts"],"names":[],"mappings":"AAmBA,aAAK,kBAAkB,CAAC,CAAC,SAAS,KAAK,CAAC,kBAAkB,IAAI,IAAI,CAChE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAChB,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAC9E,GAAG;IACF,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAqEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,yEAEvB,QAAQ,MAAM,MAAM,CAAC,MAAM,OAAO,CAAC,CAuCrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessageFromMainDB.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/getMessageFromMainDB.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMessageFromMainDB.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/getMessageFromMainDB.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,cAAe,MAAM,KAAG,MAAM,eAAe,GAAG,SAMhF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareMessagePayload.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/prepareMessagePayload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareMessagePayload.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/prepareMessagePayload.ts"],"names":[],"mappings":"AA4BA,wBAAgB,cAAc,CAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,eAAe,EAAE,EAClC,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC,iBAAiB,GACpC,KAAK,CAAC,eAAe,CAqEvB;AAWD,eAAO,MAAM,qBAAqB,YACvB,MAAM,cAAc,UACrB,MAAM,MAAM,iBAAiB,KACpC,QAAQ,MAAM,uBAAuB,CAyCvC,CAAC;AAEF,aAAK,gBAAgB,GAAG,IAAI,CAC1B,KAAK,CAAC,aAAa,EAIjB,MAAM,GACN,QAAQ,GACR,cAAc,GACd,MAAM,GACN,gBAAgB,GAChB,iBAAiB,GACjB,UAAU,GACV,eAAe,GACf,eAAe,CAClB,GAAG;IACF,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACvC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IACnD,QAAQ,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC;IACpC,OAAO,EAAE;QACP,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACvC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;KACrC,CAAC;CACH,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAC5B,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,GAAG,IAAI,EACR,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAc9C;AAED,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,KAAK,EACL,IAAI,EACJ,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,sBAAsB,GAAG,gBAAgB,CAyBjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,qMAM6B,MAAM,YAAY,iJAgBzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -88,8 +88,6 @@ export const createClient = (
|
|
|
88
88
|
|
|
89
89
|
const isUnreadCountEnabled = false;
|
|
90
90
|
|
|
91
|
-
const objectSyncMap = new Map<string, string>();
|
|
92
|
-
|
|
93
91
|
const client = {
|
|
94
92
|
version: `${VERSION}`,
|
|
95
93
|
apiKey,
|
|
@@ -135,30 +133,6 @@ export const createClient = (
|
|
|
135
133
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
136
134
|
*/
|
|
137
135
|
prefixDeviceIdKey,
|
|
138
|
-
|
|
139
|
-
/*
|
|
140
|
-
* The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
|
|
141
|
-
*
|
|
142
|
-
* 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.
|
|
143
|
-
* 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.
|
|
144
|
-
*
|
|
145
|
-
* 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.
|
|
146
|
-
*
|
|
147
|
-
* Example:
|
|
148
|
-
* In the case of message optimistically creation. The referenceId is created locally.
|
|
149
|
-
*
|
|
150
|
-
* 1. When creating a message optimistically, a local referenceId is created. The objectSyncMap will have the following structure.
|
|
151
|
-
* {
|
|
152
|
-
* "LOCAL_uuid": undefined,
|
|
153
|
-
* }
|
|
154
|
-
*
|
|
155
|
-
* 2. After the message was created on the server and SDK received the response from server, the objectSyncMap will be updated to
|
|
156
|
-
* {
|
|
157
|
-
* "LOCAL_uuid": "server_message_id",
|
|
158
|
-
* "server_message_id": "LOCAL_uuid"
|
|
159
|
-
* }
|
|
160
|
-
*/
|
|
161
|
-
objectSyncMap,
|
|
162
136
|
};
|
|
163
137
|
|
|
164
138
|
try {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getActiveClient } from './activeClient';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { fetchLinkPreview } from '@amityco/ts-sdk'
|
|
6
|
+
* const { title, description, imageUrl } = fetchLinkPreview('https://www.example.com/')
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @param url the url to fetch link preview
|
|
11
|
+
* @returns A {@link Amity.LinkPreview} instance
|
|
12
|
+
*
|
|
13
|
+
* @category Client API
|
|
14
|
+
* */
|
|
15
|
+
|
|
16
|
+
export const fetchLinkPreview = async (url: string): Promise<Amity.LinkPreview> => {
|
|
17
|
+
const client = getActiveClient();
|
|
18
|
+
|
|
19
|
+
let fetchUrl = url;
|
|
20
|
+
|
|
21
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
22
|
+
fetchUrl = `https://${url}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { data } = await client.http.get<Amity.LinkPreview>(
|
|
26
|
+
`/api/v1/link-preview?url=${encodeURIComponent(fetchUrl)}`,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
};
|
package/src/client/api/index.ts
CHANGED
package/src/core/model/index.ts
CHANGED
|
@@ -30,7 +30,6 @@ const createMessageOptimistic = <T extends Amity.MessageContentType>(
|
|
|
30
30
|
bundle: createMessageParam<T>,
|
|
31
31
|
): Amity.InternalMessage | undefined => {
|
|
32
32
|
const client = getActiveClient();
|
|
33
|
-
const { objectSyncMap } = client;
|
|
34
33
|
|
|
35
34
|
if (!client.cache) return;
|
|
36
35
|
|
|
@@ -90,8 +89,6 @@ const createMessageOptimistic = <T extends Amity.MessageContentType>(
|
|
|
90
89
|
|
|
91
90
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
92
91
|
|
|
93
|
-
objectSyncMap.set(message.messageId, undefined);
|
|
94
|
-
|
|
95
92
|
fireEvent('local.message.created', { messages: [message] });
|
|
96
93
|
|
|
97
94
|
return message;
|
|
@@ -123,7 +120,6 @@ export const createMessage = async <T extends Amity.MessageContentType>(
|
|
|
123
120
|
): Promise<Amity.Cached<Amity.Message>> => {
|
|
124
121
|
const client = getActiveClient();
|
|
125
122
|
|
|
126
|
-
const { objectSyncMap } = client;
|
|
127
123
|
client.log('message/createMessage', bundle);
|
|
128
124
|
|
|
129
125
|
const optimisticData = createMessageOptimistic<T>(bundle);
|
|
@@ -137,9 +133,6 @@ export const createMessage = async <T extends Amity.MessageContentType>(
|
|
|
137
133
|
referenceId,
|
|
138
134
|
});
|
|
139
135
|
|
|
140
|
-
objectSyncMap.set(referenceId, payload.messages[0].messageId);
|
|
141
|
-
objectSyncMap.set(payload.messages[0].messageId, referenceId);
|
|
142
|
-
|
|
143
136
|
const data = await prepareMessagePayload(payload);
|
|
144
137
|
const { messages } = data;
|
|
145
138
|
|
|
@@ -4,7 +4,7 @@ import { pullFromCache, pushToCache } from '~/cache/api';
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
import { getActiveClient } from '~/client';
|
|
6
6
|
import { MessagePaginationController } from './MessagePaginationController';
|
|
7
|
-
import {
|
|
7
|
+
import { getResolver } from '~/core/model';
|
|
8
8
|
|
|
9
9
|
export class MessageQueryStreamController extends QueryStreamController<
|
|
10
10
|
Amity.MessagePayload,
|
|
@@ -50,7 +50,7 @@ export class MessageQueryStreamController extends QueryStreamController<
|
|
|
50
50
|
) {
|
|
51
51
|
if (refresh) {
|
|
52
52
|
pushToCache(this.cacheKey, {
|
|
53
|
-
data:
|
|
53
|
+
data: response.messages.map(getResolver('message')),
|
|
54
54
|
query: this.query,
|
|
55
55
|
});
|
|
56
56
|
} else {
|
|
@@ -62,8 +62,8 @@ export class MessageQueryStreamController extends QueryStreamController<
|
|
|
62
62
|
...collection,
|
|
63
63
|
data:
|
|
64
64
|
direction === 'next'
|
|
65
|
-
? [...new Set([...messages, ...
|
|
66
|
-
: [...new Set([...
|
|
65
|
+
? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
|
|
66
|
+
: [...new Set([...response.messages.map(getResolver('message')), ...messages])],
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
-
import {
|
|
3
|
-
import { isLocalId } from '~/core/model';
|
|
2
|
+
import { queryCache } from '~/cache/api/queryCache';
|
|
4
3
|
|
|
5
4
|
export const getMessageFromMainDB = (messageId: string): Amity.InternalMessage | undefined => {
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
const message = pullFromCache<Amity.InternalMessage>(['message', 'get', messageId])?.data;
|
|
6
|
+
if (message) return message;
|
|
8
7
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
: objectSyncMap.get(messageId) ?? messageId;
|
|
12
|
-
|
|
13
|
-
return pullFromCache<Amity.InternalMessage>(['message', 'get', resolvedMessageId])?.data;
|
|
8
|
+
const messages = queryCache<Amity.InternalMessage>(['message', 'get']);
|
|
9
|
+
return messages?.find(({ data }) => data.messageId === messageId)?.data;
|
|
14
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pullFromCache } from '~/cache/api';
|
|
1
|
+
import { pullFromCache, queryCache } from '~/cache/api';
|
|
2
2
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
3
|
import { getMessageMarkers } from '~/marker/api/getMessageMarkers';
|
|
4
4
|
import { prepareMessagePayloadForCache } from '~/reactionRepository/utils/prepareMessagePayloadForCache';
|
|
@@ -8,27 +8,22 @@ import { MessageContentType } from '~/@types';
|
|
|
8
8
|
import { convertFromRaw as convertSubChannelFromRaw } from '~/subChannelRepository/utils/convertSubChannelFromRaw';
|
|
9
9
|
import { updateSubChannelCache } from '~/subChannelRepository/utils/updateSubChannelCache';
|
|
10
10
|
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
11
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
12
|
-
import { isLocalId } from '~/core/model';
|
|
13
11
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
12
|
+
const mergePayloadWithLocal = (payload: Amity.RawMessage) => {
|
|
13
|
+
const localMessage = queryCache<Amity.InternalMessage>(['message', 'get'])?.find(
|
|
14
|
+
({ data }) => data.messageId === payload.messageId,
|
|
15
|
+
)?.data;
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
referenceId: isLocalId(payload.messageId)
|
|
29
|
-
? payload.messageId
|
|
30
|
-
: objectSyncMap.get(payload.messageId),
|
|
31
|
-
};
|
|
17
|
+
if (localMessage) {
|
|
18
|
+
return {
|
|
19
|
+
...localMessage,
|
|
20
|
+
...payload,
|
|
21
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
22
|
+
referenceId: localMessage.referenceId ?? payload.referenceId,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return payload;
|
|
32
27
|
};
|
|
33
28
|
|
|
34
29
|
export function convertFromRaw(
|
|
@@ -36,7 +31,7 @@ export function convertFromRaw(
|
|
|
36
31
|
reactors?: Amity.InternalReactor[],
|
|
37
32
|
event?: keyof Amity.MqttMessageEvents,
|
|
38
33
|
): Amity.InternalMessage {
|
|
39
|
-
const
|
|
34
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
40
35
|
|
|
41
36
|
const {
|
|
42
37
|
channelPublicId,
|
|
@@ -52,7 +47,7 @@ export function convertFromRaw(
|
|
|
52
47
|
messageId,
|
|
53
48
|
creatorId,
|
|
54
49
|
...rest
|
|
55
|
-
} =
|
|
50
|
+
} = mergeMessage;
|
|
56
51
|
|
|
57
52
|
let cache: Amity.CacheEntry<Amity.Message> | undefined;
|
|
58
53
|
|
package/src/utils/event.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
3
|
-
import { isLocalId } from '~/core/model';
|
|
4
2
|
|
|
5
3
|
export const convertEventPayload =
|
|
6
4
|
<
|
|
@@ -18,23 +16,8 @@ export const convertEventPayload =
|
|
|
18
16
|
return sourceModel;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
* 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.
|
|
26
|
-
* 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.
|
|
27
|
-
*/
|
|
28
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp] as unknown as string)
|
|
29
|
-
? sourceModel[sourceModelProp]
|
|
30
|
-
: objectSyncMap.get(sourceModel[sourceModelProp] as unknown as string) ??
|
|
31
|
-
sourceModel[sourceModelProp];
|
|
32
|
-
|
|
33
|
-
const model = pullFromCache<DestinationModel>([
|
|
34
|
-
destinationDomain,
|
|
35
|
-
'get',
|
|
36
|
-
`${resolvedId}`,
|
|
37
|
-
])?.data;
|
|
19
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
20
|
+
const model = pullFromCache<DestinationModel>(cacheKey)?.data;
|
|
38
21
|
|
|
39
22
|
if (!model) return;
|
|
40
23
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localReferenceId.d.ts","sourceRoot":"","sources":["../../../src/core/model/localReferenceId.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,OAAQ,MAAM,YAEnC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getMessageIdentifierIds.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/getMessageIdentifierIds.ts"],"names":[],"mappings":"AAoBA,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,EAAE,YAgBnE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* To check if an id is a local referenceId, the id must start with 'LOCAL_'.
|
|
3
|
-
*
|
|
4
|
-
* Example: LOCAL_155f5158-281a-4a9d-a445-9243138d2041
|
|
5
|
-
*
|
|
6
|
-
* @param id as string
|
|
7
|
-
* @returns true if the id is a local referenceId, false otherwise
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export const isLocalId = (id: string) => {
|
|
11
|
-
return id.startsWith('LOCAL_');
|
|
12
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
-
import { isLocalId } from '~/core/model';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
* To get message identifier ids used as a cache key for the each message.
|
|
6
|
-
* These ids are used to store in the query stream and use to get messages from cache.
|
|
7
|
-
*
|
|
8
|
-
* The query stream data keeps the message identifier ids as follows:
|
|
9
|
-
* ['server_message_id_1', 'server_message_id_2', 'LOCAL_message_id_1', 'LOCAL_message_id_2']
|
|
10
|
-
*
|
|
11
|
-
* Example use case: Message created locally and then created on the server.
|
|
12
|
-
*
|
|
13
|
-
* 1. Message created locally has `LOCAL_message_id_2` as referenceId.
|
|
14
|
-
* 2. The `message.created` event will be fired from server with message payload that has no the referenceId.
|
|
15
|
-
* 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.
|
|
16
|
-
* 4. The SDK use this identifier ids to check if the message is already in the query stream before appending it.
|
|
17
|
-
*
|
|
18
|
-
* @param The raw message payload from server response
|
|
19
|
-
* @returns The identifier ids of the messages
|
|
20
|
-
*/
|
|
21
|
-
export function getMessageIdentifierIds(messages: Amity.RawMessage[]) {
|
|
22
|
-
const client = getActiveClient();
|
|
23
|
-
const { objectSyncMap } = client;
|
|
24
|
-
|
|
25
|
-
return messages
|
|
26
|
-
.map(message => {
|
|
27
|
-
/* NOTE: This logic is used to get identifier id for each message.
|
|
28
|
-
*
|
|
29
|
-
* if messageId is a local id, use it as identifier id else get identifier id from objectSyncMap.
|
|
30
|
-
* if find referenceId in objectSyncMap, this means this message is a local created message. The identifier id will be local message id.
|
|
31
|
-
* 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.
|
|
32
|
-
*/
|
|
33
|
-
if (isLocalId(message.messageId)) return message.messageId;
|
|
34
|
-
return objectSyncMap.get(message.messageId) ?? message.messageId;
|
|
35
|
-
})
|
|
36
|
-
.filter(Boolean);
|
|
37
|
-
}
|