5.5 KiB
5.5 KiB
Utilities
This directory contains organized utility functions and modules for the T4B Chat application.
Files
notificationUtils.ts
Contains utility functions for creating notification channels, configuring settings, and showing local notifications.
permissionUtils.ts
Handles notification permission requests and checks for Android and iOS platforms.
deepLinkUtils.ts
Handles deep linking functionality for FCM notifications and chat navigation.
DeepLinkHandlerclass for managing deep links- Methods for handling killed app, foreground, and background deep links
- Channel ID extraction and URL building utilities
webViewUtils.ts
Manages WebView functionality, navigation, and message handling.
WebViewHandlerclass for WebView management- Navigation request handling and validation
- Message processing and debug script injection
cookieUtils.ts
Handles cookie management for WebView authentication.
CookieHandlerclass for cookie operations- Platform-specific cookie retrieval (iOS/Android)
- Session cookie validation and refresh functionality
fcmUtils.ts
Manages Firebase Cloud Messaging (FCM) functionality.
FCMHandlerclass for FCM operations- Token management and backend communication
- Message handling for different app states
constants.ts
Centralized configuration constants for the entire application.
- Domain configuration
- FCM endpoints
- Navigation delays
- URL patterns
- Platform configuration
- Notification settings
loaderUtils.tsx
Beautiful custom loading components with animations and chat icons.
CustomLoader- Main animated loader componentProgressLoader- Loader with progress indicator- Predefined loader configurations for different scenarios
- Smooth animations and transitions
Usage
Import the utilities you need in your components:
import { showLocalNotification, createNotificationChannel } from './utilities/notificationUtils';
import { requestNotificationPermission, checkNotificationPermission } from './utilities/permissionUtils';
import { createDeepLinkHandler } from './utilities/deepLinkUtils';
import { createWebViewHandler } from './utilities/webViewUtils';
import { createCookieHandler } from './utilities/cookieUtils';
import { createFCMHandler } from './utilities/fcmUtils';
import { ALLOWED_DOMAIN, NAVIGATION_DELAYS, URL_PATTERNS } from './utilities/constants';
import { CustomLoader, createOdooLoader, createChatLoader } from './utilities/loaderUtils';
Classes and Methods
Deep Link Handler
handleKilledAppDeepLink(data)- Handle deep links from killed apphandleForegroundBackgroundDeepLink(data)- Handle deep links from foreground/backgroundnavigateToChannel(channelId)- Navigate to specific channelhandleDeepLink(deepLink)- Process deep link URLs
WebView Handler
handleNavigation(request)- Handle WebView navigation requestshandleWebViewMessage(event, setWebViewCookies)- Process WebView messageshandleWebViewLoadEnd(currentChannel, isNavigating)- Handle load completioninjectDebugScript()- Inject debug script into WebView
Cookie Handler
getWebViewCookies()- Get authentication cookiesrefreshWebViewCookies()- Set up periodic cookie refreshgetCookiesForUrl(url)- Get cookies for specific URLsetCookiesForUrl(url, cookies)- Set cookies for specific URLclearAllCookies()- Clear all cookiesisValidSessionCookie(cookies)- Validate session cookies
FCM Handler
initializeNotifications()- Initialize FCM notificationsrequestUserPermission()- Request notification permissionsgetFcmToken()- Get FCM tokensendTokenToBackend(token)- Send token to backendsetupMessageListeners(appState)- Setup FCM message listeners
Constants
ALLOWED_DOMAIN- Base domain for the applicationNAVIGATION_DELAYS- Timing constants for navigation delaysURL_PATTERNS- URL pattern templatesFCM_REGISTER_ENDPOINT- FCM registration endpointCOOKIE_REFRESH_INTERVAL- Cookie refresh timingNOTIFICATION_CONFIG- Notification channel configuration
Loader Components
CustomLoader- Main animated loader with chat iconProgressLoader- Loader with progress indicatorcreateOdooLoader()- Pre-configured Odoo loadercreateChatLoader()- Pre-configured chat loadercreateNavigationLoader()- Pre-configured navigation loaderLOADER_CONFIGS- Predefined loader configurations
Notification Utils
createNotificationChannel()- Creates Android notification channelconfigureNotificationSettings()- Configures notification settingsshowLocalNotification(options)- Shows local notificationshouldShowCustomNotification(appState)- Checks if custom notification should be showntestNotification()- Test notification function
Permission Utils
requestNotificationPermission()- Requests notification permissioncheckNotificationPermission()- Checks current permission statusneedsNotificationPermission()- Checks if permission is neededshowPermissionExplanation()- Shows permission explanation dialogshowSettingsDialog()- Shows settings dialog for denied permissions
Architecture Benefits
- Separation of Concerns: Each utility handles a specific domain
- Reusability: Utilities can be easily reused across components
- Maintainability: Code is organized and easy to understand
- Testability: Each utility can be tested independently
- Type Safety: Proper TypeScript interfaces and types
- Documentation: Comprehensive JSDoc comments throughout