T4B_Chat/utilities
2025-10-03 18:17:10 +05:30
..
constants.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
cookieUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
deepLinkUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
fcmUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
loaderUtils.tsx now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
notificationUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
permissionUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
README.md now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30
webViewUtils.ts now deep linking completed and loader also added for the app 2025-10-03 18:17:10 +05:30

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.

  • DeepLinkHandler class 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.

  • WebViewHandler class for WebView management
  • Navigation request handling and validation
  • Message processing and debug script injection

cookieUtils.ts

Handles cookie management for WebView authentication.

  • CookieHandler class for cookie operations
  • Platform-specific cookie retrieval (iOS/Android)
  • Session cookie validation and refresh functionality

fcmUtils.ts

Manages Firebase Cloud Messaging (FCM) functionality.

  • FCMHandler class 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 component
  • ProgressLoader - 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

  • handleKilledAppDeepLink(data) - Handle deep links from killed app
  • handleForegroundBackgroundDeepLink(data) - Handle deep links from foreground/background
  • navigateToChannel(channelId) - Navigate to specific channel
  • handleDeepLink(deepLink) - Process deep link URLs

WebView Handler

  • handleNavigation(request) - Handle WebView navigation requests
  • handleWebViewMessage(event, setWebViewCookies) - Process WebView messages
  • handleWebViewLoadEnd(currentChannel, isNavigating) - Handle load completion
  • injectDebugScript() - Inject debug script into WebView
  • getWebViewCookies() - Get authentication cookies
  • refreshWebViewCookies() - Set up periodic cookie refresh
  • getCookiesForUrl(url) - Get cookies for specific URL
  • setCookiesForUrl(url, cookies) - Set cookies for specific URL
  • clearAllCookies() - Clear all cookies
  • isValidSessionCookie(cookies) - Validate session cookies

FCM Handler

  • initializeNotifications() - Initialize FCM notifications
  • requestUserPermission() - Request notification permissions
  • getFcmToken() - Get FCM token
  • sendTokenToBackend(token) - Send token to backend
  • setupMessageListeners(appState) - Setup FCM message listeners

Constants

  • ALLOWED_DOMAIN - Base domain for the application
  • NAVIGATION_DELAYS - Timing constants for navigation delays
  • URL_PATTERNS - URL pattern templates
  • FCM_REGISTER_ENDPOINT - FCM registration endpoint
  • COOKIE_REFRESH_INTERVAL - Cookie refresh timing
  • NOTIFICATION_CONFIG - Notification channel configuration

Loader Components

  • CustomLoader - Main animated loader with chat icon
  • ProgressLoader - Loader with progress indicator
  • createOdooLoader() - Pre-configured Odoo loader
  • createChatLoader() - Pre-configured chat loader
  • createNavigationLoader() - Pre-configured navigation loader
  • LOADER_CONFIGS - Predefined loader configurations

Notification Utils

  • createNotificationChannel() - Creates Android notification channel
  • configureNotificationSettings() - Configures notification settings
  • showLocalNotification(options) - Shows local notification
  • shouldShowCustomNotification(appState) - Checks if custom notification should be shown
  • testNotification() - Test notification function

Permission Utils

  • requestNotificationPermission() - Requests notification permission
  • checkNotificationPermission() - Checks current permission status
  • needsNotificationPermission() - Checks if permission is needed
  • showPermissionExplanation() - Shows permission explanation dialog
  • showSettingsDialog() - Shows settings dialog for denied permissions

Architecture Benefits

  1. Separation of Concerns: Each utility handles a specific domain
  2. Reusability: Utilities can be easily reused across components
  3. Maintainability: Code is organized and easy to understand
  4. Testability: Each utility can be tested independently
  5. Type Safety: Proper TypeScript interfaces and types
  6. Documentation: Comprehensive JSDoc comments throughout