@amityco/ts-sdk 7.5.3-d6ee46d.0 → 7.5.4-2d34fd5f.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/@types/domains/content.d.ts +11 -2
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +2 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +3 -1
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/pinnedPost.d.ts +1 -1
- package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +21 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/communityRepository/api/deleteCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +2 -2
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +1 -0
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadClip.d.ts +17 -0
- package/dist/fileRepository/api/uploadClip.d.ts.map +1 -0
- package/dist/index.cjs.js +433 -432
- package/dist/index.esm.js +400 -399
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/postRepository/api/createClipPost.d.ts +32 -0
- package/dist/postRepository/api/createClipPost.d.ts.map +1 -0
- package/dist/postRepository/api/getPost.d.ts +2 -2
- package/dist/postRepository/api/getPost.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +1 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers.d.ts +4 -4
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +1 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/domains/content.ts +25 -1
- package/src/@types/domains/feed.ts +2 -1
- package/src/@types/domains/file.ts +5 -0
- package/src/@types/domains/pinnedPost.ts +1 -1
- package/src/@types/domains/post.ts +29 -8
- package/src/@types/index.ts +2 -0
- package/src/client/api/enableUnreadCount.ts +0 -22
- package/src/client/api/login.ts +0 -4
- package/src/client/utils/markerSyncEngine.ts +3 -24
- package/src/commentRepository/api/createComment.ts +1 -1
- package/src/commentRepository/api/deleteComment.ts +1 -1
- package/src/communityRepository/api/deleteCommunity.ts +2 -1
- package/src/communityRepository/api/getCommunity.ts +5 -7
- package/src/communityRepository/observers/getCommunity.ts +24 -12
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +1 -2
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +1 -1
- package/src/feedRepository/api/queryGlobalFeed.ts +3 -1
- package/src/fileRepository/api/index.ts +1 -0
- package/src/fileRepository/api/uploadClip.ts +71 -0
- package/src/postRepository/api/createClipPost.ts +62 -0
- package/src/postRepository/api/getPost.ts +6 -4
- package/src/postRepository/api/index.ts +2 -0
- package/src/postRepository/api/queryPosts.ts +1 -1
- package/src/postRepository/observers/getPost.ts +2 -2
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +1 -1
- package/src/reactionRepository/api/addReaction.ts +1 -1
- package/src/userRepository/observers/getBlockedUsers.ts +4 -4
- package/src/utils/linkedObject/postLinkedObject.ts +12 -1
- package/src/utils/linkedObject/streamLinkedObject.ts +1 -1
- package/src/utils/postTypePredicate.ts +10 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
+
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
|
+
|
|
5
|
+
/* begin_public_function
|
|
6
|
+
id: file.upload.clip
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* ```js
|
|
10
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
11
|
+
* const created = await FileRepository.uploadClip(formData)
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Creates an {@link Amity.File}
|
|
15
|
+
*
|
|
16
|
+
* @param formData The data necessary to create a new {@link Amity.File}
|
|
17
|
+
* @param onProgress The callback to track the upload progress
|
|
18
|
+
* @returns The newly created {@link Amity.File}
|
|
19
|
+
*
|
|
20
|
+
* @category File API
|
|
21
|
+
* @async
|
|
22
|
+
*/
|
|
23
|
+
export const uploadClip = async (
|
|
24
|
+
formData: FormData,
|
|
25
|
+
feedType?: Amity.ContentFeedType,
|
|
26
|
+
onProgress?: (percent: number) => void,
|
|
27
|
+
): Promise<Amity.Cached<Amity.File<'clip'>[]>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('file/uploadClip', formData);
|
|
30
|
+
|
|
31
|
+
const file = formData.get('files');
|
|
32
|
+
|
|
33
|
+
if (!file) throw new Error('The formData object must have a `files` key.');
|
|
34
|
+
|
|
35
|
+
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
36
|
+
formData.append('accessType', accessType);
|
|
37
|
+
|
|
38
|
+
formData.append('preferredFilename', (file as File).name);
|
|
39
|
+
|
|
40
|
+
if (feedType) {
|
|
41
|
+
formData.append('feedType', feedType);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const headers =
|
|
45
|
+
'getHeaders' in formData
|
|
46
|
+
? (formData as any).getHeaders()
|
|
47
|
+
: { 'content-type': 'multipart/form-data' };
|
|
48
|
+
|
|
49
|
+
const { data } = await client.upload.post<Amity.CreateFilePayload<'clip'>>(
|
|
50
|
+
'/api/v4/clips',
|
|
51
|
+
formData,
|
|
52
|
+
{
|
|
53
|
+
headers,
|
|
54
|
+
onUploadProgress({ loaded, total = 100 }) {
|
|
55
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// API-FIX: payload should be serialized properly
|
|
61
|
+
// const { files } = data
|
|
62
|
+
|
|
63
|
+
const cachedAt = client.cache && Date.now();
|
|
64
|
+
if (client.cache) ingestInCache({ files: data }, { cachedAt });
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
data,
|
|
68
|
+
cachedAt,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/* end_public_function */
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { fireEvent } from '~/core/events';
|
|
5
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
7
|
+
|
|
8
|
+
/* begin_public_function
|
|
9
|
+
id: post.create.clip_post
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* ```js
|
|
13
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
14
|
+
* const created = await PostRepository.createClipPost({
|
|
15
|
+
* targetType: 'user',
|
|
16
|
+
* targetId: 'foobar',
|
|
17
|
+
* dataType: 'clip',
|
|
18
|
+
* data: { text: 'hello world' },
|
|
19
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
20
|
+
* }))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Creates an {@link Amity.Post}
|
|
24
|
+
*
|
|
25
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
26
|
+
* @returns The newly created {@link Amity.Post}
|
|
27
|
+
*
|
|
28
|
+
* @category Post API
|
|
29
|
+
* @async
|
|
30
|
+
*/
|
|
31
|
+
export const createClipPost = async <T extends Amity.PostContentType | string>(
|
|
32
|
+
bundle: Pick<Amity.Post<T>, 'targetType' | 'targetId'> &
|
|
33
|
+
Partial<Pick<Amity.Post<T>, 'metadata' | 'mentionees' | 'tags'>> & {
|
|
34
|
+
data: { [k: string]: any };
|
|
35
|
+
attachments: {
|
|
36
|
+
type: T;
|
|
37
|
+
fileId: Amity.File['fileId'];
|
|
38
|
+
displayMode?: Amity.ClipDisplayMode;
|
|
39
|
+
isMuted?: boolean;
|
|
40
|
+
}[];
|
|
41
|
+
},
|
|
42
|
+
): Promise<Amity.Cached<Amity.Post>> => {
|
|
43
|
+
const client = getActiveClient();
|
|
44
|
+
client.log('post/createPost', bundle);
|
|
45
|
+
|
|
46
|
+
const { data: payload } = await client.http.post<Amity.PostPayload>('/api/v4/posts', bundle);
|
|
47
|
+
|
|
48
|
+
fireEvent('post.created', payload);
|
|
49
|
+
|
|
50
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
51
|
+
const cachedAt = client.cache && Date.now();
|
|
52
|
+
|
|
53
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
54
|
+
|
|
55
|
+
const { posts } = data;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
data: LinkedObject.post(posts[0]),
|
|
59
|
+
cachedAt,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/* end_public_function */
|
|
@@ -22,7 +22,9 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
22
22
|
* @category Post API
|
|
23
23
|
* @async
|
|
24
24
|
*/
|
|
25
|
-
export const getPost = async (
|
|
25
|
+
export const getPost = async (
|
|
26
|
+
postId: Amity.Post['postId'],
|
|
27
|
+
): Promise<Amity.Cached<Amity.InternalPost>> => {
|
|
26
28
|
const client = getActiveClient();
|
|
27
29
|
client.log('post/getPost', postId);
|
|
28
30
|
|
|
@@ -54,7 +56,7 @@ export const getPost = async (postId: Amity.Post['postId']): Promise<Amity.Cache
|
|
|
54
56
|
const result = posts.find(post => post.postId === postId)!;
|
|
55
57
|
|
|
56
58
|
return {
|
|
57
|
-
data:
|
|
59
|
+
data: result,
|
|
58
60
|
cachedAt,
|
|
59
61
|
};
|
|
60
62
|
};
|
|
@@ -72,7 +74,7 @@ export const getPost = async (postId: Amity.Post['postId']): Promise<Amity.Cache
|
|
|
72
74
|
*
|
|
73
75
|
* @category Post API
|
|
74
76
|
*/
|
|
75
|
-
getPost.locally = (postId: Amity.Post['postId']): Amity.Cached<Amity.
|
|
77
|
+
getPost.locally = (postId: Amity.Post['postId']): Amity.Cached<Amity.InternalPost> | undefined => {
|
|
76
78
|
const client = getActiveClient();
|
|
77
79
|
client.log('post/getPost.locally', postId);
|
|
78
80
|
|
|
@@ -83,7 +85,7 @@ getPost.locally = (postId: Amity.Post['postId']): Amity.Cached<Amity.Post> | und
|
|
|
83
85
|
if (!cached) return;
|
|
84
86
|
|
|
85
87
|
return {
|
|
86
|
-
data:
|
|
88
|
+
data: cached.data,
|
|
87
89
|
cachedAt: cached.cachedAt,
|
|
88
90
|
};
|
|
89
91
|
};
|
|
@@ -43,7 +43,7 @@ export const queryPosts = async (
|
|
|
43
43
|
// API-FIX: parameters should be querystring. (1)
|
|
44
44
|
// API-FIX: backend should answer Amity.Response (2)
|
|
45
45
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
46
|
-
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/
|
|
46
|
+
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/v5/posts`, {
|
|
47
47
|
params: {
|
|
48
48
|
...params,
|
|
49
49
|
isDeleted: inferIsDeleted(includeDeleted),
|
|
@@ -85,12 +85,12 @@ export const getPost = (
|
|
|
85
85
|
onPostFlagged,
|
|
86
86
|
(callback: Amity.Listener<Amity.InternalPost>) => {
|
|
87
87
|
return onPostReactionAdded((post: Amity.InternalPost) => {
|
|
88
|
-
callback(
|
|
88
|
+
callback(post);
|
|
89
89
|
});
|
|
90
90
|
},
|
|
91
91
|
(callback: Amity.Listener<Amity.InternalPost>) => {
|
|
92
92
|
return onPostReactionRemoved((post: Amity.InternalPost) => {
|
|
93
|
-
callback(
|
|
93
|
+
callback(post);
|
|
94
94
|
});
|
|
95
95
|
},
|
|
96
96
|
onPostUnflagged,
|
|
@@ -23,7 +23,7 @@ export class PostPaginationController extends PaginationController<
|
|
|
23
23
|
const options = token ? { ...baseOptions, token } : { ...baseOptions, limit };
|
|
24
24
|
|
|
25
25
|
const { data: queryResponse } = await this.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
26
|
-
`/api/
|
|
26
|
+
`/api/v5/posts`,
|
|
27
27
|
{
|
|
28
28
|
params: {
|
|
29
29
|
...params,
|
|
@@ -12,10 +12,10 @@ import { BlockedUserLiveCollectionController } from './getBlockedUsers/BlockedUs
|
|
|
12
12
|
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* Blocks a {@link Amity.
|
|
15
|
+
* Blocks a {@link Amity.User}
|
|
16
16
|
*
|
|
17
|
-
* @param params The params to get blocked {@link Amity.
|
|
18
|
-
* @param callback to recieve updates on unblocked {@link Amity.
|
|
17
|
+
* @param params The params to get blocked {@link Amity.User}s
|
|
18
|
+
* @param callback to recieve updates on unblocked {@link Amity.User}s
|
|
19
19
|
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
20
20
|
*
|
|
21
21
|
* @category Post API
|
|
@@ -23,7 +23,7 @@ import { BlockedUserLiveCollectionController } from './getBlockedUsers/BlockedUs
|
|
|
23
23
|
*/
|
|
24
24
|
export const getBlockedUsers = (
|
|
25
25
|
params: Amity.BlockedUsersLiveCollection,
|
|
26
|
-
callback: Amity.LiveCollectionCallback<Amity.
|
|
26
|
+
callback: Amity.LiveCollectionCallback<Amity.User>,
|
|
27
27
|
config?: Amity.LiveCollectionConfig,
|
|
28
28
|
): Amity.Unsubscriber => {
|
|
29
29
|
const { log, cache } = getActiveClient();
|
|
@@ -2,7 +2,12 @@ import { pullFromCache } from '~/cache/api';
|
|
|
2
2
|
import { commentLinkedObject } from '~/utils/linkedObject/commentLinkedObject';
|
|
3
3
|
import AnalyticsEngine from '../../analytic/service/analytic/AnalyticsEngine';
|
|
4
4
|
import { userLinkedObject } from './userLinkedObject';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
isAmityClipPost,
|
|
7
|
+
isAmityFilePost,
|
|
8
|
+
isAmityImagePost,
|
|
9
|
+
isAmityVideoPost,
|
|
10
|
+
} from '../postTypePredicate';
|
|
6
11
|
|
|
7
12
|
export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
8
13
|
return {
|
|
@@ -64,5 +69,11 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
|
64
69
|
? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
|
|
65
70
|
: undefined;
|
|
66
71
|
},
|
|
72
|
+
|
|
73
|
+
getClipInfo(): Amity.File<'clip'> | undefined {
|
|
74
|
+
return isAmityClipPost(post)
|
|
75
|
+
? pullFromCache<Amity.File<'clip'>>(['file', 'get', post?.data?.fileId])?.data
|
|
76
|
+
: undefined;
|
|
77
|
+
},
|
|
67
78
|
};
|
|
68
79
|
};
|
|
@@ -9,7 +9,7 @@ export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream =
|
|
|
9
9
|
},
|
|
10
10
|
get post() {
|
|
11
11
|
if (stream.referenceType !== 'post') return;
|
|
12
|
-
return pullFromCache<Amity.
|
|
12
|
+
return pullFromCache<Amity.InternalPost>(['post', 'get', stream.referenceId])?.data;
|
|
13
13
|
},
|
|
14
14
|
get community() {
|
|
15
15
|
if (stream.targetType !== 'community') return;
|
|
@@ -25,3 +25,13 @@ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'
|
|
|
25
25
|
post.dataType === 'video'
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export function isAmityClipPost(post: Amity.InternalPost): post is Amity.Post<'clip'> {
|
|
30
|
+
return !!(
|
|
31
|
+
post.data &&
|
|
32
|
+
typeof post.data !== 'string' &&
|
|
33
|
+
'fileId' in post.data &&
|
|
34
|
+
'thumbnailFileId' in post.data &&
|
|
35
|
+
post.dataType === 'clip'
|
|
36
|
+
);
|
|
37
|
+
}
|