@amityco/ts-sdk-react-native 6.30.2-bc5ef81.0 → 6.30.2
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/core/payload.d.ts +12 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +10 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/createComment.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/deleteComment.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/index.cjs.js +255 -27
- package/dist/index.esm.js +255 -27
- package/dist/index.umd.js +3 -3
- package/dist/postRepository/api/deletePost.d.ts.map +1 -1
- package/dist/postRepository/observers/enums.d.ts +12 -0
- package/dist/postRepository/observers/enums.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts +1 -1
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.d.ts +11 -0
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/semanticSearch/utils.d.ts +3 -0
- package/dist/postRepository/observers/semanticSearch/utils.d.ts.map +1 -0
- package/dist/postRepository/observers/semanticSearchPosts.d.ts +10 -0
- package/dist/postRepository/observers/semanticSearchPosts.d.ts.map +1 -0
- package/dist/postRepository/utils/payload.d.ts +2 -1
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +11 -0
- package/src/@types/domains/post.ts +17 -0
- package/src/commentRepository/api/createComment.ts +1 -0
- package/src/commentRepository/api/deleteComment.ts +1 -0
- package/src/commentRepository/internalApi/createComment.ts +1 -0
- package/src/commentRepository/internalApi/deleteComment.ts +1 -0
- package/src/core/query/filtering.ts +6 -22
- package/src/postRepository/api/deletePost.ts +1 -0
- package/src/postRepository/observers/enums.ts +11 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +1 -1
- package/src/postRepository/observers/getPosts/PostQueryStreamController.ts +1 -1
- package/src/postRepository/observers/index.ts +1 -0
- package/src/postRepository/observers/semanticSearch/SemanticSearchPostLiveCollectionController.ts +199 -0
- package/src/postRepository/observers/semanticSearch/SemanticSearchPostPaginationController.ts +27 -0
- package/src/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.ts +111 -0
- package/src/postRepository/observers/semanticSearch/utils.ts +12 -0
- package/src/postRepository/observers/semanticSearchPosts.ts +42 -0
- package/src/postRepository/utils/payload.ts +17 -2
package/src/postRepository/observers/semanticSearch/SemanticSearchPostQueryStreamController.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { getActiveClient } from '~/client';
|
|
5
|
+
import { EnumPostActions } from '../enums';
|
|
6
|
+
import { preparePostResponse } from './utils';
|
|
7
|
+
|
|
8
|
+
export class SemanticSearchPostQueryStreamController extends QueryStreamController<
|
|
9
|
+
Amity.SemanticSearchPostPayload,
|
|
10
|
+
Amity.SemanticSearchPostLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
13
|
+
|
|
14
|
+
private preparePayload: (
|
|
15
|
+
response: Amity.SemanticSearchPostPayload,
|
|
16
|
+
) => Amity.ProcessedSemanticSearchPostPayload;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
query: Amity.SemanticSearchPostLiveCollection,
|
|
20
|
+
cacheKey: string[],
|
|
21
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
22
|
+
preparePayload: (
|
|
23
|
+
response: Amity.SemanticSearchPostPayload,
|
|
24
|
+
) => Amity.ProcessedSemanticSearchPostPayload,
|
|
25
|
+
) {
|
|
26
|
+
super(query, cacheKey);
|
|
27
|
+
this.notifyChange = notifyChange;
|
|
28
|
+
this.preparePayload = preparePayload;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async saveToMainDB(response: Amity.SemanticSearchPostPayload) {
|
|
32
|
+
const processedPayload = this.preparePayload(response);
|
|
33
|
+
|
|
34
|
+
const client = getActiveClient();
|
|
35
|
+
const cachedAt = client.cache && Date.now();
|
|
36
|
+
|
|
37
|
+
if (client.cache) {
|
|
38
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
appendToQueryStream(
|
|
43
|
+
response: Amity.SemanticSearchPostPayload & Partial<Amity.Pagination>,
|
|
44
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
45
|
+
refresh = false,
|
|
46
|
+
) {
|
|
47
|
+
if (refresh) {
|
|
48
|
+
pushToCache(this.cacheKey, {
|
|
49
|
+
data: preparePostResponse(response),
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
|
|
53
|
+
|
|
54
|
+
const posts = collection?.data ?? [];
|
|
55
|
+
|
|
56
|
+
pushToCache(this.cacheKey, {
|
|
57
|
+
...collection,
|
|
58
|
+
data: [...new Set([...posts, ...preparePostResponse(response)])],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
reactor(action: EnumPostActions) {
|
|
64
|
+
return (post: Amity.InternalPost) => {
|
|
65
|
+
const collection = pullFromCache<Amity.SemanticSearchPostLiveCollectionCache>(
|
|
66
|
+
this.cacheKey,
|
|
67
|
+
)?.data;
|
|
68
|
+
|
|
69
|
+
if (!collection) return;
|
|
70
|
+
|
|
71
|
+
if (post.parentPostId && post.isDeleted) {
|
|
72
|
+
const parentSemanticSearchPost = pullFromCache<Amity.InternalPost>([
|
|
73
|
+
'post',
|
|
74
|
+
'get',
|
|
75
|
+
post.parentPostId,
|
|
76
|
+
])?.data;
|
|
77
|
+
|
|
78
|
+
if (!parentSemanticSearchPost || parentSemanticSearchPost?.targetId !== this.query.targetId)
|
|
79
|
+
return;
|
|
80
|
+
|
|
81
|
+
parentSemanticSearchPost.children = parentSemanticSearchPost.children.filter(
|
|
82
|
+
childId => childId !== post.postId,
|
|
83
|
+
);
|
|
84
|
+
pushToCache(['post', 'get', parentSemanticSearchPost.postId], parentSemanticSearchPost);
|
|
85
|
+
} else {
|
|
86
|
+
if (this.query.targetId !== post.targetId) return;
|
|
87
|
+
if (this.query.targetType !== post.targetType) return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
91
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
95
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
pushToCache(this.cacheKey, collection);
|
|
99
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
subscribeRTE(
|
|
104
|
+
createSubscriber: {
|
|
105
|
+
fn: (reactor: (post: Amity.InternalPost) => void) => Amity.Unsubscriber;
|
|
106
|
+
action: EnumPostActions;
|
|
107
|
+
}[],
|
|
108
|
+
) {
|
|
109
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function preparePostResponse(response: Amity.SemanticSearchPostPayload) {
|
|
2
|
+
return response.posts.map(post => {
|
|
3
|
+
const postScore = response.searchResult.find(result => result.postId === post.postId)!;
|
|
4
|
+
return `${post.postId}:${postScore.score}`;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getPostIdsFromCache(cacheData?: string[]) {
|
|
9
|
+
return (cacheData ?? []).map(postIdWithScore => {
|
|
10
|
+
return postIdWithScore.split(':')[0];
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { dropFromCache } from '~/cache/api';
|
|
3
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
4
|
+
import { SemanticSearchPostLiveCollectionController } from './semanticSearch/SemanticSearchPostLiveCollectionController';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* search posts by semantic search
|
|
8
|
+
*
|
|
9
|
+
* @returns the associated pinned post(s)
|
|
10
|
+
*
|
|
11
|
+
* @category Posts Live Collection
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export const semanticSearchPosts = (
|
|
15
|
+
params: Amity.LiveCollectionParams<Amity.SemanticSearchPostLiveCollection>,
|
|
16
|
+
callback: Amity.LiveCollectionCallback<Amity.Post>,
|
|
17
|
+
config?: Amity.LiveCollectionConfig,
|
|
18
|
+
) => {
|
|
19
|
+
const { log, cache } = getActiveClient();
|
|
20
|
+
|
|
21
|
+
if (!cache) {
|
|
22
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const timestamp = Date.now();
|
|
26
|
+
log(`semanticSearchPosts(tmpid: ${timestamp}) > listen`);
|
|
27
|
+
|
|
28
|
+
const semanticSearchPostLiveCollection = new SemanticSearchPostLiveCollectionController(
|
|
29
|
+
params,
|
|
30
|
+
callback,
|
|
31
|
+
);
|
|
32
|
+
const disposers = semanticSearchPostLiveCollection.startSubscription();
|
|
33
|
+
|
|
34
|
+
const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
|
|
35
|
+
|
|
36
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
log(`semanticSearchPosts(tmpid: ${timestamp}) > dispose`);
|
|
40
|
+
disposers.forEach(fn => fn());
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { addPostSetting } from '~/communityRepository/utils';
|
|
2
2
|
import { updateMembershipStatus } from '~/communityRepository/utils/communityWithMembership';
|
|
3
3
|
|
|
4
|
-
export const preparePostPayload = (
|
|
4
|
+
export const preparePostPayload = (payload: Amity.PostPayload): Amity.ProcessedPostPayload => {
|
|
5
|
+
const { posts: postsData, ...postPayload } = payload;
|
|
6
|
+
|
|
5
7
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
6
8
|
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
7
9
|
|
|
@@ -23,7 +25,7 @@ export const preparePostPayload = (postPayload: Amity.PostPayload): Amity.Proces
|
|
|
23
25
|
);
|
|
24
26
|
|
|
25
27
|
// feed type
|
|
26
|
-
const posts =
|
|
28
|
+
const posts = postsData.map(post => {
|
|
27
29
|
const feedType = postPayload.feeds.find(feed => feed.feedId === post.feedId)?.feedType;
|
|
28
30
|
|
|
29
31
|
return {
|
|
@@ -39,3 +41,16 @@ export const preparePostPayload = (postPayload: Amity.PostPayload): Amity.Proces
|
|
|
39
41
|
communityUsers: mappedCommunityUsers,
|
|
40
42
|
};
|
|
41
43
|
};
|
|
44
|
+
|
|
45
|
+
export const prepareSemanticSearchPostPayload = ({
|
|
46
|
+
searchResult,
|
|
47
|
+
polls,
|
|
48
|
+
...postPayload
|
|
49
|
+
}: Amity.SemanticSearchPostPayload): Amity.ProcessedSemanticSearchPostPayload => {
|
|
50
|
+
const processedPostPayload = preparePostPayload(postPayload);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...processedPostPayload,
|
|
54
|
+
polls,
|
|
55
|
+
};
|
|
56
|
+
};
|