@amityco/ts-sdk-react-native 7.4.0 → 7.5.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 { MessageRepository } from '@amityco/ts-sdk-react-native'
4
- * const flagged = await MessageRepository.flagMessage(messageId)
4
+ * const flagged = await MessageRepository.flagMessage(messageId, reason)
5
5
  * ```
6
6
  *
7
7
  * @param messageId of the message to flag
8
+ * @param reason the reason to flag the message
8
9
  * @returns the created report result
9
10
  *
10
11
  * @category Message API
11
12
  * @async
12
13
  * */
13
- export declare const flagMessage: (messageId: Amity.Message['messageId']) => Promise<boolean>;
14
+ export declare const flagMessage: (messageId: Amity.Message['messageId'], reason?: Amity.ContentFlagReason) => Promise<boolean>;
14
15
  //# sourceMappingURL=flagMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flagMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/flagMessage.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,WAAW,cAAqB,MAAM,OAAO,CAAC,WAAW,CAAC,KAAG,QAAQ,OAAO,CAgBxF,CAAC"}
1
+ {"version":3,"file":"flagMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/flagMessage.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,WAAW,cACX,MAAM,OAAO,CAAC,WAAW,CAAC,WAC5B,MAAM,iBAAiB,KAC/B,QAAQ,OAAO,CA4BjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk-react-native",
3
- "version": "7.4.0",
3
+ "version": "7.5.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",
@@ -1,4 +1,5 @@
1
1
  import { fireEvent } from '~/core/events';
2
+ import { ContentFlagReasonEnum } from '~/@types';
2
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
3
4
  import { getActiveClient } from '~/client/api/activeClient';
4
5
  import { prepareMessagePayload } from '~/messageRepository/utils';
@@ -9,21 +10,37 @@ import { prepareMessagePayload } from '~/messageRepository/utils';
9
10
  /**
10
11
  * ```js
11
12
  * import { MessageRepository } from '@amityco/ts-sdk-react-native'
12
- * const flagged = await MessageRepository.flagMessage(messageId)
13
+ * const flagged = await MessageRepository.flagMessage(messageId, reason)
13
14
  * ```
14
15
  *
15
16
  * @param messageId of the message to flag
17
+ * @param reason the reason to flag the message
16
18
  * @returns the created report result
17
19
  *
18
20
  * @category Message API
19
21
  * @async
20
22
  * */
21
- export const flagMessage = async (messageId: Amity.Message['messageId']): Promise<boolean> => {
23
+ export const flagMessage = async (
24
+ messageId: Amity.Message['messageId'],
25
+ reason?: Amity.ContentFlagReason,
26
+ ): Promise<boolean> => {
22
27
  const client = getActiveClient();
23
28
  client.log('message/flag', messageId);
24
29
 
30
+ const isPredefinedReason =
31
+ reason &&
32
+ Object.entries(ContentFlagReasonEnum).some(
33
+ ([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason,
34
+ );
35
+
36
+ const body = {
37
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
38
+ detail: !isPredefinedReason ? reason : '',
39
+ };
40
+
25
41
  const { data: payload } = await client.http.post<Amity.MessagePayload>(
26
42
  `/api/v5/messages/${encodeURIComponent(messageId)}/flags`,
43
+ body,
27
44
  );
28
45
 
29
46
  if (client.cache) {