@amityco/ts-sdk 7.2.1-eeeca9c0.0 → 7.3.1-56cdb841.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.
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * ```js
3
3
  * import { PostRepository } from '@amityco/ts-sdk'
4
- * const flagged = await PostRepository.flagPost(postId)
4
+ * const flagged = await PostRepository.flagPost(postId, reason)
5
5
  * ```
6
6
  *
7
7
  * @param postId of the post to flag
8
+ * @param reason the reason to flag the post
8
9
  * @returns a boolean
9
10
  *
10
11
  * @category Post API
11
12
  * @async
12
13
  * */
13
- export declare const flagPost: (postId: Amity.Post['postId']) => Promise<boolean>;
14
+ export declare const flagPost: (postId: Amity.Post['postId'], reason: Amity.ContentFlagReason) => Promise<boolean>;
14
15
  //# sourceMappingURL=flagPost.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flagPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/flagPost.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,QAAQ,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,CAe5E,CAAC"}
1
+ {"version":3,"file":"flagPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/flagPost.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,QAAQ,WACX,MAAM,IAAI,CAAC,QAAQ,CAAC,UACpB,MAAM,iBAAiB,KAC9B,QAAQ,OAAO,CAyBjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "7.2.1-eeeca9c0.0",
3
+ "version": "7.3.1-56cdb841.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -6,8 +6,24 @@ export const ContentFeedType = Object.freeze({
6
6
  MESSAGE: 'message',
7
7
  });
8
8
 
9
+ export enum ContentFlagReasonEnum {
10
+ CommunityGuidelines = 'Against community guidelines',
11
+ HarassmentOrBullying = 'Harassment or bullying',
12
+ SelfHarmOrSuicide = 'Self-harm or suicide',
13
+ ViolenceOrThreateningContent = 'Violence or threatening content',
14
+ SellingRestrictedItems = 'Selling and promoting restricted items',
15
+ SexualContentOrNudity = 'Sexual message or nudity',
16
+ SpamOrScams = 'Spam or scams',
17
+ FalseInformation = 'False information or misinformation',
18
+ Others = 'Others',
19
+ }
20
+
9
21
  declare global {
10
22
  namespace Amity {
23
+ type ContentFlagReason =
24
+ | Exclude<`${ContentFlagReasonEnum}`, `${ContentFlagReasonEnum.Others}`>
25
+ | (string & {});
26
+
11
27
  type ContentType = 'text' | 'image' | 'file' | 'video' | 'poll' | 'json' | string;
12
28
 
13
29
  type ContentFeedType = ValueOf<typeof ContentFeedType>;
@@ -1,7 +1,8 @@
1
1
  import { getActiveClient } from '~/client/api/activeClient';
2
-
3
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
3
  import { fireEvent } from '~/core/events';
4
+ import { prepareMembershipPayload } from '~/group/utils';
5
+ import { ContentFlagReasonEnum } from '~/@types';
5
6
 
6
7
  /* begin_public_function
7
8
  id: comment.flag
@@ -9,21 +10,35 @@ import { fireEvent } from '~/core/events';
9
10
  /**
10
11
  * ```js
11
12
  * import { CommentRepository } from '@amityco/ts-sdk'
12
- * const flagged = await CommentRepository.flagComment('commentId')
13
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
13
14
  * ```
14
15
  *
15
16
  * @param commentId The ID of the comment to flag
17
+ * @param reason the reason to flag the comment
16
18
  * @returns the created report result
17
19
  *
18
20
  * @category Comment API
19
21
  * @async
20
22
  * */
21
- export const flagComment = async (commentId: Amity.Comment['commentId']): Promise<boolean> => {
23
+ export const flagComment = async (
24
+ commentId: Amity.Comment['commentId'],
25
+ reason: Amity.ContentFlagReason,
26
+ ): Promise<boolean> => {
22
27
  const client = getActiveClient();
23
28
  client.log('comment/flagComment', commentId);
24
29
 
30
+ const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(
31
+ ([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason,
32
+ );
33
+
34
+ const body = {
35
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
36
+ detail: isPredefinedReason ? '' : reason,
37
+ };
38
+
25
39
  const { data: payload } = await client.http.post<Amity.CommentPayload>(
26
40
  `/api/v3/comments/${encodeURIComponent(commentId)}/flag`,
41
+ body,
27
42
  );
28
43
 
29
44
  if (client.cache) {
@@ -33,7 +33,7 @@ export const markItemsSeen = async (trayItems: Amity.QueryNotificationItemSeen[]
33
33
  },
34
34
  );
35
35
 
36
- const updatedData = trayItems
36
+ const updatedData = payload.trayItems
37
37
  .map(patchItem => {
38
38
  const cacheData = pullFromCache<Amity.InternalNotificationTrayItem>([
39
39
  'notificationTrayItem',
@@ -45,7 +45,7 @@ export const markItemsSeen = async (trayItems: Amity.QueryNotificationItemSeen[]
45
45
 
46
46
  const data = {
47
47
  ...cacheData,
48
- ...payload,
48
+ lastSeenAt: patchItem.lastSeenAt,
49
49
  };
50
50
 
51
51
  if (client.cache) {
@@ -1,8 +1,8 @@
1
1
  import { getActiveClient } from '~/client/api/activeClient';
2
-
3
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
3
  import { fireEvent } from '~/core/events';
5
4
  import { prepareMembershipPayload } from '~/group/utils';
5
+ import { ContentFlagReasonEnum } from '~/@types';
6
6
 
7
7
  /* begin_public_function
8
8
  id: post.flag
@@ -10,21 +10,35 @@ import { prepareMembershipPayload } from '~/group/utils';
10
10
  /**
11
11
  * ```js
12
12
  * import { PostRepository } from '@amityco/ts-sdk'
13
- * const flagged = await PostRepository.flagPost(postId)
13
+ * const flagged = await PostRepository.flagPost(postId, reason)
14
14
  * ```
15
15
  *
16
16
  * @param postId of the post to flag
17
+ * @param reason the reason to flag the post
17
18
  * @returns a boolean
18
19
  *
19
20
  * @category Post API
20
21
  * @async
21
22
  * */
22
- export const flagPost = async (postId: Amity.Post['postId']): Promise<boolean> => {
23
+ export const flagPost = async (
24
+ postId: Amity.Post['postId'],
25
+ reason: Amity.ContentFlagReason,
26
+ ): Promise<boolean> => {
23
27
  const client = getActiveClient();
24
28
  client.log('post/flagPost', postId);
25
29
 
30
+ const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(
31
+ ([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason,
32
+ );
33
+
34
+ const body = {
35
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
36
+ detail: isPredefinedReason ? '' : reason,
37
+ };
38
+
26
39
  const { data: payload } = await client.http.post<Amity.PostPayload>(
27
40
  `/api/v3/posts/${encodeURIComponent(postId)}/flag`,
41
+ body,
28
42
  );
29
43
 
30
44
  if (client.cache) {