### Install Development Tools with Homebrew Source: https://github.com/overtake/telegramswift/blob/master/INSTALL.md Install necessary development tools such as cmake, ninja, openssl, and others using Homebrew. ```bash brew install cmake ninja openssl@1.1 zlib autoconf libtool automake yasm pkg-config ``` -------------------------------- ### Install Homebrew Package Manager Source: https://github.com/overtake/telegramswift/blob/master/INSTALL.md Install Homebrew, a package manager for macOS, which is required to install other development tools. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Clone TelegramSwift Repository Source: https://github.com/overtake/telegramswift/blob/master/INSTALL.md Clone the TelegramSwift repository including all submodules to get the complete project. ```bash git clone https://github.com/overtake/TelegramSwift.git --recurse-submodules ``` -------------------------------- ### Configure Frameworks Script Source: https://github.com/overtake/telegramswift/blob/master/INSTALL.md Execute the configure_frameworks.sh script to set up the project's frameworks. Ensure the project directory is correctly specified. ```bash sh %project_dir%/scripts/configure_frameworks.sh ``` -------------------------------- ### Build Google Test as a standalone project Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Standard commands to initialize a build directory and generate native build scripts using CMake. ```bash mkdir mybuild # Create a directory to hold the build output. cd mybuild cmake ${GTEST_DIR} # Generate native build scripts. ``` ```bash cmake -Dgtest_build_samples=ON ${GTEST_DIR} ``` -------------------------------- ### Configure ColorPalette and Themes Source: https://context7.com/overtake/telegramswift/llms.txt Manages theme configuration, wallpaper settings, and interactive theme updates. ```swift // Theme palette configuration public struct ColorPalette { public let isDark: Bool public let tinted: Bool public let name: String public let parent: TelegramBuiltinTheme public let wallpaper: PaletteWallpaper public let copyright: String public let accentList: [NSColor] // Core colors public let background: NSColor public let text: NSColor public let grayText: NSColor public let link: NSColor public let accent: NSColor // ... many more color properties } // Wallpaper types let noWallpaper = PaletteWallpaper.none let builtinWallpaper = PaletteWallpaper.builtin let colorWallpaper = PaletteWallpaper.color(NSColor.blue) let urlWallpaper = PaletteWallpaper.url("https://t.me/bg/pattern") // Update theme interactively _ = updateThemeInteractivetly( accountManager: context.sharedContext.accountManager ) { settings in return settings .withUpdatedPalette(newPalette) .withUpdatedCloudTheme(cloudTheme) .updateWallpaper { value in return value.withUpdatedWallpaper(newWallpaper) } } // Apply cloud theme let applySignal = downloadAndApplyCloudTheme( context: context, theme: cloudTheme, palette: customPalette, install: true ) ``` -------------------------------- ### Configure Premium Settings and Limits Source: https://context7.com/overtake/telegramswift/llms.txt Access premium configuration, check feature availability based on boost levels, and retrieve premium product pricing. ```swift // Get premium configuration from app config let premiumConfig = PremiumConfiguration.with(appConfiguration: context.appConfiguration) // Check if premium is disabled if premiumConfig.isPremiumDisabled { // Handle premium unavailable } // Access premium limits let limits = context.premiumLimits let captionLimit = context.isPremium ? limits.caption_length_limit_premium : limits.caption_length_limit_default // Check boost levels for features if boostLevel >= premiumConfig.minChannelNameColorLevel { // Enable name color customization } if boostLevel >= premiumConfig.minChannelWallpaperLevel { // Enable channel wallpaper } // Premium gift products let products = context.premiumProductsAndPrice.0 for product in products { let months = product.months let price = product.price let pricePerMonth = product.pricePerMonth } ``` -------------------------------- ### Handle Push Notifications and Alerts Source: https://context7.com/overtake/telegramswift/llms.txt Initialize the notification manager and configure bindings for navigation, message reading, and passlock state management. ```swift // Initialize notification manager let notificationManager = SharedNotificationManager( activeAccounts: sharedContext.activeAccounts.map { ($0.0, $0.1.map { ($0.0, $0.1) }) }, appEncryption: appEncryption, accountManager: accountManager, bindings: notificationBindings ) // Configure notification bindings let bindings = SharedNotificationBindings( navigateToChat: { account, peerId in // Navigate to chat from notification tap }, navigateToThread: { account, threadId, fromId, threadData in // Navigate to thread from notification }, updateCurrectController: { // Refresh current controller }, applyMaxReadIndexInteractively: { index in // Mark messages as read } ) // Check passlock state let isLocked = notificationManager.isLocked // Update passlock notificationManager.updatePasslock( context.sharedContext.accountManager.transaction { transaction in return transaction.getAccessChallengeData() != .none } ) ``` -------------------------------- ### Configure SplitView Layouts in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Control responsive layout proportions and observe state changes for single, dual, or minimized views. ```swift // Configure split view proportions splitView.setProportion( proportion: SplitProportion(min: 380, max: 300 + 350), state: .single ) splitView.setProportion( proportion: SplitProportion(min: 300 + 350, max: 300 + 350 + 600), state: .dual ) // Switch layout states context.bindings.switchSplitLayout(.single) // Single column context.bindings.switchSplitLayout(.dual) // Two columns context.bindings.switchSplitLayout(.minimisize) // Minimized sidebar // Access current layout let currentLayout = context.layout // Observe layout changes context.layoutValue.start(next: { state in switch state { case .single: // Handle single column layout case .dual: // Handle dual column layout case .minimisize: // Handle minimized layout } }) ``` -------------------------------- ### Integrate Google Test into an existing project Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md CMake commands to download, configure, and add the Google Test subdirectory to an existing build process. ```cmake # Download and unpack googletest at configure time configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) if(result) message(FATAL_ERROR "CMake step for googletest failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) if(result) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() # Prevent overriding the parent project's compiler/linker # settings on Windows set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add googletest directly to our build. This defines # the gtest and gtest_main targets. add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) # The gtest/gtest_main targets carry header search path ``` -------------------------------- ### Register Global Keyboard Shortcuts Source: https://context7.com/overtake/telegramswift/llms.txt Define keyboard shortcut handlers for navigation, app locking, search, and account switching using the window handler system. ```swift // Quick folder/chat navigation (Cmd+1-9) window.set(handler: { _ -> KeyHandlerResult in self.openChat(0, false) // Open first chat return .invoked }, with: self, for: .One, priority: .low, modifierFlags: [.command]) // Saved messages (Cmd+0) window.set(handler: { _ -> KeyHandlerResult in rightController.push(ChatController( context: context, chatLocation: .peer(context.peerId) )) return .invoked }, with: self, for: .Zero, priority: .low, modifierFlags: [.command]) // Lock app (Cmd+L) window.set(handler: { _ -> KeyHandlerResult in // Trigger passlock appDelegate?.sharedApplicationContextValue?.notificationManager.updatePasslock(...) return .invoked }, with: self, for: .L, priority: .supreme, modifierFlags: [.command]) // Global search (Cmd+K or Cmd+Shift+F) window.set(handler: { _ -> KeyHandlerResult in leftController.focusSearch(animated: true) return .invoked }, with: self, for: .K, priority: .supreme, modifierFlags: [.command]) // Shortcut list (Cmd+/) window.set(handler: { _ -> KeyHandlerResult in context.bindings.rootNavigation().push(ShortcutListController(context: context)) return .invoked }, with: self, for: .Slash, priority: .low, modifierFlags: [.command]) // Account switching (Ctrl+1-9) window.set(handler: { _ -> KeyHandlerResult in self.switchAccount(1, true) // Switch to first account return .invoked }, with: self, for: .One, priority: .low, modifierFlags: [.control]) ``` -------------------------------- ### Build Google Test as a Shared Library Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Compiler flags for creating and linking against Google Test as a shared library. ```bash -DGTEST_CREATE_SHARED_LIBRARY=1 ``` ```bash -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ``` -------------------------------- ### Manage Call Interfaces in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Use these patterns to initiate calls, configure voice settings, and access active call sessions within the application context. ```swift // Initiate a phone call let callResult = phoneCall( context: context, peerId: userPeerId, isVideo: false ) _ = callResult.start(next: { result in applyUIPCallResult(context, result) }) // Call settings configuration struct VoiceCallSettings { let pushToTalk: PushToTalk? let audioInputDeviceId: String? let audioOutputDeviceId: String? let cameraInputDeviceId: String? } // Access call session if let callSession = context.sharedContext.getCrossAccountCallSession() { // Handle active call rightController.callHeader?.show(true, contextObject: callSession) } ``` -------------------------------- ### Initialize and Navigate ChatController Source: https://context7.com/overtake/telegramswift/llms.txt Manages the instantiation and navigation of chat interfaces for history, scheduled messages, pinned items, and threads. ```swift // Initialize and push a chat controller let chatController = ChatController( context: context, chatLocation: .peer(peerId), mode: .history, focusTarget: ChatFocusTarget(messageId: targetMessageId), initialAction: nil ) context.bindings.rootNavigation().push(chatController) // Navigate to chat with specific message focus navigateToChat( navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId), mode: .history, focusTarget: ChatFocusTarget(messageId: messageId, string: "search text"), initialAction: nil ) // Open scheduled messages let scheduledController = ChatController( context: context, chatLocation: .peer(peerId), mode: .scheduled ) // Open pinned messages view let pinnedController = ChatController( context: context, chatLocation: .peer(peerId), mode: .pinned ) // Open reply thread/comments let threadController = ChatController( context: context, chatLocation: .thread(replyThreadMessage), mode: .thread(mode: .comments(origin: originMessageId)) ) ``` -------------------------------- ### Configure Google Test as an external project Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Template for a CMakeLists.txt.in file used to download and configure Google Test during the build's configure step. ```cmake cmake_minimum_required(VERSION 2.8.2) project(googletest-download NONE) include(ExternalProject) ExternalProject_Add(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG master SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" ) ``` -------------------------------- ### Initialize and Configure ChatInteraction Source: https://context7.com/overtake/telegramswift/llms.txt Handles chat-related user actions, message operations, and media attachments through a centralized interface. ```swift // Initialize chat interaction let chatInteraction = ChatInteraction( chatLocation: .peer(peerId), context: context, mode: .history, isLogInteraction: false, disableSelectAbility: false, isGlobalSearchMessage: false, isPeerSavedMessages: false ) // Update presentation state chatInteraction.update(animated: true) { state in return state.updatedInterfaceState { interface in interface.withUpdatedInputState(newInputState) } } // Set up message actions chatInteraction.sendMessage = { silent, scheduleDate, effect in // Handle sending message } chatInteraction.forwardMessages = { messages in // Handle message forwarding } chatInteraction.deleteMessages = { messageIds in // Handle message deletion } chatInteraction.setupReplyMessage = { message, replySubject in // Set up reply to message } chatInteraction.beginEditingMessage = { message in // Begin editing an existing message } // Media attachments chatInteraction.attachFile = { asMedia in // Open file picker } chatInteraction.attachPhotoOrVideo = { type in // Open photo/video picker } chatInteraction.sendMedia = { containers in // Send media files } // Voice/Video calls chatInteraction.call(isVideo: false) // Start voice call chatInteraction.call(isVideo: true) // Start video call ``` -------------------------------- ### Integrate Google Test with CMake Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Configure include directories and link against Google Test within a CMake project. ```cmake # dependencies automatically when using CMake 2.8.11 or # later. Otherwise we have to add them here ourselves. if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include") endif() # Now simply link against gtest or gtest_main as needed. Eg add_executable(example example.cpp) target_link_libraries(example gtest_main) add_test(NAME example_test COMMAND example) ``` -------------------------------- ### Configure InputViewTheme Source: https://context7.com/overtake/telegramswift/llms.txt Sets appearance properties for text input fields, including quote styling and font sizing. ```swift let inputTheme = InputViewTheme( quote: InputViewTheme.Quote( foreground: PeerNameColors.Colors(main: .blue, secondary: nil, tertiary: nil), icon: quoteIcon, collapse: collapseIcon, expand: expandIcon ), indicatorColor: .systemBlue, backgroundColor: .white, selectingColor: .lightGray, textColor: .black, accentColor: .systemBlue, grayTextColor: .gray, fontSize: 14.0 ) // Update quote colors let updatedTheme = inputTheme.withUpdatedQuote(newColors) // Update font size let resizedTheme = inputTheme.withUpdatedFontSize(16.0) ``` -------------------------------- ### Manage Stack-Based Navigation in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Use the MajorNavigationController to push, pop, or navigate through the view controller stack. ```swift // Get root navigation let navigation = context.bindings.rootNavigation() // Push a new controller navigation.push(viewController, animated: true) // Push with custom style navigation.push( controller, animated: true, style: .push ) // Pop current controller navigation.back(animated: true) // Go to empty state navigation.gotoEmpty(animated: false) // Access current controller if let chatController = navigation.controller as? ChatController { // Handle chat controller } ``` -------------------------------- ### Manage Message Reactions and Effects Source: https://context7.com/overtake/telegramswift/llms.txt Initialize the reactions manager and define handlers for star balance checks, reaction animations, and full-screen emoji effects. ```swift // Initialize reactions manager let reactions = Reactions(context.engine) reactions.isPremium = context.isPremium // Check stars balance for star reactions reactions.checkStarsAmount = { amount, peerId in return combineLatest( context.starsContext.state .filter { $0 != nil } .map { $0! } .take(1) .map { $0.balance.value >= amount }, starsAllowed ) } // Handle reaction effects chatInteraction.runReactionEffect = { reaction, messageId in // Play reaction animation } // Update message reactions chatInteraction.updateReactions = { messageId, reaction, completion in // Update reaction on message completion(true) } // Emoji screen effects chatInteraction.runEmojiScreenEffect = { emoji, message, isIncoming, mirror in // Play full-screen emoji animation } chatInteraction.runPremiumScreenEffect = { message, isIncoming, mirror in // Play premium sticker effect } ``` -------------------------------- ### Open Peer Profiles in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Navigate to user, group, or channel profiles using the PeerInfoController or account switching actions. ```swift // Open peer info PeerInfoController.push( navigation: context.bindings.rootNavigation(), context: context, peerId: peerId ) // Navigate to profile with launch settings context.sharedContext.switchToAccount( id: account.id, action: .profile(EnginePeer(peer), necessary: true) ) // Open user profile from chat chatInteraction.openInfo = { peerId, openChat, postId, initialAction in if openChat { // Navigate to chat } else { // Open profile PeerInfoController.push( navigation: context.bindings.rootNavigation(), context: context, peerId: peerId ) } } ``` -------------------------------- ### Manage AccountContext and Application State Source: https://context7.com/overtake/telegramswift/llms.txt Initializes the shared account context and provides access to user session data, premium status, and engine operations. ```swift // Creating and using AccountContext let sharedContext = SharedAccountContext( accountManager: accountManager, networkArguments: networkArguments, rootPath: rootPath, encryptionParameters: encryptionParameters, appEncryption: appEncryption, displayUpgradeProgress: displayUpgrade ) // AccountContext initialization within AuthorizedApplicationContext let context = AccountContext( sharedContext: sharedApplicationContext.sharedContext, window: window, account: account ) // Accessing premium status if context.isPremium { // Enable premium features } // Get current timestamp with server time difference let serverTimestamp = context.timestamp // Access the Telegram engine for API operations let engine = context.engine // Check app configuration values let config = context.appConfiguration let isFeatureEnabled = config.getBoolValue("feature_key", orElse: false) ``` -------------------------------- ### Define Chat Display Modes Source: https://context7.com/overtake/telegramswift/llms.txt Configures how a chat is rendered, including support for threads, scheduled messages, and custom business content. ```swift // Standard history mode let historyMode = ChatMode.history // Scheduled messages mode let scheduledMode = ChatMode.scheduled // Pinned messages only let pinnedMode = ChatMode.pinned // Reply thread modes let commentsMode = ChatMode.thread(mode: .comments(origin: messageId)) let repliesMode = ChatMode.thread(mode: .replies(origin: messageId)) let topicMode = ChatMode.thread(mode: .topic(origin: messageId)) let savedMessagesMode = ChatMode.thread(mode: .savedMessages(origin: messageId)) // Custom content modes for business features let greetingMode = ChatMode.customChatContents(contents: greetingContents) let awayMode = ChatMode.customChatContents(contents: awayContents) // Check mode properties if mode.isThreadMode { // Handle thread-specific UI } if let originId = mode.originId { // Access the origin message ID } ``` -------------------------------- ### Manage Group Calls in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Handle group call joining, context access, and UI state management for participants and media sources. ```swift // Join a group call chatInteraction.joinGroupCall = { activeCall, inviteHash in // activeCall contains CachedChannelData.ActiveCall // inviteHash is optional String for invite links } // Access group call context if let groupCallContext = context.sharedContext.getCrossAccountGroupCall() { // Show group call header rightController.callHeader?.show(true, contextObject: groupCallContext) } // Group call UI state management struct GroupCallUIState { let participants: [GroupCallParticipant] let dominantSpeaker: PeerId? let videoSources: [PeerId: VideoSource] let isMuted: Bool let isVideoEnabled: Bool } ``` -------------------------------- ### Configure Pthread Support Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Manually force the detection of pthread support using compiler flags. ```bash -DGTEST_HAS_PTHREAD=1 ``` ```bash -DGTEST_HAS_PTHREAD=0 ``` -------------------------------- ### Update Configuration for Forking Source: https://github.com/overtake/telegramswift/blob/master/INSTALL.md Modify configuration files when developing a fork. This includes changing the bundle identifier, API ID, API Hash, and potentially other settings like SFEED_URL and APPCENTER_SECRET. ```swift apiId = "YOUR_API_ID" apiHash = "YOUR_API_HASH" teamId = "YOUR_TEAM_ID" ``` -------------------------------- ### Navigate via MainViewController in Swift Source: https://context7.com/overtake/telegramswift/llms.txt Access the primary navigation controller to switch tabs, show preferences, or trigger global searches. ```swift // Access main controller through context bindings let mainController = context.bindings.mainController() // Navigate to chat list tab mainController.tabController.select(index: mainController.chatIndex) // Navigate to settings tab mainController.tabController.select(index: mainController.settingsIndex) // Show preferences mainController.showPreferences() // Focus search field mainController.focusSearch(animated: true) // Global search context.bindings.globalSearch("search query", peerId, cachedSearchMessages) ``` -------------------------------- ### Avoid Macro Name Clashes Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/third_party/googletest/src/README.md Rename conflicting Google Test macros by defining specific compiler flags. ```bash -DGTEST_DONT_DEFINE_FOO=1 ``` ```cpp GTEST_TEST(SomeTest, DoesThis) { ... } ``` ```cpp TEST(SomeTest, DoesThis) { ... } ``` -------------------------------- ### Define ChatLocation Navigation Types Source: https://context7.com/overtake/telegramswift/llms.txt Defines various chat navigation targets including direct peers, threads, and saved messages. ```swift // Navigate to a peer's chat let peerLocation = ChatLocation.peer(peerId) // Navigate to a thread/topic within a channel or group let threadLocation = ChatLocation.thread(ChatReplyThreadMessage( peerId: channelPeerId, threadId: threadId, channelMessageId: nil, isChannelPost: false, isForumPost: true, isMonoforumPost: false, maxMessage: nil, maxReadIncomingMessageId: nil, maxReadOutgoingMessageId: nil, unreadCount: 0, initialFilledHoles: IndexSet(), initialAnchor: .automatic, isNotAvailable: false )) // Create saved messages thread location let savedLocation = ChatLocation.makeSaved(accountPeerId, peerId: targetPeerId) // Access location properties let peerId = chatLocation.peerId let threadId = chatLocation.threadId let threadMsgId = chatLocation.threadMsgId ``` -------------------------------- ### vpx_codec_encode Function Source: https://github.com/overtake/telegramswift/blob/master/core-xprojects/libvpx/source/usage_cx.dox The vpx_codec_encode() function is central to the encoding loop, processing raw images to produce compressed data packets. The 'deadline' parameter influences the time spent encoding each frame. ```APIDOC ## vpx_codec_encode Function ### Description Processes raw images to produce packets of compressed data. ### Method N/A (Function documentation) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Additional Information - The `deadline` parameter controls the amount of time in microseconds the encoder should spend working on the frame. For more information on the `deadline` parameter, see \ref usage_deadline. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.