mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 16:05:19 +00:00
Refactor/robustness (#446)
* Refactor BitChat for improved robustness and performance Major refactoring to simplify architecture and fix critical issues: Architecture Improvements: - Replace complex BluetoothMeshService with simplified SimplifiedBluetoothService - Consolidate message routing and peer management into unified services - Remove redundant caching layers and optimize performance Bug Fixes: - Fix critical BLE peer mapping corruption in mesh networks - Fix encrypted message routing failures in multi-peer scenarios - Fix app freezes and Main Thread Checker warnings - Fix BLE message delivery in dual-role connections - Fix favorite toggle UI not updating instantly - Fix Nostr offline messaging with 24-hour message filtering Features: - Add command processor for chat commands - Add autocomplete service for mentions and commands - Improve private chat management with dedicated service - Add unified peer service for consistent state management Performance: - Optimize BLE reconnection speed - Reduce excessive logging throughout codebase - Improve message deduplication efficiency - Optimize UI updates and state management * Improvements refactor robust (#441) * remove unused code * remove more * TLV for announcement * restore * restore * restore? * messages tlv too (#442) * Fix Nostr notification and read receipt issues, add TLV encoding, cleanup unused code ## Notification & Read Receipt Fixes - Fixed toolbar notification icon appearing incorrectly on app restart for already-read messages - Fixed read receipts being incorrectly deleted on startup when privateChats was empty - Fixed messages not being marked as read when opening chat for first time - Fixed senderPeerID not being updated during message consolidation - Added startup phase logic to block old messages (>30s) while allowing recent ones - Fixed unread status checking across all storage locations (ephemeral, stable Noise keys, temporary Nostr IDs) ## TLV Encoding Implementation - Implemented Type-Length-Value encoding for private message payloads - Added PrivateMessagePacket struct with TLV encode/decode methods - Enhanced message structure for better extensibility and robustness ## Code Cleanup - Removed unused PeerStateManager class and related dependencies - Removed dead protocol types (DeliveryAck, ProtocolAck/Nack, NoiseIdentityAnnouncement) - Cleaned up BitchatDelegate by removing unused methods - Removed excessive debug logging throughout ChatViewModel - Added test-only ProtocolNack helper for integration tests ## Technical Details - Messages stored under three ID types: ephemeral peer IDs, stable Noise key hexes, temporary Nostr IDs - Fixed cleanupOldReadReceipts() to skip when privateChats is empty or during startup - Updated message consolidation to properly update senderPeerID - Restored NIP-17 timestamp randomization (±15 minutes) for privacy --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com> Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
@@ -397,7 +397,7 @@ struct ContentView: View {
|
||||
_ = viewModel.completeNickname(suggestion, in: &messageText)
|
||||
}) {
|
||||
HStack {
|
||||
Text("@\(suggestion)")
|
||||
Text(suggestion)
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
.foregroundColor(textColor)
|
||||
.fontWeight(.medium)
|
||||
@@ -426,10 +426,13 @@ struct ContentView: View {
|
||||
let commandInfo: [(commands: [String], syntax: String?, description: String)] = [
|
||||
(["/block"], "[nickname]", "block or list blocked peers"),
|
||||
(["/clear"], nil, "clear chat messages"),
|
||||
(["/fav"], "<nickname>", "add to favorites"),
|
||||
(["/help"], nil, "show this help"),
|
||||
(["/hug"], "<nickname>", "send someone a warm hug"),
|
||||
(["/m", "/msg"], "<nickname> [message]", "send private message"),
|
||||
(["/slap"], "<nickname>", "slap someone with a trout"),
|
||||
(["/unblock"], "<nickname>", "unblock a peer"),
|
||||
(["/unfav"], "<nickname>", "remove from favorites"),
|
||||
(["/w"], nil, "see who's online")
|
||||
]
|
||||
|
||||
@@ -512,10 +515,13 @@ struct ContentView: View {
|
||||
let commandDescriptions = [
|
||||
("/block", "block or list blocked peers"),
|
||||
("/clear", "clear chat messages"),
|
||||
("/fav", "add to favorites"),
|
||||
("/help", "show this help"),
|
||||
("/hug", "send someone a warm hug"),
|
||||
("/m", "send private message"),
|
||||
("/slap", "slap someone with a trout"),
|
||||
("/unblock", "unblock a peer"),
|
||||
("/unfav", "remove from favorites"),
|
||||
("/w", "see who's online")
|
||||
]
|
||||
|
||||
@@ -645,7 +651,7 @@ struct ContentView: View {
|
||||
displayName: peer.id == currentMyPeerID ? viewModel.nickname : peer.nickname,
|
||||
isFavorite: peer.favoriteStatus?.isFavorite ?? false,
|
||||
isMe: peer.id == currentMyPeerID,
|
||||
hasUnreadMessages: viewModel.unreadPrivateMessages.contains(peer.id),
|
||||
hasUnreadMessages: viewModel.hasUnreadMessages(for: peer.id),
|
||||
encryptionStatus: viewModel.getEncryptionStatus(for: peer.id),
|
||||
connectionState: peer.connectionState,
|
||||
isMutualFavorite: peer.favoriteStatus?.isMutual ?? false
|
||||
@@ -884,7 +890,7 @@ struct ContentView: View {
|
||||
|
||||
// People counter with unread indicator
|
||||
HStack(spacing: 4) {
|
||||
if !viewModel.unreadPrivateMessages.isEmpty {
|
||||
if viewModel.hasAnyUnreadMessages {
|
||||
Image(systemName: "envelope.fill")
|
||||
.font(.system(size: 12))
|
||||
.foregroundColor(Color.orange)
|
||||
|
||||
Reference in New Issue
Block a user