From a83dee34baf466b4ef9dca9fa057cc78f1d18666 Mon Sep 17 00:00:00 2001 From: jack Date: Fri, 4 Jul 2025 20:02:54 +0200 Subject: [PATCH] Update logging to only write to disk on macOS - Add conditional compilation to LoggingService - macOS continues to write logs to Documents/Logs - iOS uses /dev/null to prevent disk writes - Remove room auto-join on mention (only join when sending to room) --- bitchat.xcodeproj/project.pbxproj | 7 ++++--- bitchat/Services/LoggingService.swift | 6 ++++++ bitchat/ViewModels/ChatViewModel.swift | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index e9074598..5c2393b3 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 63; objects = { /* Begin PBXBuildFile section */ @@ -39,7 +39,7 @@ 763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = ""; }; 7EEBDA723E1CFD88758DA4AC /* bitchat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96CDF6D0AF0F2052A6C7E634 /* LoggingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingService.swift; sourceTree = ""; }; - 997D512074C64904D75DDD40 /* bitchat.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 997D512074C64904D75DDD40 /* bitchat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = ""; }; D5C3D880FF8AE1673B20E1E3 /* BluetoothMeshService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothMeshService.swift; sourceTree = ""; }; @@ -183,7 +183,6 @@ ); mainGroup = 18198ED912AAF495D8AF7763; minimizedProjectReferenceProxies = 1; - preferredProjectObjectVersion = 54; projectDirPath = ""; projectRoot = ""; targets = ( @@ -259,6 +258,7 @@ CODE_SIGNING_REQUIRED = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = L3N5LHJD5Y; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = bitchat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 16.0; @@ -285,6 +285,7 @@ CODE_SIGNING_REQUIRED = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = L3N5LHJD5Y; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = bitchat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 16.0; diff --git a/bitchat/Services/LoggingService.swift b/bitchat/Services/LoggingService.swift index 84740149..a46b98f7 100644 --- a/bitchat/Services/LoggingService.swift +++ b/bitchat/Services/LoggingService.swift @@ -22,6 +22,8 @@ class LoggingService { dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" + #if os(macOS) + // Only create log files on macOS // Get documents directory let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! @@ -45,6 +47,10 @@ class LoggingService { log("=== BitChat Started ===") log("Log file: \(fileURL.path)") + #else + // On iOS, just create a dummy URL since we won't write to disk + fileURL = URL(fileURLWithPath: "/dev/null") + #endif } func log(_ message: String, category: String = "general") { diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 9a52bc79..09858cb2 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -261,10 +261,10 @@ class ChatViewModel: ObservableObject { messages.append(message) } - // Auto-join any new rooms mentioned in the message - for room in rooms { - if !joinedRooms.contains(room) { - joinRoom(room) + // Only auto-join rooms if we're sending TO that room + if let messageRoom = messageRoom { + if !joinedRooms.contains(messageRoom) { + joinRoom(messageRoom) } } @@ -631,6 +631,8 @@ class ChatViewModel: ObservableObject { extension ChatViewModel: BitchatDelegate { func didReceiveMessage(_ message: BitchatMessage) { + bitchatLog("Received message from \(message.sender), room: \(message.room ?? "nil"), senderPeerID: \(message.senderPeerID ?? "nil")", category: "message") + if message.isPrivate { // Handle private message @@ -675,7 +677,7 @@ extension ChatViewModel: BitchatDelegate { roomMessages[room]?.append(message) roomMessages[room]?.sort { $0.timestamp < $1.timestamp } - // Track room members + // Track room members - only track the sender as a member if roomMembers[room] == nil { roomMembers[room] = [] }