@amityco/ts-sdk 7.7.1-9bf1d358.0 → 7.7.1-a266e7d8.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/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +5 -3
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/searchPostsByHashtag.d.ts +16 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/searchPostsByHashtag.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/searchPostsByHashtag.js +62 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/searchPostsByHashtag.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.js +3 -4
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostPaginationController.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js +135 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js +65 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/domains/post.d.ts +5 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.esm.js +3 -3
- package/dist/index.umd.js +1 -1
- package/dist/postRepository/api/index.d.ts +1 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/api/searchPostsByHashtag.d.ts +16 -0
- package/dist/postRepository/api/searchPostsByHashtag.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
- package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/domains/post.ts +9 -3
- package/src/postRepository/api/index.ts +2 -0
- package/src/postRepository/api/searchPostsByHashtag.ts +77 -0
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +0 -7
- package/src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts +198 -0
- package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +47 -0
- package/src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts +99 -0
- package/src/postRepository/observers/index.ts +1 -0
- package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAE/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AAEpC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAE/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AAEpC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { searchPostsByHashtag } from '@amityco/ts-sdk'
|
|
4
|
+
* const { data: posts, prevPage, nextPage } = await searchPostsByHashtag({ hashtags: ['amity'], limit: 10 });
|
|
5
|
+
* ```
|
|
6
|
+
*
|
|
7
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
8
|
+
*
|
|
9
|
+
* @param query The query parameters
|
|
10
|
+
* @returns posts
|
|
11
|
+
*
|
|
12
|
+
* @category Post API
|
|
13
|
+
* @async
|
|
14
|
+
*/
|
|
15
|
+
export declare const searchPostsByHashtag: (query: Amity.QueryPostsWithHashtags) => Promise<Amity.Cached<Amity.PageToken<Amity.Post>>>;
|
|
16
|
+
//# sourceMappingURL=searchPostsByHashtag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchPostsByHashtag.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/searchPostsByHashtag.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,UACxB,MAAM,sBAAsB,KAClC,QAAQ,MAAM,MAAM,CAAC,MAAM,SAAS,CAAC,MAAM,IAAI,CAAC,CAAC,CAkDnD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostPaginationController.d.ts","sourceRoot":"","sources":["../../../../src/postRepository/observers/getPosts/PostPaginationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"PostPaginationController.d.ts","sourceRoot":"","sources":["../../../../src/postRepository/observers/getPosts/PostPaginationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAGlF,qBAAa,wBAAyB,SAAQ,oBAAoB,CAChE,MAAM,EACN,KAAK,CAAC,kBAAkB,CACzB;IACO,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS;CAkClF"}
|
package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SearchPostPaginationController } from './SearchPostPaginationController';
|
|
2
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
3
|
+
export declare class SearchPostLiveCollectionController extends LiveCollectionController<'post', Amity.PostLiveCollection, Amity.Post, SearchPostPaginationController> {
|
|
4
|
+
private queryStreamController;
|
|
5
|
+
private query;
|
|
6
|
+
constructor(query: Amity.PostLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Post>);
|
|
7
|
+
protected setup(): void;
|
|
8
|
+
protected persistModel(queryPayload: Amity.PostPayload & Amity.Pagination): Promise<void>;
|
|
9
|
+
protected persistQueryStream({ response, direction, refresh, }: Amity.LiveCollectionPersistQueryStreamParams<'post'>): void;
|
|
10
|
+
startSubscription(): Amity.Unsubscriber[];
|
|
11
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams): void;
|
|
12
|
+
applyFilter(data: Amity.InternalPost[]): Amity.InternalPost<any>[];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SearchPostLiveCollectionController.d.ts.map
|
package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchPostLiveCollectionController.d.ts","sourceRoot":"","sources":["../../../../src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AA+B1F,qBAAa,kCAAmC,SAAQ,wBAAwB,CAC9E,MAAM,EACN,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,IAAI,EACV,8BAA8B,CAC/B;IACC,OAAO,CAAC,qBAAqB,CAAkC;IAE/D,OAAO,CAAC,KAAK,CAA2B;gBAE5B,KAAK,EAAE,KAAK,CAAC,kBAAkB,EAAE,QAAQ,EAAE,KAAK,CAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC;IAmB/F,SAAS,CAAC,KAAK;cAUC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,UAAU;IAI/E,SAAS,CAAC,kBAAkB,CAAC,EAC3B,QAAQ,EACR,SAAS,EACT,OAAO,GACR,EAAE,KAAK,CAAC,sCAAsC,CAAC,MAAM,CAAC;IAIvD,iBAAiB;IA0DjB,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,0BAA0B;IAsBzE,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,EAAE;CA+BvC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
export declare class SearchPostPaginationController extends PaginationController<'post', Amity.PostLiveCollection> {
|
|
3
|
+
getRequest(queryParams: Amity.PostLiveCollection, token: string | undefined): Promise<Amity.PostPayload<any> & Amity.Pagination>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=SearchPostPaginationController.d.ts.map
|
package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchPostPaginationController.d.ts","sourceRoot":"","sources":["../../../../src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAIlF,qBAAa,8BAA+B,SAAQ,oBAAoB,CACtE,MAAM,EACN,KAAK,CAAC,kBAAkB,CACzB;IACO,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS;CAsClF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { EnumPostActions } from '../enums';
|
|
3
|
+
export declare class SearchPostQueryStreamController extends QueryStreamController<Amity.PostPayload, Amity.PostLiveCollection> {
|
|
4
|
+
private notifyChange;
|
|
5
|
+
private preparePayload;
|
|
6
|
+
constructor(query: Amity.PostLiveCollection, cacheKey: string[], notifyChange: (params: Amity.LiveCollectionNotifyParams) => void, preparePayload: (response: Amity.PostPayload) => Amity.ProcessedPostPayload);
|
|
7
|
+
saveToMainDB(response: Amity.PostPayload): Promise<void>;
|
|
8
|
+
appendToQueryStream(response: Amity.PostPayload & Partial<Amity.Pagination>, direction: Amity.LiveCollectionPageDirection, refresh?: boolean): void;
|
|
9
|
+
reactor(action: EnumPostActions): (post: Amity.InternalPost) => void;
|
|
10
|
+
subscribeRTE(createSubscriber: {
|
|
11
|
+
fn: (reactor: (post: Amity.InternalPost) => void) => Amity.Unsubscriber;
|
|
12
|
+
action: EnumPostActions;
|
|
13
|
+
}[]): Amity.Unsubscriber[];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=SearchPostQueryStreamController.d.ts.map
|
package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchPostQueryStreamController.d.ts","sourceRoot":"","sources":["../../../../src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAKpF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,qBAAa,+BAAgC,SAAQ,qBAAqB,CACxE,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,kBAAkB,CACzB;IACC,OAAO,CAAC,YAAY,CAAqD;IAEzE,OAAO,CAAC,cAAc,CAA8D;gBAGlF,KAAK,EAAE,KAAK,CAAC,kBAAkB,EAC/B,QAAQ,EAAE,MAAM,EAAE,EAClB,YAAY,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,0BAA0B,KAAK,IAAI,EAChE,cAAc,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,oBAAoB;IAOvE,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW;IAW9C,mBAAmB,CACjB,QAAQ,EAAE,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EACvD,SAAS,EAAE,KAAK,CAAC,2BAA2B,EAC5C,OAAO,UAAQ;IAkBjB,OAAO,CAAC,MAAM,EAAE,eAAe,UACf,MAAM,YAAY;IA+BlC,YAAY,CACV,gBAAgB,EAAE;QAChB,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,KAAK,IAAI,KAAK,KAAK,CAAC,YAAY,CAAC;QACxE,MAAM,EAAE,eAAe,CAAC;KACzB,EAAE;CAIN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postRepository/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postRepository/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* let posts = []
|
|
6
|
+
* const unsub = PostRepository.searchPostsByHashtag({
|
|
7
|
+
* hashtags: ['amity'],
|
|
8
|
+
* limit: 10,
|
|
9
|
+
* }, response => merge(posts, response.data))
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
13
|
+
*
|
|
14
|
+
* @param params.hashtags the hashtags to search for
|
|
15
|
+
* @param callback the function to call when new data are available
|
|
16
|
+
* @param config
|
|
17
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
18
|
+
*
|
|
19
|
+
* @category Posts Live Collection
|
|
20
|
+
*/
|
|
21
|
+
export declare const searchPostsByHashtag: (params: Amity.PostLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Post>, config?: Amity.LiveCollectionConfig) => Amity.Unsubscriber;
|
|
22
|
+
//# sourceMappingURL=searchPostsByHashtag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchPostsByHashtag.d.ts","sourceRoot":"","sources":["../../../src/postRepository/observers/searchPostsByHashtag.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,KAClC,MAAM,YAqBR,CAAC"}
|
package/package.json
CHANGED
|
@@ -106,19 +106,25 @@ declare global {
|
|
|
106
106
|
matchingOnlyParentPost?: boolean;
|
|
107
107
|
page?: string;
|
|
108
108
|
limit?: number;
|
|
109
|
-
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type QueryPostsWithHashtags = Pick<
|
|
112
|
+
Amity.QueryPosts,
|
|
113
|
+
'dataTypes' | 'matchingOnlyParentPost' | 'sortBy' | 'page' | 'limit'
|
|
114
|
+
> & {
|
|
115
|
+
hashtags: string[];
|
|
110
116
|
};
|
|
111
117
|
|
|
112
118
|
// Omit sortBy explained in asc-3398
|
|
113
119
|
type PostLiveCollection = Amity.LiveCollectionParams<
|
|
114
|
-
Omit<QueryPosts, 'sortBy' | 'page'> & {
|
|
120
|
+
Omit<QueryPosts | QueryPostsWithHashtags, 'sortBy' | 'page'> & {
|
|
115
121
|
sortBy?: 'lastCreated' | 'firstCreated';
|
|
116
122
|
}
|
|
117
123
|
>;
|
|
118
124
|
|
|
119
125
|
type PostLiveCollectionCache = Amity.LiveCollectionCache<
|
|
120
126
|
Amity.InternalPost['postId'],
|
|
121
|
-
Pick<QueryPosts, 'page'>
|
|
127
|
+
Pick<QueryPosts | QueryPostsWithHashtags, 'page'>
|
|
122
128
|
>;
|
|
123
129
|
|
|
124
130
|
type QuerySemanticSearchPosts = {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { pushToCache } from '~/cache/api';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { getResolver } from '~/core/model';
|
|
6
|
+
|
|
7
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
8
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
9
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* ```js
|
|
13
|
+
* import { searchPostsByHashtag } from '@amityco/ts-sdk'
|
|
14
|
+
* const { data: posts, prevPage, nextPage } = await searchPostsByHashtag({ hashtags: ['amity'], limit: 10 });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
18
|
+
*
|
|
19
|
+
* @param query The query parameters
|
|
20
|
+
* @returns posts
|
|
21
|
+
*
|
|
22
|
+
* @category Post API
|
|
23
|
+
* @async
|
|
24
|
+
*/
|
|
25
|
+
export const searchPostsByHashtag = async (
|
|
26
|
+
query: Amity.QueryPostsWithHashtags,
|
|
27
|
+
): Promise<Amity.Cached<Amity.PageToken<Amity.Post>>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('post/queryByHashtag', query);
|
|
30
|
+
|
|
31
|
+
const { page, limit = 10, ...params } = query;
|
|
32
|
+
const { dataTypes, matchingOnlyParentPost, hashtags } = params;
|
|
33
|
+
|
|
34
|
+
const options = (() => {
|
|
35
|
+
if (page) return { token: page };
|
|
36
|
+
if (limit) return { limit };
|
|
37
|
+
|
|
38
|
+
return undefined;
|
|
39
|
+
})();
|
|
40
|
+
|
|
41
|
+
// API-FIX: parameters should be querystring. (1)
|
|
42
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
43
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
44
|
+
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/v5/posts`, {
|
|
45
|
+
params: {
|
|
46
|
+
...params,
|
|
47
|
+
hashtags,
|
|
48
|
+
/*
|
|
49
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
50
|
+
* 1. parent post to store text with dataType=text
|
|
51
|
+
* 2. child post to store dataTypes post data
|
|
52
|
+
*
|
|
53
|
+
* By default, BE queries only parent post
|
|
54
|
+
*/
|
|
55
|
+
matchingOnlyParentPost: matchingOnlyParentPost ?? !dataTypes?.length,
|
|
56
|
+
options,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// API-FIX: backend should answer Amity.Response (2)
|
|
61
|
+
// const { paging, posts } = unwrapPayload(data)
|
|
62
|
+
// unpacking
|
|
63
|
+
const { paging, ...payload } = data;
|
|
64
|
+
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
65
|
+
const { posts } = payload;
|
|
66
|
+
|
|
67
|
+
const cachedAt = client.cache && Date.now();
|
|
68
|
+
|
|
69
|
+
if (client.cache) {
|
|
70
|
+
ingestInCache(paperedPayload, { cachedAt });
|
|
71
|
+
|
|
72
|
+
const cacheKey = ['post', 'query', { ...params, options } as Amity.Serializable];
|
|
73
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
77
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
2
|
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
3
|
-
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
4
3
|
|
|
5
4
|
export class PostPaginationController extends PaginationController<
|
|
6
5
|
'post',
|
|
@@ -9,10 +8,7 @@ export class PostPaginationController extends PaginationController<
|
|
|
9
8
|
async getRequest(queryParams: Amity.PostLiveCollection, token: string | undefined) {
|
|
10
9
|
const {
|
|
11
10
|
limit = COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
12
|
-
includeDeleted,
|
|
13
11
|
matchingOnlyParentPost,
|
|
14
|
-
targetType,
|
|
15
|
-
hashtags,
|
|
16
12
|
...params
|
|
17
13
|
} = queryParams;
|
|
18
14
|
|
|
@@ -29,7 +25,6 @@ export class PostPaginationController extends PaginationController<
|
|
|
29
25
|
{
|
|
30
26
|
params: {
|
|
31
27
|
...params,
|
|
32
|
-
isDeleted: inferIsDeleted(includeDeleted),
|
|
33
28
|
/*
|
|
34
29
|
* when creating post like image, file, video BE will create 2 posts
|
|
35
30
|
* 1. parent post to store text with dataType=text
|
|
@@ -38,8 +33,6 @@ export class PostPaginationController extends PaginationController<
|
|
|
38
33
|
* By default, BE queries only parent post
|
|
39
34
|
*/
|
|
40
35
|
matchingOnlyParentPost: matchingOnlyParentPost ?? !dataTypes?.length,
|
|
41
|
-
targetType,
|
|
42
|
-
...(targetType === 'all' && hashtags && { hashtags }),
|
|
43
36
|
options,
|
|
44
37
|
},
|
|
45
38
|
},
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { SearchPostPaginationController } from './SearchPostPaginationController';
|
|
4
|
+
import { SearchPostQueryStreamController } from './SearchPostQueryStreamController';
|
|
5
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
6
|
+
import {
|
|
7
|
+
onPostCreated,
|
|
8
|
+
onPostUpdated,
|
|
9
|
+
onPostDeleted,
|
|
10
|
+
onPostFlagged,
|
|
11
|
+
onPostUnflagged,
|
|
12
|
+
onPostReactionAdded,
|
|
13
|
+
onPostReactionRemoved,
|
|
14
|
+
onPostApproved,
|
|
15
|
+
onPostDeclined,
|
|
16
|
+
} from '~/postRepository/events';
|
|
17
|
+
import {
|
|
18
|
+
filterByFeedType,
|
|
19
|
+
filterByPostDataTypes,
|
|
20
|
+
filterByPropEquality,
|
|
21
|
+
sortByFirstCreated,
|
|
22
|
+
sortByLastCreated,
|
|
23
|
+
} from '~/core/query';
|
|
24
|
+
import { isNonNullable } from '~/utils';
|
|
25
|
+
import { EnumPostActions } from '../enums';
|
|
26
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
27
|
+
import { preparePostPayload } from '~/postRepository/utils/payload';
|
|
28
|
+
import { convertEventPayload } from '~/utils/event';
|
|
29
|
+
import { onCommentCreated, onCommentDeleted } from '~/commentRepository';
|
|
30
|
+
import { getPost } from '~/postRepository/internalApi/getPost';
|
|
31
|
+
import { onPostUpdatedLocal } from '~/postRepository/events/onPostUpdatedLocal';
|
|
32
|
+
import { onLocalPostReactionAdded } from '~/postRepository/events/onLocalPostReactionAdded';
|
|
33
|
+
import { onLocalPostReactionRemoved } from '~/postRepository/events/onLocalPostReactionRemoved';
|
|
34
|
+
import { onLocalPostDeleted } from '~/postRepository/events/onLocalPostDeleted';
|
|
35
|
+
|
|
36
|
+
export class SearchPostLiveCollectionController extends LiveCollectionController<
|
|
37
|
+
'post',
|
|
38
|
+
Amity.PostLiveCollection,
|
|
39
|
+
Amity.Post,
|
|
40
|
+
SearchPostPaginationController
|
|
41
|
+
> {
|
|
42
|
+
private queryStreamController: SearchPostQueryStreamController;
|
|
43
|
+
|
|
44
|
+
private query: Amity.PostLiveCollection;
|
|
45
|
+
|
|
46
|
+
constructor(query: Amity.PostLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Post>) {
|
|
47
|
+
const queryStreamId = hash(query);
|
|
48
|
+
const cacheKey = ['posts', 'collection', queryStreamId];
|
|
49
|
+
const paginationController = new SearchPostPaginationController(query);
|
|
50
|
+
|
|
51
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
52
|
+
|
|
53
|
+
this.query = query;
|
|
54
|
+
this.queryStreamController = new SearchPostQueryStreamController(
|
|
55
|
+
this.query,
|
|
56
|
+
this.cacheKey,
|
|
57
|
+
this.notifyChange.bind(this),
|
|
58
|
+
preparePostPayload,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
this.callback = callback.bind(this);
|
|
62
|
+
this.loadPage({ initial: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected setup() {
|
|
66
|
+
const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
|
|
67
|
+
if (!collection) {
|
|
68
|
+
pushToCache(this.cacheKey, {
|
|
69
|
+
data: [],
|
|
70
|
+
params: {},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected async persistModel(queryPayload: Amity.PostPayload & Amity.Pagination) {
|
|
76
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected persistQueryStream({
|
|
80
|
+
response,
|
|
81
|
+
direction,
|
|
82
|
+
refresh,
|
|
83
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'post'>) {
|
|
84
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
startSubscription() {
|
|
88
|
+
return this.queryStreamController.subscribeRTE([
|
|
89
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
90
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
91
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
92
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
93
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
94
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
95
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
96
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
97
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
98
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
99
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
100
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
101
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
102
|
+
{
|
|
103
|
+
fn: convertEventPayload(
|
|
104
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
105
|
+
return onCommentCreated(async (comment: Amity.InternalComment) => {
|
|
106
|
+
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(
|
|
107
|
+
this.cacheKey,
|
|
108
|
+
)?.data;
|
|
109
|
+
|
|
110
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
111
|
+
return;
|
|
112
|
+
|
|
113
|
+
await getPost(comment.referenceId);
|
|
114
|
+
callback(comment);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
'referenceId',
|
|
118
|
+
'post',
|
|
119
|
+
),
|
|
120
|
+
action: EnumPostActions.OnPostUpdated,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
fn: convertEventPayload(
|
|
124
|
+
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
125
|
+
return onCommentDeleted(async (comment: Amity.InternalComment) => {
|
|
126
|
+
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(
|
|
127
|
+
this.cacheKey,
|
|
128
|
+
)?.data;
|
|
129
|
+
|
|
130
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
131
|
+
return;
|
|
132
|
+
|
|
133
|
+
await getPost(comment.referenceId);
|
|
134
|
+
callback(comment);
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
'referenceId',
|
|
138
|
+
'post',
|
|
139
|
+
),
|
|
140
|
+
action: EnumPostActions.OnPostUpdated,
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
146
|
+
const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
|
|
147
|
+
if (!collection) return;
|
|
148
|
+
|
|
149
|
+
const data = this.applyFilter(
|
|
150
|
+
collection.data
|
|
151
|
+
.map(id => pullFromCache<Amity.InternalPost>(['post', 'get', id])!)
|
|
152
|
+
.filter(isNonNullable)
|
|
153
|
+
.map(({ data }) => data) ?? [],
|
|
154
|
+
).map(LinkedObject.post);
|
|
155
|
+
|
|
156
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
157
|
+
|
|
158
|
+
this.callback({
|
|
159
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
160
|
+
data,
|
|
161
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
162
|
+
loading,
|
|
163
|
+
error,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
applyFilter(data: Amity.InternalPost[]) {
|
|
168
|
+
let posts = data;
|
|
169
|
+
|
|
170
|
+
if (!this.query.includeDeleted) {
|
|
171
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this.query.tags) {
|
|
175
|
+
posts = posts.filter(p => p.tags?.some(t => this.query.tags?.includes(t)));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this.query.targetType === 'community' && this.query.feedType) {
|
|
179
|
+
posts = filterByFeedType(posts, this.query.feedType);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this.query.dataTypes?.length) {
|
|
183
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
switch (this.query.sortBy) {
|
|
187
|
+
case 'firstCreated':
|
|
188
|
+
posts = posts.sort(sortByFirstCreated);
|
|
189
|
+
break;
|
|
190
|
+
case 'lastCreated':
|
|
191
|
+
default:
|
|
192
|
+
posts = posts.sort(sortByLastCreated);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return posts;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
3
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
4
|
+
|
|
5
|
+
export class SearchPostPaginationController extends PaginationController<
|
|
6
|
+
'post',
|
|
7
|
+
Amity.PostLiveCollection
|
|
8
|
+
> {
|
|
9
|
+
async getRequest(queryParams: Amity.PostLiveCollection, token: string | undefined) {
|
|
10
|
+
const {
|
|
11
|
+
limit = COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
12
|
+
includeDeleted,
|
|
13
|
+
matchingOnlyParentPost,
|
|
14
|
+
hashtags,
|
|
15
|
+
...params
|
|
16
|
+
} = queryParams;
|
|
17
|
+
|
|
18
|
+
const { dataTypes } = params;
|
|
19
|
+
|
|
20
|
+
const baseOptions = {
|
|
21
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const options = token ? { ...baseOptions, token } : { ...baseOptions, limit };
|
|
25
|
+
|
|
26
|
+
const { data: queryResponse } = await this.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
27
|
+
`/api/v1/search/posts`,
|
|
28
|
+
{
|
|
29
|
+
params: {
|
|
30
|
+
...params,
|
|
31
|
+
isDeleted: inferIsDeleted(includeDeleted),
|
|
32
|
+
hashtags,
|
|
33
|
+
/*
|
|
34
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
35
|
+
* 1. parent post to store text with dataType=text
|
|
36
|
+
* 2. child post to store dataTypes post data
|
|
37
|
+
*
|
|
38
|
+
* By default, BE queries only parent post
|
|
39
|
+
*/
|
|
40
|
+
matchingOnlyParentPost: matchingOnlyParentPost ?? !dataTypes?.length,
|
|
41
|
+
options,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
return queryResponse;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { getResolver } from '~/core/model';
|
|
5
|
+
import { getActiveClient } from '~/client';
|
|
6
|
+
import { EnumPostActions } from '../enums';
|
|
7
|
+
|
|
8
|
+
export class SearchPostQueryStreamController extends QueryStreamController<
|
|
9
|
+
Amity.PostPayload,
|
|
10
|
+
Amity.PostLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
13
|
+
|
|
14
|
+
private preparePayload: (response: Amity.PostPayload) => Amity.ProcessedPostPayload;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
query: Amity.PostLiveCollection,
|
|
18
|
+
cacheKey: string[],
|
|
19
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
20
|
+
preparePayload: (response: Amity.PostPayload) => Amity.ProcessedPostPayload,
|
|
21
|
+
) {
|
|
22
|
+
super(query, cacheKey);
|
|
23
|
+
this.notifyChange = notifyChange;
|
|
24
|
+
this.preparePayload = preparePayload;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async saveToMainDB(response: Amity.PostPayload) {
|
|
28
|
+
const processedPayload = await this.preparePayload(response);
|
|
29
|
+
|
|
30
|
+
const client = getActiveClient();
|
|
31
|
+
const cachedAt = client.cache && Date.now();
|
|
32
|
+
|
|
33
|
+
if (client.cache) {
|
|
34
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
appendToQueryStream(
|
|
39
|
+
response: Amity.PostPayload & Partial<Amity.Pagination>,
|
|
40
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
41
|
+
refresh = false,
|
|
42
|
+
) {
|
|
43
|
+
if (refresh) {
|
|
44
|
+
pushToCache(this.cacheKey, {
|
|
45
|
+
data: response.posts.map(getResolver('post')),
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
|
|
49
|
+
|
|
50
|
+
const posts = collection?.data ?? [];
|
|
51
|
+
|
|
52
|
+
pushToCache(this.cacheKey, {
|
|
53
|
+
...collection,
|
|
54
|
+
data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
reactor(action: EnumPostActions) {
|
|
60
|
+
return (post: Amity.InternalPost) => {
|
|
61
|
+
const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
|
|
62
|
+
|
|
63
|
+
if (!collection) return;
|
|
64
|
+
|
|
65
|
+
if (post.parentPostId && post.isDeleted) {
|
|
66
|
+
const parentPost = pullFromCache<Amity.InternalPost>([
|
|
67
|
+
'post',
|
|
68
|
+
'get',
|
|
69
|
+
post.parentPostId,
|
|
70
|
+
])?.data;
|
|
71
|
+
|
|
72
|
+
if (!parentPost) return;
|
|
73
|
+
|
|
74
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
75
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
79
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
83
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pushToCache(this.cacheKey, collection);
|
|
87
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
subscribeRTE(
|
|
92
|
+
createSubscriber: {
|
|
93
|
+
fn: (reactor: (post: Amity.InternalPost) => void) => Amity.Unsubscriber;
|
|
94
|
+
action: EnumPostActions;
|
|
95
|
+
}[],
|
|
96
|
+
) {
|
|
97
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
98
|
+
}
|
|
99
|
+
}
|