Files
Morgan Pretty 55ba2aa8ed Merge remote-tracking branch 'upstream/dev' into feature/libsession-message-wrapping
# Conflicts:
#	Session/Conversations/ConversationVC+Interaction.swift
#	Session/Conversations/ConversationVC.swift
#	Session/Conversations/Settings/ThreadSettingsViewModel.swift
#	Session/Home/GlobalSearch/GlobalSearchViewController.swift
#	Session/Meta/AppDelegate.swift
#	SessionMessagingKit/Open Groups/OpenGroupManager.swift
#	SessionMessagingKit/Sending & Receiving/MessageReceiver.swift
#	SessionMessagingKit/Utilities/MessageWrapper.swift
2025-12-17 13:23:36 +11:00

146 lines
5.5 KiB
Swift

// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
import UIKit
import AVFoundation
import UniformTypeIdentifiers
import SessionUIKit
import SessionNetworkingKit
import SessionMessagingKit
import SessionUtilitiesKit
// MARK: - SessionSNUIKitConfig
internal struct SessionSNUIKitConfig: SNUIKit.ConfigType {
private let dependencies: Dependencies
var maxFileSize: UInt { Network.maxFileSize }
var isStorageValid: Bool { dependencies[singleton: .storage].isValid }
var isRTL: Bool { Dependencies.isRTL }
let initialMainScreenScale: CGFloat
let initialMainScreenMaxDimension: CGFloat
// MARK: - Initialization
@MainActor init(using dependencies: Dependencies) {
self.dependencies = dependencies
self.initialMainScreenScale = UIScreen.main.scale
self.initialMainScreenMaxDimension = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
}
// MARK: - Functions
func themeChanged(_ theme: Theme, _ primaryColor: Theme.PrimaryColor, _ matchSystemNightModeSetting: Bool) {
let mutation: LibSession.Mutation? = try? dependencies.mutate(cache: .libSession) { cache in
try cache.perform(for: .local) {
cache.set(.theme, theme)
cache.set(.themePrimaryColor, primaryColor)
cache.set(.themeMatchSystemDayNightCycle, matchSystemNightModeSetting)
}
}
dependencies[singleton: .storage].writeAsync { db in
try mutation?.upsert(db)
}
}
func navBarSessionIcon() -> NavBarSessionIcon {
switch (dependencies[feature: .serviceNetwork], dependencies[feature: .forceOffline]) {
case (.mainnet, false): return NavBarSessionIcon()
case (.testnet, _), (.mainnet, true):
return NavBarSessionIcon(
showDebugUI: true,
serviceNetworkTitle: dependencies[feature: .serviceNetwork].title,
isMainnet: (dependencies[feature: .serviceNetwork] == .mainnet),
isOffline: dependencies[feature: .forceOffline]
)
}
}
func persistentTopBannerChanged(warningKey: String?) {
dependencies[defaults: .appGroup, key: .topBannerWarningToShow] = warningKey
}
func cachedContextualActionInfo(tableViewHash: Int, sideKey: String) -> [Int: Any]? {
dependencies[cache: .general].contextualActionLookupMap
.getting(tableViewHash)?
.getting(sideKey)
}
func cacheContextualActionInfo(tableViewHash: Int, sideKey: String, actionIndex: Int, actionInfo: Any) {
dependencies.mutate(cache: .general) { cache in
let updatedLookup = (cache.contextualActionLookupMap[tableViewHash] ?? [:])
.setting(
sideKey,
((cache.contextualActionLookupMap[tableViewHash] ?? [:]).getting(sideKey) ?? [:])
.setting(actionIndex, actionInfo)
)
cache.contextualActionLookupMap[tableViewHash] = updatedLookup
}
}
func removeCachedContextualActionInfo(tableViewHash: Int, keys: [String]) {
dependencies.mutate(cache: .general) { cache in
keys.forEach { key in
cache.contextualActionLookupMap[tableViewHash]?[key] = nil
}
if cache.contextualActionLookupMap[tableViewHash]?.isEmpty == true {
cache.contextualActionLookupMap[tableViewHash] = nil
}
}
}
func shouldShowStringKeys() -> Bool {
return dependencies[feature: .showStringKeys]
}
func assetInfo(for path: String, utType: UTType, sourceFilename: String?) -> (asset: AVURLAsset, isValidVideo: Bool, cleanup: () -> Void)? {
guard
let result: (asset: AVURLAsset, utType: UTType, cleanup: () -> Void) = AVURLAsset.asset(
for: path,
utType: utType,
sourceFilename: sourceFilename,
using: dependencies
)
else { return nil }
return (result.asset, MediaUtils.isValidVideo(asset: result.asset, utType: result.utType), result.cleanup)
}
func mediaDecoderDefaultImageOptions() -> CFDictionary {
return dependencies[singleton: .mediaDecoder].defaultImageOptions
}
func mediaDecoderDefaultThumbnailOptions(maxDimension: CGFloat) -> CFDictionary {
return dependencies[singleton: .mediaDecoder].defaultThumbnailOptions(maxDimension: maxDimension)
}
func mediaDecoderSource(for url: URL) -> CGImageSource? {
return dependencies[singleton: .mediaDecoder].source(for: url)
}
func mediaDecoderSource(for data: Data) -> CGImageSource? {
return dependencies[singleton: .mediaDecoder].source(for: data)
}
@MainActor func numberOfCharactersLeft(for text: String) -> Int {
return dependencies[singleton: .sessionProManager].numberOfCharactersLeft(for: text)
}
func urlStringProvider() -> StringProvider.Url {
return Constants.urls
}
func buildVariantStringProvider() -> StringProvider.BuildVariant {
return Constants.buildVariants
}
func proClientPlatformStringProvider(for platform: SessionProUI.ClientPlatform) -> StringProvider.ClientPlatform {
switch platform {
case .iOS: return Constants.PaymentProvider.appStore
case .android: return Constants.PaymentProvider.playStore
}
}
}