@amityco/ts-sdk 6.5.7-d7d687d.0 → 6.5.7-e5b9646.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/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/onOnline.d.ts +2 -0
- package/dist/client/utils/onOnline.d.ts.map +1 -0
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/index.cjs.js +43 -46
- package/dist/index.esm.js +43 -46
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/client/utils/markerSyncEngine.ts +5 -13
- package/src/client/utils/onOnline.ts +26 -0
- package/src/core/query/paging.ts +9 -6
- package/src/messageRepository/events/onMessageCreated.ts +0 -9
- package/src/messageRepository/observers/getMessages.ts +3 -1
- package/src/subChannelRepository/api/querySubChannels.ts +1 -1
- package/src/subChannelRepository/observers/getSubChannels.ts +1 -1
- package/src/subChannelRepository/utils/markReadEngine.ts +7 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,aACjB,MAAM,QAAQ,CAAC,MAAM,OAAO,CAAC,sBAEtC,MAAM,YAwBR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessages.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessages.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YA+GR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markReadEngine.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/markReadEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markReadEngine.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/markReadEngine.ts"],"names":[],"mappings":"AAmDA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,kBAYxC,CAAC;AAsCF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,iBAAwB,MAAM,UAAU,CAAC,cAAc,CAAC,qBAchF,CAAC;AAMF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,iBAAkB,MAAM,UAAU,CAAC,cAAc,CAAC,qBAIzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amityco/ts-sdk",
|
|
3
|
-
"version": "6.5.7-
|
|
3
|
+
"version": "6.5.7-e5b9646.0",
|
|
4
4
|
"license": "CC-BY-ND-4.0",
|
|
5
5
|
"author": "amity.co <developers@amity.co> (https://amity.co)",
|
|
6
6
|
"description": "Amity Social Cloud Typescript SDK",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@react-native-async-storage/async-storage": "^1.17.7",
|
|
57
|
+
"@react-native-community/netinfo": "^9.4.1",
|
|
57
58
|
"agentkeepalive": "^4.2.1",
|
|
58
59
|
"axios": "^1.2.3",
|
|
59
60
|
"debug": "^4.3.4",
|
|
@@ -63,5 +64,8 @@
|
|
|
63
64
|
"react-native-uuid": "^2.0.1",
|
|
64
65
|
"socket.io-client": "2.2.0",
|
|
65
66
|
"ts-jest": "^28.0.3"
|
|
67
|
+
},
|
|
68
|
+
"optionalDependencies": {
|
|
69
|
+
"react-native-web": "^0.19.7"
|
|
66
70
|
}
|
|
67
71
|
}
|
|
@@ -13,6 +13,7 @@ import { onSubChannelCreated, onSubChannelDeleted } from '~/subChannelRepository
|
|
|
13
13
|
import { isUnreadCountSupport } from '~/subChannelRepository/utils';
|
|
14
14
|
|
|
15
15
|
import { markerSync } from '../api';
|
|
16
|
+
import { onOnline } from './onOnline';
|
|
16
17
|
|
|
17
18
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
18
19
|
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
@@ -103,18 +104,6 @@ export const markerSyncTrigger = async () => {
|
|
|
103
104
|
isWaitingForResponse = false;
|
|
104
105
|
};
|
|
105
106
|
|
|
106
|
-
/**
|
|
107
|
-
* the event callback when app is back to online
|
|
108
|
-
*/
|
|
109
|
-
const onOnline = () => {
|
|
110
|
-
// should add RESUME to the event to trigger marker syncing again
|
|
111
|
-
const callback = () => events.push(Amity.MarkerSyncEvent.RESUME);
|
|
112
|
-
|
|
113
|
-
window.addEventListener('online', callback);
|
|
114
|
-
|
|
115
|
-
return () => window.removeEventListener('online', callback);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
107
|
const registerEventListeners = () => {
|
|
119
108
|
// based on the tech spec design, we designed a fetch marker in case of these events
|
|
120
109
|
// - new message
|
|
@@ -122,7 +111,10 @@ const registerEventListeners = () => {
|
|
|
122
111
|
// - remove channel
|
|
123
112
|
// - app going to online again after offline
|
|
124
113
|
disposers.push(
|
|
125
|
-
onOnline()
|
|
114
|
+
onOnline(() => {
|
|
115
|
+
// should add RESUME to the event to trigger marker syncing again
|
|
116
|
+
events.push(Amity.MarkerSyncEvent.RESUME);
|
|
117
|
+
}),
|
|
126
118
|
|
|
127
119
|
onMessageCreated(
|
|
128
120
|
message => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const onOnline = (callback: () => void) => {
|
|
2
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
3
|
+
window.addEventListener('online', callback);
|
|
4
|
+
return () => window.removeEventListener('online', callback);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
8
|
+
document.addEventListener('online', callback);
|
|
9
|
+
return () => document.removeEventListener('online', callback);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// @TODO: Please update code below to follow our coding conventions and our TS rules
|
|
13
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
|
|
15
|
+
const NetInfo = require('@react-native-community/netinfo');
|
|
16
|
+
|
|
17
|
+
return NetInfo.addEventListener((state: { isConnected: boolean }) => {
|
|
18
|
+
if (!state.isConnected) return;
|
|
19
|
+
callback();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Handle unsupported environment
|
|
24
|
+
console.error('Unsupported environment');
|
|
25
|
+
return () => console.error('Unsupported environment');
|
|
26
|
+
};
|
package/src/core/query/paging.ts
CHANGED
|
@@ -80,19 +80,22 @@ export const toToken = (
|
|
|
80
80
|
"before" or "after" value. if that would change,
|
|
81
81
|
we'd need to move toward a more simple: `!paging.before`
|
|
82
82
|
*/
|
|
83
|
-
if (
|
|
83
|
+
if (paging?.before) {
|
|
84
84
|
payload = {
|
|
85
|
+
...payload,
|
|
85
86
|
before: paging.before,
|
|
86
|
-
last: paging.limit,
|
|
87
87
|
};
|
|
88
|
-
}
|
|
88
|
+
}
|
|
89
|
+
if (paging?.after) {
|
|
89
90
|
payload = {
|
|
91
|
+
...payload,
|
|
90
92
|
after: paging.after,
|
|
91
|
-
first: paging.limit,
|
|
92
93
|
};
|
|
93
|
-
}
|
|
94
|
+
}
|
|
95
|
+
if (!Number.isNaN(Number(paging?.limit))) {
|
|
94
96
|
payload = {
|
|
95
|
-
|
|
97
|
+
...payload,
|
|
98
|
+
limit: paging.limit,
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
} else if (style === 'afterbeforeraw') {
|
|
@@ -2,7 +2,6 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
-
import { upsertInCache } from '~/cache/api';
|
|
6
5
|
import { prepareMessagePayload } from '../utils';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -31,15 +30,7 @@ export const onMessageCreated = (
|
|
|
31
30
|
const payload = await prepareMessagePayload(rawPayload);
|
|
32
31
|
const message = payload.messages[0];
|
|
33
32
|
|
|
34
|
-
// Update in cache
|
|
35
33
|
ingestInCache(payload);
|
|
36
|
-
|
|
37
|
-
// Update lastActivity for Channel and SubChannel
|
|
38
|
-
payload.messages.forEach(({ channelId, subChannelId, createdAt }) => {
|
|
39
|
-
upsertInCache(['channel', 'get', channelId], { lastActivityAt: createdAt });
|
|
40
|
-
upsertInCache(['subChannel', 'get', channelId], { lastActivityAt: createdAt });
|
|
41
|
-
});
|
|
42
|
-
|
|
43
34
|
callback(message);
|
|
44
35
|
};
|
|
45
36
|
|
|
@@ -99,7 +99,9 @@ export const getMessages = (
|
|
|
99
99
|
|
|
100
100
|
if (params.subChannelId !== message?.subChannelId || !collection) return;
|
|
101
101
|
|
|
102
|
-
collection.data
|
|
102
|
+
if (!collection.data.includes(message.messageId)) {
|
|
103
|
+
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
104
|
+
}
|
|
103
105
|
|
|
104
106
|
pushToCache(cacheKey, collection);
|
|
105
107
|
|
|
@@ -111,7 +111,7 @@ export const getSubChannels = (
|
|
|
111
111
|
|
|
112
112
|
const query = createQuery(querySubChannels, {
|
|
113
113
|
...queryParams,
|
|
114
|
-
page: snapshot?.params.page
|
|
114
|
+
page: snapshot?.params.page ? { ...snapshot?.params.page, limit } : { limit },
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
runQuery(
|
|
@@ -2,6 +2,7 @@ import { onSessionStateChange } from '~/client/events/onSessionStateChange';
|
|
|
2
2
|
import { getMarkedMessageTopic, subscribeTopic } from '~/core/subscription';
|
|
3
3
|
import { setIntervalTask } from '~/utils/timer';
|
|
4
4
|
|
|
5
|
+
import { onOnline } from '~/client/utils/onOnline';
|
|
5
6
|
import { getSubChannel } from '../api/getSubChannel';
|
|
6
7
|
import { readingAPI } from '../api/readingAPI';
|
|
7
8
|
import { startReadingAPI } from '../api/startReadingAPI';
|
|
@@ -68,20 +69,6 @@ export const markReadEngineOnLoginHandler = () => {
|
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
71
|
|
|
71
|
-
/**
|
|
72
|
-
* the event callback when app is back to online
|
|
73
|
-
*/
|
|
74
|
-
const onOnline = () => {
|
|
75
|
-
const callback = () => {
|
|
76
|
-
// Start reading the reading subChannel again when resume from offline state
|
|
77
|
-
startReadingFromReadingList();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
window.addEventListener('online', callback);
|
|
81
|
-
|
|
82
|
-
return () => window.removeEventListener('online', callback);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
72
|
const getParentChannelId = async (
|
|
86
73
|
subChannelId: Amity.SubChannel['subChannelId'],
|
|
87
74
|
): Promise<Amity.SubChannel['channelId']> => {
|
|
@@ -96,7 +83,12 @@ const getParentChannelId = async (
|
|
|
96
83
|
};
|
|
97
84
|
|
|
98
85
|
const registerEventListeners = () => {
|
|
99
|
-
disposers.push(
|
|
86
|
+
disposers.push(
|
|
87
|
+
onOnline(() => {
|
|
88
|
+
// Start reading the reading subChannel again when resume from offline state
|
|
89
|
+
startReadingFromReadingList();
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
100
92
|
};
|
|
101
93
|
|
|
102
94
|
const registerTopicSubscribers = async (subChannelId: Amity.SubChannel['subChannelId']) => {
|