@amityco/ts-sdk 0.0.1-beta.26 → 0.0.1-beta.27
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/events.d.ts +7 -7
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +3 -5
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +2 -1
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +10 -0
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts +16 -0
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/index.d.ts +2 -0
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/api/unbanChannelMembers.d.ts +16 -0
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -0
- package/dist/comment/observers/liveComments.d.ts.map +1 -1
- package/dist/follow/api/follow.d.ts.map +1 -1
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
- package/dist/follow/api/queryFollowers.d.ts +4 -4
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +4 -4
- package/dist/follow/api/queryFollowings.d.ts.map +1 -1
- package/dist/follow/api/utils.d.ts +4 -4
- package/dist/follow/api/utils.d.ts.map +1 -1
- package/dist/follow/events/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +345 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +340 -20
- package/dist/index.umd.js +4 -4
- package/dist/reaction/api/queryReactions.d.ts +1 -6
- package/dist/reaction/api/queryReactions.d.ts.map +1 -1
- package/dist/reaction/events/index.d.ts +3 -0
- package/dist/reaction/events/index.d.ts.map +1 -1
- package/dist/reaction/events/onReactorAdded.d.ts +19 -0
- package/dist/reaction/events/onReactorAdded.d.ts.map +1 -0
- package/dist/reaction/events/onReactorRemoved.d.ts +19 -0
- package/dist/reaction/events/onReactorRemoved.d.ts.map +1 -0
- package/dist/reaction/observers/index.d.ts +2 -0
- package/dist/reaction/observers/index.d.ts.map +1 -0
- package/dist/reaction/observers/liveReactions.d.ts +22 -0
- package/dist/reaction/observers/liveReactions.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/events.ts +7 -7
- package/src/@types/core/payload.ts +5 -6
- package/src/@types/domains/follow.ts +3 -1
- package/src/@types/domains/reaction.ts +17 -0
- package/src/channel/api/banChannelMembers.ts +41 -0
- package/src/channel/api/index.ts +3 -0
- package/src/channel/api/unbanChannelMembers.ts +41 -0
- package/src/comment/observers/liveComments.ts +4 -1
- package/src/follow/api/acceptFollower.ts +1 -1
- package/src/follow/api/declineFollower.ts +1 -1
- package/src/follow/api/follow.ts +1 -4
- package/src/follow/api/getFollowInfo.ts +8 -5
- package/src/follow/api/queryFollowers.ts +5 -4
- package/src/follow/api/queryFollowings.ts +5 -4
- package/src/follow/api/unfollow.ts +1 -1
- package/src/follow/api/utils.ts +10 -10
- package/src/follow/events/utils.ts +9 -6
- package/src/index.ts +1 -0
- package/src/reaction/api/queryReactions.ts +6 -6
- package/src/reaction/events/index.ts +4 -0
- package/src/reaction/events/onReactorAdded.ts +80 -0
- package/src/reaction/events/onReactorRemoved.ts +85 -0
- package/src/reaction/observers/index.ts +1 -0
- package/src/reaction/observers/liveReactions.ts +142 -0
|
@@ -15,10 +15,5 @@
|
|
|
15
15
|
* @reaction Reaction API
|
|
16
16
|
* @async
|
|
17
17
|
* */
|
|
18
|
-
export declare const queryReactions: (query:
|
|
19
|
-
referenceId: Amity.Reaction['referenceId'];
|
|
20
|
-
referenceType: Amity.Reaction['referenceType'];
|
|
21
|
-
reactionName?: Amity.Reaction['reactionName'];
|
|
22
|
-
page?: Amity.Page<string>;
|
|
23
|
-
}) => Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page<string>>>;
|
|
18
|
+
export declare const queryReactions: (query: Amity.QueryReactions) => Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page<string>>>;
|
|
24
19
|
//# sourceMappingURL=queryReactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryReactions.d.ts","sourceRoot":"","sources":["../../../src/reaction/api/queryReactions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queryReactions.d.ts","sourceRoot":"","sources":["../../../src/reaction/api/queryReactions.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,cAAc,UAClB,MAAM,cAAc,KAC1B,QAAQ,MAAM,KAAK,CAAC,MAAM,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CA2B9D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onReactorAdded } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onReactorAdded('post', postId, reactor => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Reactor} has been added
|
|
10
|
+
*
|
|
11
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
12
|
+
* @param {string} referenceId
|
|
13
|
+
* @param callback The function to call when the event was fired
|
|
14
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
|
+
*
|
|
16
|
+
* @category Events
|
|
17
|
+
* */
|
|
18
|
+
export declare const onReactorAdded: (referenceType: Amity.ReactableType, referenceId: Amity.Reaction['referenceId'], callback: Amity.Listener<Amity.Reactor>) => Amity.Unsubscriber;
|
|
19
|
+
//# sourceMappingURL=onReactorAdded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onReactorAdded.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/onReactorAdded.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,cAAc,kBACV,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,YAChC,MAAM,QAAQ,CAAC,MAAM,OAAO,CAAC,KACtC,MAAM,YAsDR,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onReactorRemoved } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onReactorRemoved('post', postId, reactor => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Reactor} has been removed
|
|
10
|
+
*
|
|
11
|
+
* @param {@link Amity.ReactableType} referenceType
|
|
12
|
+
* @param {string} referenceId
|
|
13
|
+
* @param callback The function to call when the event was fired
|
|
14
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
|
+
*
|
|
16
|
+
* @category Events
|
|
17
|
+
* */
|
|
18
|
+
export declare const onReactorRemoved: (referenceType: Amity.ReactableType, referenceId: Amity.Reaction['referenceId'], callback: Amity.Listener<Amity.Reactor>) => Amity.Unsubscriber;
|
|
19
|
+
//# sourceMappingURL=onReactorRemoved.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onReactorRemoved.d.ts","sourceRoot":"","sources":["../../../src/reaction/events/onReactorRemoved.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;KAgBK;AACL,eAAO,MAAM,gBAAgB,kBACZ,MAAM,aAAa,eACrB,MAAM,QAAQ,CAAC,aAAa,CAAC,YAChC,MAAM,QAAQ,CAAC,MAAM,OAAO,CAAC,KACtC,MAAM,YA2DR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reaction/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { liveReactions } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* let reactions = []
|
|
6
|
+
* const unsub = liveReactions({
|
|
7
|
+
* referenceId: Amity.Reaction['referenceId'],
|
|
8
|
+
* referenceType: Amity.Reaction['referenceType'],
|
|
9
|
+
* }, response => merge(reactions, response.data))
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Observe all mutations on a list of {@link Amity.Reaction} for a given target object
|
|
13
|
+
*
|
|
14
|
+
* @param referenceType the type of the target
|
|
15
|
+
* @param referenceId the ID of the target
|
|
16
|
+
* @param callback the function to call when new data are available
|
|
17
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
18
|
+
*
|
|
19
|
+
* @category Reactions Live Collection
|
|
20
|
+
*/
|
|
21
|
+
export declare const liveReactions: (params: Amity.ReactionLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Reactor>, config?: Amity.LiveCollectionConfig) => Amity.Unsubscriber;
|
|
22
|
+
//# sourceMappingURL=liveReactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liveReactions.d.ts","sourceRoot":"","sources":["../../../src/reaction/observers/liveReactions.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,WAChB,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAuGR,CAAC"}
|
package/package.json
CHANGED
|
@@ -101,13 +101,13 @@ declare global {
|
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
type MqttFollowMessageEvents = {
|
|
104
|
-
'follow.created': Amity.
|
|
105
|
-
'follow.requested': Amity.
|
|
106
|
-
'follow.accepted': Amity.
|
|
107
|
-
'follow.unfollowed': Amity.
|
|
108
|
-
'follow.requestCanceled': Amity.
|
|
109
|
-
'follow.requestDeclined': Amity.
|
|
110
|
-
'follow.followerDeleted': Amity.
|
|
104
|
+
'follow.created': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
105
|
+
'follow.requested': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
106
|
+
'follow.accepted': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
107
|
+
'follow.unfollowed': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
108
|
+
'follow.requestCanceled': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
109
|
+
'follow.requestDeclined': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
110
|
+
'follow.followerDeleted': Amity.FollowersPayload | Amity.FollowStatusPayload;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
type MqttMessageEvents = MqttCommunityMessageEvents &
|
|
@@ -112,17 +112,16 @@ declare global {
|
|
|
112
112
|
|
|
113
113
|
type GlobalFeedPayload = Amity.PostPayload;
|
|
114
114
|
|
|
115
|
-
type FollowersPayload = {
|
|
116
|
-
follows: Amity.FollowStatus[];
|
|
117
|
-
} & UserPayload;
|
|
118
|
-
|
|
119
115
|
type FollowStatusPayload = {
|
|
120
116
|
follows: Amity.FollowStatus[];
|
|
121
117
|
};
|
|
122
118
|
|
|
123
|
-
type
|
|
124
|
-
follows: Amity.FollowStatus[];
|
|
119
|
+
type FollowInfoMePayload = {
|
|
125
120
|
followCounts: Amity.FollowCount[];
|
|
126
121
|
};
|
|
122
|
+
|
|
123
|
+
type FollowersPayload = Amity.FollowStatusPayload & UserPayload;
|
|
124
|
+
|
|
125
|
+
type FollowInfoPayload = FollowInfoMePayload & Amity.FollowStatusPayload;
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -2,10 +2,12 @@ export {};
|
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
|
+
type FollowStatusType = 'all' | 'pending' | 'accepted' | 'none';
|
|
6
|
+
|
|
5
7
|
type FollowStatus = {
|
|
6
8
|
from: Amity.User['userId'];
|
|
7
9
|
to: Amity.User['userId'];
|
|
8
|
-
status:
|
|
10
|
+
status: Exclude<FollowStatusType, 'all'>;
|
|
9
11
|
} & Amity.CreatedAt &
|
|
10
12
|
Amity.UpdatedAt;
|
|
11
13
|
|
|
@@ -4,6 +4,8 @@ declare global {
|
|
|
4
4
|
namespace Amity {
|
|
5
5
|
type ReactableType = 'message' | 'post' | 'comment';
|
|
6
6
|
|
|
7
|
+
type ReactionActionType = 'onAdded' | 'onRemoved';
|
|
8
|
+
|
|
7
9
|
type Reactor = {
|
|
8
10
|
reactionId: string;
|
|
9
11
|
reactionName: string;
|
|
@@ -19,11 +21,26 @@ declare global {
|
|
|
19
21
|
|
|
20
22
|
latestReaction?: Amity.Reaction & {
|
|
21
23
|
eventName: 'add' | 'remove';
|
|
24
|
+
userDisplayName: string;
|
|
22
25
|
};
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
type ReactionQuery = {
|
|
26
29
|
reactors: Reactor[];
|
|
27
30
|
} & Amity.Relationship<ReactableType>;
|
|
31
|
+
|
|
32
|
+
type QueryReactions = {
|
|
33
|
+
referenceId: Amity.Reaction['referenceId'];
|
|
34
|
+
referenceType: Amity.Reaction['referenceType'];
|
|
35
|
+
reactionName?: Amity.Reaction['reactionName'];
|
|
36
|
+
page?: Amity.Page<string>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type ReactionLiveCollection = Amity.LiveCollectionParams<Omit<QueryReactions, 'page'>>;
|
|
40
|
+
|
|
41
|
+
type ReactionLiveCollectionCache = Amity.LiveCollectionCache<
|
|
42
|
+
Amity.Reactor['reactionId'],
|
|
43
|
+
Pick<QueryReactions, 'page'>
|
|
44
|
+
>;
|
|
28
45
|
}
|
|
29
46
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { banChannelMembers } from '@amityco/ts-sdk'
|
|
8
|
+
*
|
|
9
|
+
* await banChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param channelId of {@link Amity.Channel} from which the users should be banned
|
|
13
|
+
* @param userIds of the {@link Amity.User}'s to be banned
|
|
14
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
15
|
+
*
|
|
16
|
+
* @category Channel API
|
|
17
|
+
* @async
|
|
18
|
+
* */
|
|
19
|
+
export const banChannelMembers = async (
|
|
20
|
+
channelId: Amity.Channel['channelId'],
|
|
21
|
+
userIds: Amity.User['userId'][],
|
|
22
|
+
): Promise<Amity.Cached<Amity.Membership<'channel'>[]>> => {
|
|
23
|
+
const client = getActiveClient();
|
|
24
|
+
client.log('channel/banChannelMembers', { userIds, channelId });
|
|
25
|
+
|
|
26
|
+
const payload = await client.http.put<Amity.ChannelPayload>(
|
|
27
|
+
`/api/v3/channels/${channelId}/users/ban`,
|
|
28
|
+
{
|
|
29
|
+
userIds,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const cachedAt = client.cache && Date.now();
|
|
34
|
+
if (client.cache) ingestInCache(payload.data, { cachedAt });
|
|
35
|
+
|
|
36
|
+
const { channelUsers } = payload.data;
|
|
37
|
+
return {
|
|
38
|
+
data: channelUsers?.filter(user => user.membership === 'banned')!,
|
|
39
|
+
cachedAt,
|
|
40
|
+
};
|
|
41
|
+
};
|
package/src/channel/api/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { unbanChannelMembers } from '@amityco/ts-sdk'
|
|
8
|
+
*
|
|
9
|
+
* await unbanChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param channelId of {@link Amity.Channel} where the users should be unbanned
|
|
13
|
+
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
14
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
15
|
+
*
|
|
16
|
+
* @category Channel API
|
|
17
|
+
* @async
|
|
18
|
+
* */
|
|
19
|
+
export const unbanChannelMembers = async (
|
|
20
|
+
channelId: Amity.Channel['channelId'],
|
|
21
|
+
userIds: Amity.User['userId'][],
|
|
22
|
+
): Promise<Amity.Cached<Amity.Membership<'channel'>[]>> => {
|
|
23
|
+
const client = getActiveClient();
|
|
24
|
+
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
25
|
+
|
|
26
|
+
const payload = await client.http.put<Amity.ChannelPayload>(
|
|
27
|
+
`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`,
|
|
28
|
+
{
|
|
29
|
+
userIds,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const cachedAt = client.cache && Date.now();
|
|
34
|
+
if (client.cache) ingestInCache(payload.data, { cachedAt });
|
|
35
|
+
|
|
36
|
+
const { channelUsers } = payload.data;
|
|
37
|
+
return {
|
|
38
|
+
data: channelUsers?.filter(user => user.membership === 'member')!,
|
|
39
|
+
cachedAt,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -130,7 +130,10 @@ export const liveComments = (
|
|
|
130
130
|
|
|
131
131
|
runQuery(
|
|
132
132
|
query,
|
|
133
|
-
({ data: result, error, loading, prevPage
|
|
133
|
+
({ data: result, error, loading, prevPage, nextPage }) => {
|
|
134
|
+
// depend on sortBy value we have two different pagination type
|
|
135
|
+
const page = queryParams.sortBy ? nextPage : prevPage;
|
|
136
|
+
|
|
134
137
|
const data = {
|
|
135
138
|
loading,
|
|
136
139
|
error,
|
package/src/follow/api/follow.ts
CHANGED
|
@@ -32,10 +32,7 @@ export const follow = async (
|
|
|
32
32
|
ingestInCache(data, { cachedAt });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
fireEvent(
|
|
36
|
-
data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested',
|
|
37
|
-
data.follows[0],
|
|
38
|
-
);
|
|
35
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data);
|
|
39
36
|
|
|
40
37
|
return {
|
|
41
38
|
data: data.follows[0],
|
|
@@ -27,15 +27,18 @@ export const getFollowInfo = async (
|
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('follow/getFollowInfo', userId);
|
|
29
29
|
|
|
30
|
-
const { data } = await client.http.get<Amity.FollowInfoPayload>(
|
|
30
|
+
const { data } = await client.http.get<Amity.FollowInfoMePayload | Amity.FollowInfoPayload>(
|
|
31
31
|
client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`,
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const cachedAt = client.cache && Date.now();
|
|
35
|
-
const followInfo =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const followInfo =
|
|
36
|
+
'follows' in data
|
|
37
|
+
? {
|
|
38
|
+
...data.followCounts[0],
|
|
39
|
+
status: data.follows?.[0]?.status,
|
|
40
|
+
}
|
|
41
|
+
: data.followCounts[0];
|
|
39
42
|
|
|
40
43
|
if (client.cache) {
|
|
41
44
|
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
@@ -16,9 +16,10 @@ import { queryFollows } from './utils';
|
|
|
16
16
|
*/
|
|
17
17
|
export const queryFollowers = async (query: {
|
|
18
18
|
userId: Amity.User['userId'];
|
|
19
|
-
status?:
|
|
20
|
-
page?: Amity.
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> =>
|
|
19
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
20
|
+
page?: Amity.PageRaw;
|
|
21
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
|
+
queryFollows('followers', query);
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* ```js
|
|
@@ -35,5 +36,5 @@ export const queryFollowers = async (query: {
|
|
|
35
36
|
*/
|
|
36
37
|
queryFollowers.locally = (
|
|
37
38
|
query: Parameters<typeof queryFollowers>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
39
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
40
|
queryFollows.locally('followers', query);
|
|
@@ -16,9 +16,10 @@ import { queryFollows } from './utils';
|
|
|
16
16
|
*/
|
|
17
17
|
export const queryFollowings = async (query: {
|
|
18
18
|
userId: Amity.User['userId'];
|
|
19
|
-
status?: Exclude<Amity.
|
|
20
|
-
page?: Amity.
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> =>
|
|
19
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
20
|
+
page?: Amity.PageRaw;
|
|
21
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
|
+
queryFollows('following', query);
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* ```js
|
|
@@ -35,5 +36,5 @@ export const queryFollowings = async (query: {
|
|
|
35
36
|
*/
|
|
36
37
|
queryFollowings.locally = (
|
|
37
38
|
query: Parameters<typeof queryFollowings>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
39
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
40
|
queryFollows.locally('following', query);
|
package/src/follow/api/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
|
-
import {
|
|
2
|
+
import { toPageRaw, toToken } from '~/core/query';
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
5
5
|
import { getResolver } from '~/core/model';
|
|
@@ -8,10 +8,10 @@ export const queryFollows = async (
|
|
|
8
8
|
key: 'followers' | 'following',
|
|
9
9
|
query: {
|
|
10
10
|
userId: Amity.User['userId'];
|
|
11
|
-
status?:
|
|
12
|
-
page?: Amity.
|
|
11
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
12
|
+
page?: Amity.PageRaw;
|
|
13
13
|
},
|
|
14
|
-
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> => {
|
|
14
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> => {
|
|
15
15
|
const client = getActiveClient();
|
|
16
16
|
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ export const queryFollows = async (
|
|
|
22
22
|
{
|
|
23
23
|
params: {
|
|
24
24
|
...params,
|
|
25
|
-
token: toToken(page, '
|
|
25
|
+
token: toToken(page, 'afterbeforeraw'),
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
28
|
);
|
|
@@ -43,8 +43,8 @@ export const queryFollows = async (
|
|
|
43
43
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const nextPage =
|
|
47
|
-
const prevPage =
|
|
46
|
+
const nextPage = toPageRaw(paging.next);
|
|
47
|
+
const prevPage = toPageRaw(paging.previous);
|
|
48
48
|
|
|
49
49
|
return { data: follows, cachedAt, prevPage, nextPage };
|
|
50
50
|
};
|
|
@@ -52,7 +52,7 @@ export const queryFollows = async (
|
|
|
52
52
|
queryFollows.locally = (
|
|
53
53
|
key: Parameters<typeof queryFollows>[0],
|
|
54
54
|
query: Parameters<typeof queryFollows>[1],
|
|
55
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined => {
|
|
55
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined => {
|
|
56
56
|
const client = getActiveClient();
|
|
57
57
|
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
58
58
|
|
|
@@ -73,8 +73,8 @@ queryFollows.locally = (
|
|
|
73
73
|
.filter(Boolean)
|
|
74
74
|
.map(({ data }) => data);
|
|
75
75
|
|
|
76
|
-
const prevPage =
|
|
77
|
-
const nextPage =
|
|
76
|
+
const prevPage = toPageRaw(data?.paging.previous);
|
|
77
|
+
const nextPage = toPageRaw(data?.paging.next);
|
|
78
78
|
|
|
79
79
|
return follows.length === data?.follows?.length
|
|
80
80
|
? { data: follows, cachedAt, prevPage, nextPage }
|
|
@@ -9,11 +9,11 @@ export const createFollowEventSubscriber = (
|
|
|
9
9
|
) => {
|
|
10
10
|
const client = getActiveClient();
|
|
11
11
|
|
|
12
|
-
const filter = (payload: Amity.
|
|
12
|
+
const filter = (payload: Amity.FollowersPayload | Amity.FollowStatusPayload) => {
|
|
13
13
|
if (!client.cache) {
|
|
14
|
-
callback(payload);
|
|
14
|
+
callback(payload.follows[0]);
|
|
15
15
|
} else {
|
|
16
|
-
ingestInCache(
|
|
16
|
+
ingestInCache(payload);
|
|
17
17
|
|
|
18
18
|
const queries = [
|
|
19
19
|
...(queryCache(['followers', 'query']) ?? []),
|
|
@@ -21,11 +21,14 @@ export const createFollowEventSubscriber = (
|
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
queries
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
.filter(
|
|
25
|
+
({ key }) =>
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to,
|
|
28
|
+
)
|
|
26
29
|
.forEach(({ key, data }) => upsertInCache(key, data as any, { cachedAt: -1 }));
|
|
27
30
|
|
|
28
|
-
callback(payload);
|
|
31
|
+
callback(payload.follows[0]);
|
|
29
32
|
}
|
|
30
33
|
};
|
|
31
34
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
|
|
3
3
|
import { toToken, toPageRaw } from '~/core/query';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* ```js
|
|
@@ -19,12 +20,9 @@ import { toToken, toPageRaw } from '~/core/query';
|
|
|
19
20
|
* @reaction Reaction API
|
|
20
21
|
* @async
|
|
21
22
|
* */
|
|
22
|
-
export const queryReactions = async (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
reactionName?: Amity.Reaction['reactionName'];
|
|
26
|
-
page?: Amity.Page<string>;
|
|
27
|
-
}): Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page<string>>> => {
|
|
23
|
+
export const queryReactions = async (
|
|
24
|
+
query: Amity.QueryReactions,
|
|
25
|
+
): Promise<Amity.Paged<Amity.ReactionQuery, Amity.Page<string>>> => {
|
|
28
26
|
const client = getActiveClient();
|
|
29
27
|
client.log('reaction/queryReactions', query);
|
|
30
28
|
|
|
@@ -45,6 +43,8 @@ export const queryReactions = async (query: {
|
|
|
45
43
|
const { paging, ...payload } = data;
|
|
46
44
|
const { reactions } = payload;
|
|
47
45
|
|
|
46
|
+
ingestInCache({ ...payload, reactions: reactions[0].reactors });
|
|
47
|
+
|
|
48
48
|
const nextPage = toPageRaw(paging.next);
|
|
49
49
|
const prevPage = toPageRaw(paging.previous);
|
|
50
50
|
|