@octopus-community/react-native 1.0.7 → 1.9.1
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/OctopusReactNativeSdk.podspec +1 -1
- package/README.md +40 -35
- package/android/build.gradle +2 -0
- package/android/gradle.properties +2 -2
- package/android/src/main/AndroidManifest.xml +2 -1
- package/android/src/main/AndroidManifestNew.xml +2 -1
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusActivity.kt +56 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusContent.kt +396 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusEventEmitter.kt +22 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusEventSerializer.kt +339 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactModule.kt +326 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/{OctopusReactNativeSdkPackage.kt → OctopusReactPackage.kt} +3 -3
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSDKInitializer.kt +53 -9
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusSSOAuthenticator.kt +5 -15
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIConfiguration.kt +6 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIConfigurationManager.kt +12 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIController.kt +17 -2
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIViewManager.kt +63 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/ProfileFieldMapper.kt +2 -2
- package/ios/OctopusEventManager.swift +27 -0
- package/ios/OctopusEventSerializer.swift +271 -0
- package/ios/OctopusReactNativeSdk.mm +26 -1
- package/ios/OctopusReactNativeSdk.swift +225 -3
- package/ios/OctopusSDKInitializer.swift +32 -0
- package/ios/OctopusSSOAuthenticator.swift +1 -5
- package/ios/OctopusUIConfiguration.swift +6 -0
- package/ios/OctopusUIManager.swift +134 -10
- package/ios/OctopusUIViewManager.m +7 -0
- package/ios/OctopusUIViewManager.swift +37 -0
- package/lib/module/OctopusUIView.js +39 -0
- package/lib/module/OctopusUIView.js.map +1 -0
- package/lib/module/addHasAccessToCommunityListener.js +33 -0
- package/lib/module/addHasAccessToCommunityListener.js.map +1 -0
- package/lib/module/addNavigateToUrlListener.js +41 -0
- package/lib/module/addNavigateToUrlListener.js.map +1 -0
- package/lib/module/addNotSeenNotificationsCountListener.js +30 -0
- package/lib/module/addNotSeenNotificationsCountListener.js.map +1 -0
- package/lib/module/addSDKEventListener.js +48 -0
- package/lib/module/addSDKEventListener.js.map +1 -0
- package/lib/module/connectUser.js +24 -3
- package/lib/module/connectUser.js.map +1 -1
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/initialize.js +13 -12
- package/lib/module/initialize.js.map +1 -1
- package/lib/module/openUI.js +23 -2
- package/lib/module/openUI.js.map +1 -1
- package/lib/module/overrideCommunityAccess.js +36 -0
- package/lib/module/overrideCommunityAccess.js.map +1 -0
- package/lib/module/overrideDefaultLocale.js +75 -0
- package/lib/module/overrideDefaultLocale.js.map +1 -0
- package/lib/module/trackCommunityAccess.js +33 -0
- package/lib/module/trackCommunityAccess.js.map +1 -0
- package/lib/module/trackCustomEvent.js +36 -0
- package/lib/module/trackCustomEvent.js.map +1 -0
- package/lib/module/types/sdkEvents.js +2 -0
- package/lib/module/types/sdkEvents.js.map +1 -0
- package/lib/module/types/urlOpeningStrategy.js +23 -0
- package/lib/module/types/urlOpeningStrategy.js.map +1 -0
- package/lib/module/updateNotSeenNotificationsCount.js +33 -0
- package/lib/module/updateNotSeenNotificationsCount.js.map +1 -0
- package/lib/typescript/src/OctopusUIView.d.ts +32 -0
- package/lib/typescript/src/OctopusUIView.d.ts.map +1 -0
- package/lib/typescript/src/addHasAccessToCommunityListener.d.ts +27 -0
- package/lib/typescript/src/addHasAccessToCommunityListener.d.ts.map +1 -0
- package/lib/typescript/src/addNavigateToUrlListener.d.ts +31 -0
- package/lib/typescript/src/addNavigateToUrlListener.d.ts.map +1 -0
- package/lib/typescript/src/addNotSeenNotificationsCountListener.d.ts +24 -0
- package/lib/typescript/src/addNotSeenNotificationsCountListener.d.ts.map +1 -0
- package/lib/typescript/src/addSDKEventListener.d.ts +43 -0
- package/lib/typescript/src/addSDKEventListener.d.ts.map +1 -0
- package/lib/typescript/src/connectUser.d.ts +24 -8
- package/lib/typescript/src/connectUser.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +13 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/initialize.d.ts +22 -12
- package/lib/typescript/src/initialize.d.ts.map +1 -1
- package/lib/typescript/src/openUI.d.ts +28 -1
- package/lib/typescript/src/openUI.d.ts.map +1 -1
- package/lib/typescript/src/overrideCommunityAccess.d.ts +30 -0
- package/lib/typescript/src/overrideCommunityAccess.d.ts.map +1 -0
- package/lib/typescript/src/overrideDefaultLocale.d.ts +37 -0
- package/lib/typescript/src/overrideDefaultLocale.d.ts.map +1 -0
- package/lib/typescript/src/trackCommunityAccess.d.ts +27 -0
- package/lib/typescript/src/trackCommunityAccess.d.ts.map +1 -0
- package/lib/typescript/src/trackCustomEvent.d.ts +30 -0
- package/lib/typescript/src/trackCustomEvent.d.ts.map +1 -0
- package/lib/typescript/src/types/sdkEvents.d.ts +222 -0
- package/lib/typescript/src/types/sdkEvents.d.ts.map +1 -0
- package/lib/typescript/src/types/urlOpeningStrategy.d.ts +20 -0
- package/lib/typescript/src/types/urlOpeningStrategy.d.ts.map +1 -0
- package/lib/typescript/src/updateNotSeenNotificationsCount.d.ts +27 -0
- package/lib/typescript/src/updateNotSeenNotificationsCount.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/OctopusUIView.tsx +57 -0
- package/src/addHasAccessToCommunityListener.ts +38 -0
- package/src/addNavigateToUrlListener.ts +54 -0
- package/src/addNotSeenNotificationsCountListener.ts +35 -0
- package/src/addSDKEventListener.ts +49 -0
- package/src/connectUser.ts +24 -8
- package/src/index.ts +13 -0
- package/src/initialize.ts +23 -12
- package/src/openUI.ts +32 -2
- package/src/overrideCommunityAccess.ts +33 -0
- package/src/overrideDefaultLocale.ts +88 -0
- package/src/trackCommunityAccess.ts +30 -0
- package/src/trackCustomEvent.ts +36 -0
- package/src/types/sdkEvents.ts +315 -0
- package/src/types/urlOpeningStrategy.ts +20 -0
- package/src/updateNotSeenNotificationsCount.ts +30 -0
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusReactNativeSdkModule.kt +0 -155
- package/android/src/main/java/com/octopuscommunity/octopusreactnativesdk/OctopusUIActivity.kt +0 -422
package/src/openUI.ts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Options for opening the Octopus UI.
|
|
5
|
+
*/
|
|
6
|
+
export interface OpenUIOptions {
|
|
7
|
+
/**
|
|
8
|
+
* When `true`, URLs tapped inside the community UI are not opened by the SDK.
|
|
9
|
+
* Instead, a `navigateToUrl` event is emitted. Subscribe with
|
|
10
|
+
* `addNavigateToUrlListener` to receive the URL and decide whether to handle
|
|
11
|
+
* it in-app or delegate back to the SDK (system browser).
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
interceptUrls?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* Opens the Octopus UI home screen.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Optional configuration. Use `interceptUrls: true` to receive
|
|
22
|
+
* URL taps via `addNavigateToUrlListener` instead of having the SDK open them.
|
|
23
|
+
* @returns A promise that resolves when the UI has been opened.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Open UI with default behaviour (SDK opens links in system browser)
|
|
28
|
+
* await openUI();
|
|
29
|
+
*
|
|
30
|
+
* // Open UI with URL interception (app receives links via addNavigateToUrlListener)
|
|
31
|
+
* await openUI({ interceptUrls: true });
|
|
32
|
+
* ```
|
|
5
33
|
*/
|
|
6
|
-
export function openUI(): Promise<void> {
|
|
7
|
-
|
|
34
|
+
export function openUI(options?: OpenUIOptions): Promise<void> {
|
|
35
|
+
const opts = options ?? {};
|
|
36
|
+
const interceptUrls = opts.interceptUrls === true;
|
|
37
|
+
return OctopusReactNativeSdk.openUI({ interceptUrls });
|
|
8
38
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Override the community access cohort for the current user.
|
|
5
|
+
*
|
|
6
|
+
* **When to use:** When the **Octopus SDK manages the A/B logic** — i.e. Octopus assigns
|
|
7
|
+
* the cohort and decides who has access to the community. In that case, the "Has access
|
|
8
|
+
* to community" state is the cohort value. Use this function to override that cohort
|
|
9
|
+
* (e.g. for testing or feature gating). The new state is reflected via `addHasAccessToCommunityListener`.
|
|
10
|
+
*
|
|
11
|
+
* **When not to use:** If **your app** decides who has access (e.g. your own feature flag or A/B logic),
|
|
12
|
+
* do not use `overrideCommunityAccess`. Use `trackCommunityAccess` instead to report the access
|
|
13
|
+
* value to Octopus for analytics only; that does not change the actual access state in the SDK.
|
|
14
|
+
*
|
|
15
|
+
* @param hasAccess - `true` to grant access, `false` to deny access.
|
|
16
|
+
* @returns A promise that resolves when the override has been applied.
|
|
17
|
+
* @throws An error if the SDK is not initialized or the call fails.
|
|
18
|
+
* @see {@link addHasAccessToCommunityListener} – subscribe to the Octopus-managed community access state.
|
|
19
|
+
* @see {@link trackCommunityAccess} – when your app manages access, report it for analytics only (no change to SDK state).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const subscription = addHasAccessToCommunityListener((hasAccess) => {
|
|
24
|
+
* console.log(`Has access to community: ${hasAccess}`);
|
|
25
|
+
* });
|
|
26
|
+
* await overrideCommunityAccess(true);
|
|
27
|
+
* await overrideCommunityAccess(false);
|
|
28
|
+
* subscription.remove();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function overrideCommunityAccess(hasAccess: boolean): Promise<void> {
|
|
32
|
+
return OctopusReactNativeSdk.overrideCommunityAccess(hasAccess);
|
|
33
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for overriding the default locale used by the Octopus SDK UI.
|
|
5
|
+
* Uses ISO 639-1 language code and optional ISO 3166-1 alpha-2 country code.
|
|
6
|
+
*/
|
|
7
|
+
export interface OverrideLocaleParams {
|
|
8
|
+
/** ISO 639-1 language code (e.g. `"en"`, `"fr"`). */
|
|
9
|
+
languageCode: string;
|
|
10
|
+
/** Optional ISO 3166-1 alpha-2 country code (e.g. `"US"`, `"FR"`). */
|
|
11
|
+
countryCode?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** ISO 639-1: exactly 2 alphabetic characters (case-insensitive, normalized to lowercase). */
|
|
15
|
+
const LANGUAGE_CODE_REGEX = /^[a-zA-Z]{2}$/;
|
|
16
|
+
|
|
17
|
+
/** ISO 3166-1 alpha-2: exactly 2 alphabetic characters (case-insensitive, normalized to uppercase). */
|
|
18
|
+
const COUNTRY_CODE_REGEX = /^[a-zA-Z]{2}$/;
|
|
19
|
+
|
|
20
|
+
function validateAndNormalizeLocale(locale: OverrideLocaleParams): {
|
|
21
|
+
languageCode: string;
|
|
22
|
+
countryCode: string | null;
|
|
23
|
+
} {
|
|
24
|
+
const lang = locale.languageCode?.trim() ?? '';
|
|
25
|
+
if (!LANGUAGE_CODE_REGEX.test(lang)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"overrideDefaultLocale: languageCode must be a 2-letter ISO 639-1 code (e.g. 'en', 'fr')"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const country = locale.countryCode?.trim();
|
|
31
|
+
if (country !== undefined && country !== '') {
|
|
32
|
+
if (!COUNTRY_CODE_REGEX.test(country)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"overrideDefaultLocale: countryCode must be a 2-letter ISO 3166-1 alpha-2 code (e.g. 'US', 'FR')"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
languageCode: lang.toLowerCase(),
|
|
39
|
+
countryCode: country.toUpperCase(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
languageCode: lang.toLowerCase(),
|
|
44
|
+
countryCode: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Override the default locale used by the Octopus SDK for its UI.
|
|
50
|
+
*
|
|
51
|
+
* The change takes effect immediately for subsequently displayed SDK screens.
|
|
52
|
+
* Pass `null` to reset to the system default locale.
|
|
53
|
+
*
|
|
54
|
+
* @param locale - Object with `languageCode` and optional `countryCode`
|
|
55
|
+
* (e.g. `{ languageCode: 'fr' }` or `{ languageCode: 'en', countryCode: 'US' }`).
|
|
56
|
+
* Pass `null` to use the system default (no override).
|
|
57
|
+
* @returns A promise that resolves when the override has been applied.
|
|
58
|
+
* @throws An error if the SDK is not initialized or the call fails.
|
|
59
|
+
* @throws An error if locale is invalid (e.g. non-ISO language/country codes).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Use French
|
|
64
|
+
* await overrideDefaultLocale({ languageCode: 'fr' });
|
|
65
|
+
*
|
|
66
|
+
* // Use English (US)
|
|
67
|
+
* await overrideDefaultLocale({ languageCode: 'en', countryCode: 'US' });
|
|
68
|
+
*
|
|
69
|
+
* // Reset to system default
|
|
70
|
+
* await overrideDefaultLocale(null);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function overrideDefaultLocale(
|
|
74
|
+
locale: OverrideLocaleParams | null
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
if (locale === null) {
|
|
77
|
+
return OctopusReactNativeSdk.overrideDefaultLocale(null, null);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const { languageCode, countryCode } = validateAndNormalizeLocale(locale);
|
|
81
|
+
return OctopusReactNativeSdk.overrideDefaultLocale(
|
|
82
|
+
languageCode,
|
|
83
|
+
countryCode
|
|
84
|
+
);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return Promise.reject(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Track community access for analytics without changing the actual access.
|
|
5
|
+
*
|
|
6
|
+
* **When to use:** When **your app manages its own A/B logic** — i.e. your app decides who can see
|
|
7
|
+
* the community (e.g. via your own feature flag or experiment). Call this to report that decision
|
|
8
|
+
* to Octopus for analytics only. It does not grant or restrict access in the SDK; it only records
|
|
9
|
+
* the value for reporting.
|
|
10
|
+
*
|
|
11
|
+
* **When not to use:** If the **Octopus SDK manages the cohort** (Octopus assigns who has access),
|
|
12
|
+
* use `overrideCommunityAccess` to change the cohort and `addHasAccessToCommunityListener` to react
|
|
13
|
+
* to it. Use `trackCommunityAccess` only when the access decision is owned by your app and you just
|
|
14
|
+
* need to report it.
|
|
15
|
+
*
|
|
16
|
+
* @param hasAccess - The access value to report (e.g. the variant your app decided).
|
|
17
|
+
* @returns A promise that resolves when the tracking call has completed.
|
|
18
|
+
* @throws An error if the SDK is not initialized or the call fails.
|
|
19
|
+
* @see {@link overrideCommunityAccess} – when Octopus manages the cohort, override it (and use addHasAccessToCommunityListener to react).
|
|
20
|
+
* @see {@link addHasAccessToCommunityListener} – subscribe to the Octopus-managed access state (relevant when Octopus or override sets it).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* await trackCommunityAccess(true);
|
|
25
|
+
* await trackCommunityAccess(false);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function trackCommunityAccess(hasAccess: boolean): Promise<void> {
|
|
29
|
+
return OctopusReactNativeSdk.trackCommunityAccess(hasAccess);
|
|
30
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Track custom events that are merged into Octopus analytics reports.
|
|
5
|
+
*
|
|
6
|
+
* Use this to send app-specific business events (e.g. purchases, feature usage)
|
|
7
|
+
* so they appear alongside Octopus Community analytics.
|
|
8
|
+
*
|
|
9
|
+
* All property values must be strings. Non-string values should be stringified
|
|
10
|
+
* before calling (e.g. numbers as `"123"`, booleans as `"true"`).
|
|
11
|
+
*
|
|
12
|
+
* @param name - The name of the custom event (e.g. `"purchase"`, `"screen_view"`).
|
|
13
|
+
* @param properties - Optional map of string key-value pairs attached to the event.
|
|
14
|
+
* @returns A promise that resolves when the event has been tracked.
|
|
15
|
+
* @throws An error if the SDK is not initialized or tracking fails.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* await trackCustomEvent('purchase', {
|
|
20
|
+
* product_id: '123',
|
|
21
|
+
* price: '9.99',
|
|
22
|
+
* currency: 'EUR',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* await trackCustomEvent('feature_used', {
|
|
26
|
+
* feature: 'community_search',
|
|
27
|
+
* source: 'home_screen',
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function trackCustomEvent(
|
|
32
|
+
name: string,
|
|
33
|
+
properties?: Record<string, string>
|
|
34
|
+
): Promise<void> {
|
|
35
|
+
return OctopusReactNativeSdk.trackCustomEvent(name, properties ?? {});
|
|
36
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for SDK events emitted by Octopus SDK.
|
|
3
|
+
* These events represent various user interactions and system events within the Octopus community.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Content types that can be included in a post
|
|
8
|
+
*/
|
|
9
|
+
export type PostContentType = 'text' | 'image' | 'poll';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Content kind (post, comment, or reply)
|
|
13
|
+
*/
|
|
14
|
+
export type ContentKind = 'post' | 'comment' | 'reply';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reaction kinds
|
|
18
|
+
*/
|
|
19
|
+
export type ReactionKind =
|
|
20
|
+
| 'heart'
|
|
21
|
+
| 'joy'
|
|
22
|
+
| 'mouthOpen'
|
|
23
|
+
| 'clap'
|
|
24
|
+
| 'cry'
|
|
25
|
+
| 'rage'
|
|
26
|
+
| 'unknown';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Report reasons for content or profile reporting
|
|
30
|
+
*/
|
|
31
|
+
export type ReportReason =
|
|
32
|
+
| 'hateSpeech'
|
|
33
|
+
| 'explicit'
|
|
34
|
+
| 'violence'
|
|
35
|
+
| 'spam'
|
|
36
|
+
| 'suicide'
|
|
37
|
+
| 'fakeProfile'
|
|
38
|
+
| 'childExploitation'
|
|
39
|
+
| 'intellectualProperty'
|
|
40
|
+
| 'other';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gamification actions that can gain points
|
|
44
|
+
*/
|
|
45
|
+
export type GamificationPointsGainedAction =
|
|
46
|
+
| 'post'
|
|
47
|
+
| 'comment'
|
|
48
|
+
| 'reply'
|
|
49
|
+
| 'reaction'
|
|
50
|
+
| 'vote'
|
|
51
|
+
| 'postCommented'
|
|
52
|
+
| 'profileCompleted'
|
|
53
|
+
| 'dailySession';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Gamification actions that can remove points
|
|
57
|
+
*/
|
|
58
|
+
export type GamificationPointsRemovedAction =
|
|
59
|
+
| 'postDeleted'
|
|
60
|
+
| 'commentDeleted'
|
|
61
|
+
| 'replyDeleted'
|
|
62
|
+
| 'reactionDeleted';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Source of a post click
|
|
66
|
+
*/
|
|
67
|
+
export type PostClickedSource = 'feed' | 'profile';
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Screen types displayed in the Octopus UI
|
|
71
|
+
*/
|
|
72
|
+
export type ScreenType =
|
|
73
|
+
| 'postsFeed'
|
|
74
|
+
| 'postDetail'
|
|
75
|
+
| 'commentDetail'
|
|
76
|
+
| 'createPost'
|
|
77
|
+
| 'profile'
|
|
78
|
+
| 'otherUserProfile'
|
|
79
|
+
| 'editProfile'
|
|
80
|
+
| 'reportContent'
|
|
81
|
+
| 'reportProfile'
|
|
82
|
+
| 'validateNickname'
|
|
83
|
+
| 'settingsList'
|
|
84
|
+
| 'settingsAccount'
|
|
85
|
+
| 'settingsAbout'
|
|
86
|
+
| 'reportExplanation'
|
|
87
|
+
| 'deleteAccount';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Base interface for all SDK events
|
|
91
|
+
*/
|
|
92
|
+
export interface BaseSDKEvent {
|
|
93
|
+
type: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Event emitted when a post is created
|
|
98
|
+
*/
|
|
99
|
+
export interface PostCreatedEvent extends BaseSDKEvent {
|
|
100
|
+
type: 'postCreated';
|
|
101
|
+
postId: string;
|
|
102
|
+
content: PostContentType[];
|
|
103
|
+
topicId: string | null;
|
|
104
|
+
textLength: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Event emitted when a comment is created
|
|
109
|
+
*/
|
|
110
|
+
export interface CommentCreatedEvent extends BaseSDKEvent {
|
|
111
|
+
type: 'commentCreated';
|
|
112
|
+
commentId: string;
|
|
113
|
+
postId: string;
|
|
114
|
+
textLength: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Event emitted when a reply is created
|
|
119
|
+
*/
|
|
120
|
+
export interface ReplyCreatedEvent extends BaseSDKEvent {
|
|
121
|
+
type: 'replyCreated';
|
|
122
|
+
replyId: string;
|
|
123
|
+
commentId: string;
|
|
124
|
+
textLength: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Event emitted when content is deleted
|
|
129
|
+
*/
|
|
130
|
+
export interface ContentDeletedEvent extends BaseSDKEvent {
|
|
131
|
+
type: 'contentDeleted';
|
|
132
|
+
contentId: string;
|
|
133
|
+
contentKind: ContentKind;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Event emitted when a reaction is modified (added, changed, or removed)
|
|
138
|
+
*/
|
|
139
|
+
export interface ReactionModifiedEvent extends BaseSDKEvent {
|
|
140
|
+
type: 'reactionModified';
|
|
141
|
+
contentId: string;
|
|
142
|
+
contentKind: ContentKind;
|
|
143
|
+
previousReaction: ReactionKind | null;
|
|
144
|
+
newReaction: ReactionKind | null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Event emitted when a poll is voted on
|
|
149
|
+
*/
|
|
150
|
+
export interface PollVotedEvent extends BaseSDKEvent {
|
|
151
|
+
type: 'pollVoted';
|
|
152
|
+
contentId: string;
|
|
153
|
+
optionId: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Event emitted when content is reported
|
|
158
|
+
*/
|
|
159
|
+
export interface ContentReportedEvent extends BaseSDKEvent {
|
|
160
|
+
type: 'contentReported';
|
|
161
|
+
contentId: string;
|
|
162
|
+
reasons: ReportReason[];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Event emitted when a profile is reported
|
|
167
|
+
*/
|
|
168
|
+
export interface ProfileReportedEvent extends BaseSDKEvent {
|
|
169
|
+
type: 'profileReported';
|
|
170
|
+
profileId: string;
|
|
171
|
+
reasons: ReportReason[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Event emitted when gamification points are gained
|
|
176
|
+
*/
|
|
177
|
+
export interface GamificationPointsGainedEvent extends BaseSDKEvent {
|
|
178
|
+
type: 'gamificationPointsGained';
|
|
179
|
+
points: number;
|
|
180
|
+
action: GamificationPointsGainedAction;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Event emitted when gamification points are removed
|
|
185
|
+
*/
|
|
186
|
+
export interface GamificationPointsRemovedEvent extends BaseSDKEvent {
|
|
187
|
+
type: 'gamificationPointsRemoved';
|
|
188
|
+
points: number;
|
|
189
|
+
action: GamificationPointsRemovedAction;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Screen information for screen displayed events
|
|
194
|
+
*/
|
|
195
|
+
export interface ScreenInfo {
|
|
196
|
+
type: ScreenType;
|
|
197
|
+
feedId?: string;
|
|
198
|
+
relatedTopicId?: string | null;
|
|
199
|
+
postId?: string;
|
|
200
|
+
commentId?: string;
|
|
201
|
+
profileId?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Event emitted when a screen is displayed
|
|
206
|
+
*/
|
|
207
|
+
export interface ScreenDisplayedEvent extends BaseSDKEvent {
|
|
208
|
+
type: 'screenDisplayed';
|
|
209
|
+
screen: ScreenInfo;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Event emitted when a notification is clicked
|
|
214
|
+
*/
|
|
215
|
+
export interface NotificationClickedEvent extends BaseSDKEvent {
|
|
216
|
+
type: 'notificationClicked';
|
|
217
|
+
notificationId: string;
|
|
218
|
+
contentId: string | null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Event emitted when a post is clicked
|
|
223
|
+
*/
|
|
224
|
+
export interface PostClickedEvent extends BaseSDKEvent {
|
|
225
|
+
type: 'postClicked';
|
|
226
|
+
postId: string;
|
|
227
|
+
source: PostClickedSource;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Event emitted when the translation button is clicked
|
|
232
|
+
*/
|
|
233
|
+
export interface TranslationButtonClickedEvent extends BaseSDKEvent {
|
|
234
|
+
type: 'translationButtonClicked';
|
|
235
|
+
contentId: string;
|
|
236
|
+
viewTranslated: boolean;
|
|
237
|
+
contentKind: ContentKind;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Event emitted when the comment button is clicked
|
|
242
|
+
*/
|
|
243
|
+
export interface CommentButtonClickedEvent extends BaseSDKEvent {
|
|
244
|
+
type: 'commentButtonClicked';
|
|
245
|
+
postId: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Event emitted when the reply button is clicked
|
|
250
|
+
*/
|
|
251
|
+
export interface ReplyButtonClickedEvent extends BaseSDKEvent {
|
|
252
|
+
type: 'replyButtonClicked';
|
|
253
|
+
commentId: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Event emitted when the "see replies" button is clicked
|
|
258
|
+
*/
|
|
259
|
+
export interface SeeRepliesButtonClickedEvent extends BaseSDKEvent {
|
|
260
|
+
type: 'seeRepliesButtonClicked';
|
|
261
|
+
commentId: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Event emitted when a profile is modified
|
|
266
|
+
*/
|
|
267
|
+
export interface ProfileModifiedEvent extends BaseSDKEvent {
|
|
268
|
+
type: 'profileModified';
|
|
269
|
+
nicknameUpdated: boolean;
|
|
270
|
+
bioUpdated: boolean;
|
|
271
|
+
bioLength: number | null;
|
|
272
|
+
pictureUpdated: boolean;
|
|
273
|
+
hasPicture: boolean | null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Event emitted when a session starts
|
|
278
|
+
*/
|
|
279
|
+
export interface SessionStartedEvent extends BaseSDKEvent {
|
|
280
|
+
type: 'sessionStarted';
|
|
281
|
+
sessionId: string;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Event emitted when a session stops
|
|
286
|
+
*/
|
|
287
|
+
export interface SessionStoppedEvent extends BaseSDKEvent {
|
|
288
|
+
type: 'sessionStopped';
|
|
289
|
+
sessionId: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Union type of all possible SDK events
|
|
294
|
+
*/
|
|
295
|
+
export type SDKEvent =
|
|
296
|
+
| PostCreatedEvent
|
|
297
|
+
| CommentCreatedEvent
|
|
298
|
+
| ReplyCreatedEvent
|
|
299
|
+
| ContentDeletedEvent
|
|
300
|
+
| ReactionModifiedEvent
|
|
301
|
+
| PollVotedEvent
|
|
302
|
+
| ContentReportedEvent
|
|
303
|
+
| ProfileReportedEvent
|
|
304
|
+
| GamificationPointsGainedEvent
|
|
305
|
+
| GamificationPointsRemovedEvent
|
|
306
|
+
| ScreenDisplayedEvent
|
|
307
|
+
| NotificationClickedEvent
|
|
308
|
+
| PostClickedEvent
|
|
309
|
+
| TranslationButtonClickedEvent
|
|
310
|
+
| CommentButtonClickedEvent
|
|
311
|
+
| ReplyButtonClickedEvent
|
|
312
|
+
| SeeRepliesButtonClickedEvent
|
|
313
|
+
| ProfileModifiedEvent
|
|
314
|
+
| SessionStartedEvent
|
|
315
|
+
| SessionStoppedEvent;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy for handling URLs tapped inside the Octopus Community UI.
|
|
3
|
+
*
|
|
4
|
+
* When URL interception is enabled via `openUI({ interceptUrls: true })`,
|
|
5
|
+
* the app receives each tapped URL via `addNavigateToUrlListener`. The callback
|
|
6
|
+
* returns one of these strategies to decide who handles the URL.
|
|
7
|
+
*/
|
|
8
|
+
export enum UrlOpeningStrategy {
|
|
9
|
+
/**
|
|
10
|
+
* The URL has been handled by the app. The SDK will not open it.
|
|
11
|
+
* Use this when you open the URL in an in-app web view or handle it yourself.
|
|
12
|
+
*/
|
|
13
|
+
handledByApp = 'handledByApp',
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The URL should be opened by the Octopus SDK (system browser).
|
|
17
|
+
* The native layer will open the URL in the default browser when this is returned.
|
|
18
|
+
*/
|
|
19
|
+
handledByOctopus = 'handledByOctopus',
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OctopusReactNativeSdk } from './internals/nativeModule';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Force refresh the unseen notification count from the server.
|
|
5
|
+
*
|
|
6
|
+
* This method triggers a manual update of the notification badge count.
|
|
7
|
+
* The updated count will be emitted via the notSeenNotificationsCountChanged event.
|
|
8
|
+
* Use `addNotSeenNotificationsCountListener` to listen for count changes.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves when the update is complete.
|
|
11
|
+
* @throws An error if the SDK is not initialized or if the update fails.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Listen to count changes
|
|
16
|
+
* const subscription = addNotSeenNotificationsCountListener((count) => {
|
|
17
|
+
* console.log(`Unseen notifications: ${count}`);
|
|
18
|
+
* // Update your badge UI
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Manually refresh the count
|
|
22
|
+
* await updateNotSeenNotificationsCount();
|
|
23
|
+
*
|
|
24
|
+
* // Later, unsubscribe
|
|
25
|
+
* subscription.remove();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function updateNotSeenNotificationsCount(): Promise<void> {
|
|
29
|
+
return OctopusReactNativeSdk.updateNotSeenNotificationsCount();
|
|
30
|
+
}
|