@amityco/ts-sdk 6.11.2-e853528.0 → 6.12.1-06d644c.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/channelRepsitory/api/markAsRead.d.ts.map +1 -1
- package/dist/index.cjs.js +61 -23
- package/dist/index.esm.js +61 -23
- package/dist/index.umd.js +4 -4
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts +1 -1
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannel.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannels.d.ts.map +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channelRepsitory/api/markAsRead.ts +6 -2
- package/src/marker/events/onSubChannelMarkerUpdated.ts +2 -2
- package/src/subChannelRepository/observers/getSubChannel.ts +22 -4
- package/src/subChannelRepository/observers/getSubChannels.ts +40 -25
- package/src/subChannelRepository/utils/updateSubChannelCache.ts +1 -1
- package/src/userRepository/api/isUserFlaggedByMe.ts +5 -9
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @category SubChannelMarker Events
|
|
15
15
|
*/
|
|
16
|
-
export declare const onSubChannelMarkerUpdated: (callback: Amity.Listener<Amity.SubChannelMarker>) => Amity.Unsubscriber;
|
|
16
|
+
export declare const onSubChannelMarkerUpdated: (callback: Amity.Listener<Amity.SubChannelMarker[]>) => Amity.Unsubscriber;
|
|
17
17
|
//# sourceMappingURL=onSubChannelMarkerUpdated.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onSubChannelMarkerUpdated.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onSubChannelMarkerUpdated.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,aAC1B,MAAM,QAAQ,CAAC,MAAM,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"onSubChannelMarkerUpdated.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onSubChannelMarkerUpdated.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,aAC1B,MAAM,QAAQ,CAAC,MAAM,gBAAgB,EAAE,CAAC,KACjD,MAAM,YAaR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubChannel.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/observers/getSubChannel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSubChannel.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/observers/getSubChannel.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,iBACV,MAAM,UAAU,CAAC,cAAc,CAAC,YACpC,MAAM,kBAAkB,CAAC,MAAM,UAAU,CAAC,KACnD,MAAM,YAmJR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubChannels.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/observers/getSubChannels.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,WACjB,MAAM,wBAAwB,YAC5B,MAAM,sBAAsB,CAAC,MAAM,UAAU,CAAC,WAC/C,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"getSubChannels.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/observers/getSubChannels.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,WACjB,MAAM,wBAAwB,YAC5B,MAAM,sBAAsB,CAAC,MAAM,UAAU,CAAC,WAC/C,MAAM,oBAAoB,eAoPpC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ```js
|
|
3
3
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
4
|
-
* const isFlagged = await UserRepository.isUserFlaggedByMe(
|
|
4
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
|
|
5
5
|
* ```
|
|
6
6
|
*
|
|
7
7
|
* @param userId The ID of the thing to check a report to.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUserFlaggedByMe.d.ts","sourceRoot":"","sources":["../../../src/userRepository/api/isUserFlaggedByMe.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,iBAAiB,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"isUserFlaggedByMe.d.ts","sourceRoot":"","sources":["../../../src/userRepository/api/isUserFlaggedByMe.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,iBAAiB,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,CASrF,CAAC"}
|
package/package.json
CHANGED
|
@@ -37,15 +37,15 @@ export const markAsRead = async (channelId: Amity.Channel['channelId']): Promise
|
|
|
37
37
|
} = data;
|
|
38
38
|
|
|
39
39
|
const cachedAt = client.cache && Date.now();
|
|
40
|
-
|
|
41
40
|
const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
41
|
+
const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
42
42
|
|
|
43
43
|
if (client.cache)
|
|
44
44
|
ingestInCache(
|
|
45
45
|
{
|
|
46
46
|
userMarkers: convertUserMarkerResponse(userMarkersPayload),
|
|
47
47
|
userEntityMarkers: channelMarkers,
|
|
48
|
-
userFeedMarkers:
|
|
48
|
+
userFeedMarkers: subChannelMarkers,
|
|
49
49
|
...rest,
|
|
50
50
|
},
|
|
51
51
|
{ cachedAt },
|
|
@@ -55,5 +55,9 @@ export const markAsRead = async (channelId: Amity.Channel['channelId']): Promise
|
|
|
55
55
|
userEntityMarkers: channelMarkers,
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
fireEvent('local.subChannelMarker.updated', {
|
|
59
|
+
userFeedMarkers: subChannelMarkers,
|
|
60
|
+
});
|
|
61
|
+
|
|
58
62
|
return true;
|
|
59
63
|
};
|
|
@@ -17,12 +17,12 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
17
17
|
* @category SubChannelMarker Events
|
|
18
18
|
*/
|
|
19
19
|
export const onSubChannelMarkerUpdated = (
|
|
20
|
-
callback: Amity.Listener<Amity.SubChannelMarker>,
|
|
20
|
+
callback: Amity.Listener<Amity.SubChannelMarker[]>,
|
|
21
21
|
): Amity.Unsubscriber => {
|
|
22
22
|
const client = getActiveClient();
|
|
23
23
|
|
|
24
24
|
const filter = (payload: Amity.Events['local.subChannelMarker.updated']) => {
|
|
25
|
-
callback(payload.userFeedMarkers
|
|
25
|
+
callback(payload.userFeedMarkers);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
return createEventSubscriber(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onSubChannelMarkerFetched } from '~/marker/events';
|
|
1
|
+
import { onSubChannelMarkerFetched, onSubChannelMarkerUpdated } from '~/marker/events';
|
|
2
2
|
import { convertEventPayload } from '~/utils/event';
|
|
3
3
|
import { liveObject } from '~/utils/liveObject';
|
|
4
4
|
import { getSubChannel as _getSubChannel } from '../api/getSubChannel';
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { getActiveClient } from '~/client';
|
|
15
15
|
import { getSubChannelMessagePreviewWithUser } from '~/messagePreview/utils';
|
|
16
16
|
import { isEqual } from '~/utils/isEqual';
|
|
17
|
+
import { updateSubChannelCache } from '../utils/updateSubChannelCache';
|
|
17
18
|
|
|
18
19
|
/* begin_public_function
|
|
19
20
|
id: subchannel.get
|
|
@@ -89,6 +90,25 @@ export const getSubChannel = (
|
|
|
89
90
|
},
|
|
90
91
|
onSubChannelDeleted,
|
|
91
92
|
convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel'),
|
|
93
|
+
callback => {
|
|
94
|
+
return onSubChannelMarkerUpdated(subChannelMarkers => {
|
|
95
|
+
const isTargetSubChannel = subChannelMarkers.find(
|
|
96
|
+
({ feedId }) => feedId === subChannelId,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!isTargetSubChannel) return;
|
|
100
|
+
|
|
101
|
+
const subChannel = pullFromCache<Amity.SubChannel>([
|
|
102
|
+
'subChannel',
|
|
103
|
+
'get',
|
|
104
|
+
subChannelId,
|
|
105
|
+
])?.data;
|
|
106
|
+
|
|
107
|
+
if (!subChannel) return;
|
|
108
|
+
|
|
109
|
+
callback(subChannel);
|
|
110
|
+
});
|
|
111
|
+
},
|
|
92
112
|
convertEventPayload(
|
|
93
113
|
(callback: Amity.Listener<Amity.Message>) => {
|
|
94
114
|
const updateMessagePreview = async (message: Amity.Message) => {
|
|
@@ -106,9 +126,7 @@ export const getSubChannel = (
|
|
|
106
126
|
])?.data;
|
|
107
127
|
if (!subChannel) return;
|
|
108
128
|
|
|
109
|
-
|
|
110
|
-
pushToCache(['subChannel', 'get', subChannelId], {
|
|
111
|
-
...subChannel,
|
|
129
|
+
updateSubChannelCache(subChannel, {
|
|
112
130
|
messagePreviewId: message.messageId,
|
|
113
131
|
});
|
|
114
132
|
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
runQuery,
|
|
8
8
|
sortByLastActivity,
|
|
9
9
|
} from '~/core/query';
|
|
10
|
-
import { onSubChannelMarkerFetched } from '~/marker/events';
|
|
10
|
+
import { onSubChannelMarkerFetched, onSubChannelMarkerUpdated } from '~/marker/events';
|
|
11
11
|
import {
|
|
12
12
|
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
13
13
|
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
@@ -99,27 +99,37 @@ export const getSubChannels = (
|
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
const realtimeRouter =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
snapshot.data = [subChannel, ...snapshot.data];
|
|
113
|
-
} else {
|
|
114
|
-
snapshot.data = snapshot.data.map(x =>
|
|
115
|
-
x.subChannelId === subChannel.subChannelId ? subChannel : x,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
102
|
+
const realtimeRouter =
|
|
103
|
+
(action: Amity.ChannelActionType) => (subChannel: Amity.SubChannel | Amity.SubChannel[]) => {
|
|
104
|
+
if (!Array.isArray(subChannel)) {
|
|
105
|
+
if (
|
|
106
|
+
params.channelId !== subChannel.channelId ||
|
|
107
|
+
!snapshot ||
|
|
108
|
+
!shouldDispatchCollection(snapshot.data, subChannel, action)
|
|
109
|
+
) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
118
112
|
|
|
119
|
-
|
|
113
|
+
if (action === 'onCreate') {
|
|
114
|
+
snapshot.data = [subChannel, ...snapshot.data];
|
|
115
|
+
} else {
|
|
116
|
+
snapshot.data = snapshot.data.map(x =>
|
|
117
|
+
x.subChannelId === subChannel.subChannelId ? subChannel : x,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
snapshot.data = snapshot.data.map(convertGetterPropsToStatic);
|
|
122
|
+
} else {
|
|
123
|
+
/**
|
|
124
|
+
* In case of `onUpdate` event with array of subChannel
|
|
125
|
+
*/
|
|
126
|
+
snapshot.data = snapshot.data.map(x => {
|
|
127
|
+
const targetSubChannel = subChannel.find(item => item.subChannelId === x.subChannelId);
|
|
128
|
+
return targetSubChannel ?? x;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
responder(snapshot);
|
|
132
|
+
};
|
|
123
133
|
|
|
124
134
|
const onFetch = () => {
|
|
125
135
|
const subChannels = snapshot ? snapshot.data : [];
|
|
@@ -213,11 +223,16 @@ export const getSubChannels = (
|
|
|
213
223
|
'feedId',
|
|
214
224
|
'subChannel',
|
|
215
225
|
)(realtimeRouter('onUpdate')),
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
onSubChannelMarkerUpdated((subChannelMarkers: Amity.SubChannelMarker[]) => {
|
|
227
|
+
const subChannelWithMarkerUpdated =
|
|
228
|
+
subChannelMarkers
|
|
229
|
+
.map(({ feedId }) => pullFromCache<Amity.SubChannel>(['subChannel', 'get', feedId])!)
|
|
230
|
+
.filter(Boolean)
|
|
231
|
+
.map(({ data }) => data) ?? [];
|
|
232
|
+
|
|
233
|
+
if (subChannelWithMarkerUpdated.length === 0) return;
|
|
234
|
+
realtimeRouter('onUpdate')(subChannelWithMarkerUpdated);
|
|
235
|
+
}),
|
|
221
236
|
convertEventPayload(
|
|
222
237
|
(callback: Amity.Listener<Amity.Message>) => {
|
|
223
238
|
const updateMessagePreview = async (message: Amity.Message) => {
|
|
@@ -6,7 +6,7 @@ export function updateSubChannelCache(
|
|
|
6
6
|
params: Partial<Amity.SubChannel>,
|
|
7
7
|
) {
|
|
8
8
|
pushToCache(
|
|
9
|
-
['
|
|
9
|
+
['subChannel', 'get', subChannel.subChannelId],
|
|
10
10
|
// eslint-disable-next-line prefer-object-spread
|
|
11
11
|
Object.assign(shallowClone(subChannel), params),
|
|
12
12
|
);
|
|
@@ -7,7 +7,7 @@ import { synchronousWSCall } from '~/core/transports';
|
|
|
7
7
|
/**
|
|
8
8
|
* ```js
|
|
9
9
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
10
|
-
* const isFlagged = await UserRepository.isUserFlaggedByMe(
|
|
10
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* @param userId The ID of the thing to check a report to.
|
|
@@ -20,14 +20,10 @@ export const isUserFlaggedByMe = async (userId: Amity.User['userId']): Promise<b
|
|
|
20
20
|
const client = getActiveClient();
|
|
21
21
|
client.log('user/isUserFlaggedByMe', userId);
|
|
22
22
|
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
isFlagByMe?: boolean;
|
|
27
|
-
}>(client, 'user.isFlagByMe', {
|
|
28
|
-
userId,
|
|
29
|
-
})) ?? {};
|
|
23
|
+
const {
|
|
24
|
+
data: { isFlagByMe },
|
|
25
|
+
} = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
|
|
30
26
|
|
|
31
|
-
return
|
|
27
|
+
return isFlagByMe;
|
|
32
28
|
};
|
|
33
29
|
/* end_public_function */
|