Fix notification dot size and improve peer announcements

- Make notification dot smaller (5x5) for better appearance
- Remove all delays from announcement sending
- Send announcements immediately on connection
- Add debug logging for join/leave messages
- Ensure join/leave messages are properly displayed
This commit is contained in:
jack
2025-07-02 21:32:51 +02:00
parent d67e11cdab
commit e50f14eeed
3 changed files with 17 additions and 21 deletions
+7 -8
View File
@@ -117,10 +117,9 @@ class BluetoothMeshService: NSObject {
startAdvertising()
}
// Schedule initial announcement after services are ready
announcementTimer?.invalidate()
announcementTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] _ in
self?.sendInitialAnnouncement()
// Send initial announcement immediately if we have peers
if !connectedPeripherals.isEmpty || !subscribedCentrals.isEmpty {
sendInitialAnnouncement()
}
}
@@ -623,7 +622,7 @@ extension BluetoothMeshService: CBPeripheralDelegate {
peripheral.setNotifyValue(true, for: characteristic)
peripheralCharacteristics[peripheral] = characteristic
// Send key exchange immediately
// Send key exchange and announce immediately
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
@@ -644,7 +643,7 @@ extension BluetoothMeshService: CBPeripheralDelegate {
// Send announce packet immediately after key exchange
if let vm = self.delegate as? ChatViewModel {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let announcePacket = BitchatPacket(
type: MessageType.announce.rawValue,
@@ -751,7 +750,7 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
// Send announce immediately after key exchange
if let vm = self.delegate as? ChatViewModel {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
print("[DEBUG] Sending announce packet to central after key exchange")
let announcePacket = BitchatPacket(
@@ -805,7 +804,7 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
// Send announce immediately after key exchange
if let vm = delegate as? ChatViewModel {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let announcePacket = BitchatPacket(
type: MessageType.announce.rawValue,
+4
View File
@@ -241,6 +241,7 @@ extension ChatViewModel: BitchatDelegate {
}
func didConnectToPeer(_ peerID: String) {
print("[DEBUG] didConnectToPeer called with: \(peerID)")
isConnected = true
let systemMessage = BitchatMessage(
sender: "system",
@@ -250,9 +251,11 @@ extension ChatViewModel: BitchatDelegate {
originalSender: nil
)
messages.append(systemMessage)
print("[DEBUG] Added join message, total messages: \(messages.count)")
}
func didDisconnectFromPeer(_ peerID: String) {
print("[DEBUG] didDisconnectFromPeer called with: \(peerID)")
let systemMessage = BitchatMessage(
sender: "system",
content: "\(peerID) has left the channel",
@@ -261,6 +264,7 @@ extension ChatViewModel: BitchatDelegate {
originalSender: nil
)
messages.append(systemMessage)
print("[DEBUG] Added leave message, total messages: \(messages.count)")
}
func didUpdatePeerList(_ peers: [String]) {
+6 -13
View File
@@ -175,27 +175,20 @@ struct ContentView: View {
}
} label: {
HStack(spacing: 4) {
// Notification indicator for unread messages (on the left)
if !viewModel.unreadPrivateMessages.isEmpty {
Circle()
.fill(Color.orange)
.frame(width: 8, height: 8)
}
// Text
Text(viewModel.isConnected ? "\(viewModel.connectedPeers.count) \(viewModel.connectedPeers.count == 1 ? "person" : "people")" : "scanning")
.font(.system(size: 14, design: .monospaced))
.foregroundColor(viewModel.isConnected ? textColor : Color.red)
// Chevron (on the right)
Image(systemName: "chevron.down")
.font(.system(size: 10))
.foregroundColor(secondaryTextColor)
// Notification indicator (on the right after default chevron)
if !viewModel.unreadPrivateMessages.isEmpty {
Circle()
.fill(Color.orange)
.frame(width: 5, height: 5)
}
}
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.fixedSize()
}
private var messagesView: some View {