Remove dead code and simplify codebase (#436)

* refactor: remove dead code and consolidate system messages

- Delete 3 unused functions in ShareViewController (36 lines)
- Extract addSystemMessage() helper to eliminate duplication (120+ lines)
- Remove 22 'let _ =' wasteful computations across multiple files
- Net reduction of 215 lines of dead/duplicate code
- Improves maintainability and reduces technical debt

* fix: remove remaining unused variables to eliminate compiler warnings

- Remove unused senderNoiseKey in ChatViewModel
- Remove unused lastSuccess variable in BluetoothMeshService
- Eliminates all compiler warnings related to unused values

* refactor: remove all dead legacy and migration code

- Remove unused migrateSession() functions (never called in production)
  - NoiseSession.migrateSession() - 13 lines
  - NoiseEncryptionService.migratePeerSession() - 18 lines
  - Test for migration functionality - 17 lines

- Remove unnecessary keychain cleanup code (no legacy data existed)
  - cleanupLegacyKeychainItems() - 62 lines
  - aggressiveCleanupLegacyItems() - 72 lines
  - resetCleanupFlag() - 4 lines
  - Simplified panic mode to just use deleteAllKeychainData()

Total removed: 194 lines of dead/unnecessary code

Analysis revealed:
- KeychainManager introduced July 5, 2025
- Cleanup code added July 15, 2025 (10 days later)
- Legacy service names were never used in production
- Migration functions were incomplete implementation never called
- Peer ID rotation remains active (not legacy)

* Remove dead code and simplify codebase

- Remove unused BinaryEncodable protocol and BinaryMessageType enum
- Delete MockNoiseSession.swift (never used in tests)
- Remove all relay detection code (hardcoded to false)
  - Removed isRelayConnected property from BitchatPeer
  - Removed relayConnected case from ConnectionState enum
  - Cleaned up relay-related UI indicators in ContentView
  - Removed relay status checks from ChatViewModel
- Simplified peer connection logic by removing relay layer

Total: 169 lines removed across 5 files

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-08-12 11:33:08 +02:00
committed by GitHub
co-authored by jack
parent 7a7c89e689
commit 275f0ebaaf
13 changed files with 57 additions and 626 deletions
@@ -138,44 +138,6 @@ class ShareViewController: SLComposeServiceViewController {
// MARK: - Helper Methods
private func handleSharedText(_ text: String) {
// Save to shared user defaults to pass to main app
saveToSharedDefaults(content: text, type: "text")
openMainApp()
}
private func handleSharedURL(_ url: URL) {
// Get the page title if available from the extension context
var pageTitle: String? = nil
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
pageTitle = item.attributedContentText?.string ?? item.attributedTitle?.string
}
// Create a structured format for URL sharing
let urlData: [String: String] = [
"url": url.absoluteString,
"title": pageTitle ?? url.host ?? "Shared Link"
]
// Convert to JSON string
if let jsonData = try? JSONSerialization.data(withJSONObject: urlData),
let jsonString = String(data: jsonData, encoding: .utf8) {
saveToSharedDefaults(content: jsonString, type: "url")
} else {
// Fallback to simple URL
saveToSharedDefaults(content: url.absoluteString, type: "url")
}
openMainApp()
}
private func handleSharedImage(_ image: UIImage) {
// For now, we'll just notify that image sharing isn't supported
// In the future, we could implement image sharing via the mesh
saveToSharedDefaults(content: "Image sharing coming soon!", type: "image")
openMainApp()
}
private func saveToSharedDefaults(content: String, type: String) {
// Use app groups to share data between extension and main app
guard let userDefaults = UserDefaults(suiteName: "group.chat.bitchat") else {