mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 23:45:18 +00:00
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
This commit is contained in:
@@ -37,7 +37,6 @@ struct NostrProtocol {
|
|||||||
|
|
||||||
// 2. Create ephemeral key for this message
|
// 2. Create ephemeral key for this message
|
||||||
let ephemeralKey = try P256K.Schnorr.PrivateKey()
|
let ephemeralKey = try P256K.Schnorr.PrivateKey()
|
||||||
let _ = Data(ephemeralKey.xonly.bytes).hexEncodedString()
|
|
||||||
// Created ephemeral key for seal
|
// Created ephemeral key for seal
|
||||||
|
|
||||||
// 3. Seal the rumor (encrypt to recipient)
|
// 3. Seal the rumor (encrypt to recipient)
|
||||||
@@ -213,7 +212,6 @@ struct NostrProtocol {
|
|||||||
throw NostrError.invalidPublicKey
|
throw NostrError.invalidPublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = Data(senderKey.xonly.bytes).hexEncodedString()
|
|
||||||
// Encrypting message
|
// Encrypting message
|
||||||
|
|
||||||
// Derive shared secret
|
// Derive shared secret
|
||||||
@@ -447,14 +445,11 @@ struct NostrProtocol {
|
|||||||
|
|
||||||
// Log with explicit UTC and local time for debugging
|
// Log with explicit UTC and local time for debugging
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
|
// Removed unnecessary date formatting operations
|
||||||
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||||
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
||||||
let _ = formatter.string(from: now)
|
|
||||||
let _ = formatter.string(from: randomized)
|
|
||||||
|
|
||||||
formatter.timeZone = TimeZone.current
|
formatter.timeZone = TimeZone.current
|
||||||
let _ = formatter.string(from: now)
|
|
||||||
let _ = formatter.string(from: randomized)
|
|
||||||
|
|
||||||
// Timestamp randomized for privacy
|
// Timestamp randomized for privacy
|
||||||
|
|
||||||
|
|||||||
@@ -273,8 +273,7 @@ class NostrRelayManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "EOSE":
|
case "EOSE":
|
||||||
if array.count >= 2,
|
if array.count >= 2 {
|
||||||
let _ = array[1] as? String {
|
|
||||||
// End of stored events
|
// End of stored events
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,8 +289,8 @@ class NostrRelayManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
if array.count >= 2,
|
if array.count >= 2 {
|
||||||
let _ = array[1] as? String {
|
// Server notice received
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -705,7 +705,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Update PeerSession
|
// Update PeerSession
|
||||||
if let session = peerSessions[peerID] {
|
if let session = peerSessions[peerID] {
|
||||||
let _ = session.isConnected
|
|
||||||
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
session.updateBluetoothConnection(peripheral: mapping.peripheral, characteristic: nil)
|
||||||
} else {
|
} else {
|
||||||
// This is a truly new peer session
|
// This is a truly new peer session
|
||||||
@@ -2804,7 +2803,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Check if we have a recent entry
|
// Check if we have a recent entry
|
||||||
if let entry = protocolMessageDedup[key], !isExpired(entry) {
|
if let entry = protocolMessageDedup[key], !isExpired(entry) {
|
||||||
let _ = Date().timeIntervalSince(entry.sentAt)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3466,7 +3464,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Bloom filter will be reset by timer, processedMessages is now bounded
|
// Bloom filter will be reset by timer, processedMessages is now bounded
|
||||||
|
|
||||||
// let _ = packet.senderID.hexEncodedString()
|
|
||||||
|
|
||||||
|
|
||||||
// Note: We'll decode messages in the switch statement below, not here
|
// Note: We'll decode messages in the switch statement below, not here
|
||||||
@@ -4548,7 +4545,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
if !isPeerIDOurs(senderID) {
|
if !isPeerIDOurs(senderID) {
|
||||||
// Check our current handshake state
|
// Check our current handshake state
|
||||||
let _ = handshakeCoordinator.getHandshakeState(for: senderID)
|
|
||||||
// Processing handshake response
|
// Processing handshake response
|
||||||
|
|
||||||
// Process the response - this could be message 2 or message 3 in the XX pattern
|
// Process the response - this could be message 2 or message 3 in the XX pattern
|
||||||
@@ -4734,7 +4730,6 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = Double(fragments.count - 1) * delayBetweenFragments
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleFragment(_ packet: BitchatPacket, from peerID: String) {
|
private func handleFragment(_ packet: BitchatPacket, from peerID: String) {
|
||||||
@@ -5093,8 +5088,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
category: SecureLogger.session, level: .info)
|
category: SecureLogger.session, level: .info)
|
||||||
|
|
||||||
// Log current peripheral mappings
|
// Log current peripheral mappings
|
||||||
let _ = collectionsQueue.sync { peripheralMappings.count }
|
|
||||||
let _ = connectionPool.count
|
|
||||||
|
|
||||||
peripheral.delegate = self
|
peripheral.delegate = self
|
||||||
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
peripheral.discoverServices([BluetoothMeshService.serviceUUID])
|
||||||
@@ -5283,7 +5276,6 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
// Time tracking removed - now in PeerSession
|
// Time tracking removed - now in PeerSession
|
||||||
// Keep lastSuccessfulMessageTime to validate session on reconnect
|
// Keep lastSuccessfulMessageTime to validate session on reconnect
|
||||||
let lastSuccess = self.peerSessions[peerID]?.lastSuccessfulMessageTime ?? Date.distantPast
|
let lastSuccess = self.peerSessions[peerID]?.lastSuccessfulMessageTime ?? Date.distantPast
|
||||||
let _ = Date().timeIntervalSince(lastSuccess)
|
|
||||||
// Keeping Noise session on disconnect
|
// Keeping Noise session on disconnect
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5500,7 +5492,6 @@ extension BluetoothMeshService: CBPeripheralDelegate {
|
|||||||
|
|
||||||
|
|
||||||
// Use the sender ID from the packet, not our local mapping which might still be a temp ID
|
// Use the sender ID from the packet, not our local mapping which might still be a temp ID
|
||||||
let _ = connectedPeripherals.first(where: { $0.value == peripheral })?.key ?? "unknown"
|
|
||||||
let packetSenderID = packet.senderID.hexEncodedString()
|
let packetSenderID = packet.senderID.hexEncodedString()
|
||||||
|
|
||||||
// Log the packet type we received
|
// Log the packet type we received
|
||||||
@@ -6611,8 +6602,6 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
SecureLogger.logHandshake("processing \(isInitiation ? "init" : "response")", peerID: peerID, success: true)
|
SecureLogger.logHandshake("processing \(isInitiation ? "init" : "response")", peerID: peerID, success: true)
|
||||||
|
|
||||||
// Get current handshake state before processing
|
// Get current handshake state before processing
|
||||||
let _ = handshakeCoordinator.getHandshakeState(for: peerID)
|
|
||||||
let _ = noiseService.hasEstablishedSession(with: peerID)
|
|
||||||
// Current handshake state check
|
// Current handshake state check
|
||||||
|
|
||||||
// Check for duplicate handshake messages
|
// Check for duplicate handshake messages
|
||||||
@@ -7535,7 +7524,6 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
|||||||
self.pendingPrivateMessages[recipientPeerID] = []
|
self.pendingPrivateMessages[recipientPeerID] = []
|
||||||
}
|
}
|
||||||
self.pendingPrivateMessages[recipientPeerID]?.append((content, recipientNickname, messageID ?? UUID().uuidString))
|
self.pendingPrivateMessages[recipientPeerID]?.append((content, recipientNickname, messageID ?? UUID().uuidString))
|
||||||
let _ = self.pendingPrivateMessages[recipientPeerID]?.count ?? 0
|
|
||||||
// Queued private message
|
// Queued private message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -737,13 +737,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
// Check if the recipient is blocked
|
// Check if the recipient is blocked
|
||||||
if isPeerBlocked(peerID) {
|
if isPeerBlocked(peerID) {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot send message to \(recipientNickname): user is blocked.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot send message to \(recipientNickname): user is blocked.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,13 +797,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
category: SecureLogger.session, level: .warning)
|
category: SecureLogger.session, level: .warning)
|
||||||
|
|
||||||
// Add system message to inform user
|
// Add system message to inform user
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("Cannot send message to \(recipientNickname) - peer is not reachable via mesh or Nostr.")
|
||||||
sender: "system",
|
|
||||||
content: "Cannot send message to \(recipientNickname) - peer is not reachable via mesh or Nostr.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
addMessage(systemMessage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,13 +852,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
// Check if the peer is blocked
|
// Check if the peer is blocked
|
||||||
if isPeerBlocked(peerID) {
|
if isPeerBlocked(peerID) {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot start chat with \(peerNickname): user is blocked.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot start chat with \(peerNickname): user is blocked.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -878,13 +860,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Only require mutual favorites for offline Nostr messaging
|
// Only require mutual favorites for offline Nostr messaging
|
||||||
if let peer = peerIndex[peerID],
|
if let peer = peerIndex[peerID],
|
||||||
peer.isFavorite && !peer.theyFavoritedUs && !peer.isConnected && !peer.isRelayConnected {
|
peer.isFavorite && !peer.theyFavoritedUs && !peer.isConnected && !peer.isRelayConnected {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot start chat with \(peerNickname): mutual favorite required for offline messaging.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot start chat with \(peerNickname): mutual favorite required for offline messaging.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1038,7 +1014,6 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
guard let messageId = notification.userInfo?["messageId"] as? String,
|
guard let messageId = notification.userInfo?["messageId"] as? String,
|
||||||
let senderNoiseKey = notification.userInfo?["senderNoiseKey"] as? Data else { return }
|
let senderNoiseKey = notification.userInfo?["senderNoiseKey"] as? Data else { return }
|
||||||
|
|
||||||
let _ = senderNoiseKey.hexEncodedString()
|
|
||||||
|
|
||||||
|
|
||||||
// Update the delivery status for the message
|
// Update the delivery status for the message
|
||||||
@@ -2323,54 +2298,24 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
let messageContent = parts[2...].joined(separator: " ")
|
let messageContent = parts[2...].joined(separator: " ")
|
||||||
sendPrivateMessage(messageContent, to: peerID)
|
sendPrivateMessage(messageContent, to: peerID)
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("started private chat with \(nickname)")
|
||||||
sender: "system",
|
|
||||||
content: "started private chat with \(nickname)",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("user '\(nickname)' not found. they may be offline or using a different nickname.")
|
||||||
sender: "system",
|
|
||||||
content: "user '\(nickname)' not found. they may be offline or using a different nickname.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("usage: /m @nickname [message] or /m nickname [message]")
|
||||||
sender: "system",
|
|
||||||
content: "usage: /m @nickname [message] or /m nickname [message]",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
case "/w":
|
case "/w":
|
||||||
let peerNicknames = meshService.getPeerNicknames()
|
let peerNicknames = meshService.getPeerNicknames()
|
||||||
if connectedPeers.isEmpty {
|
if connectedPeers.isEmpty {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("no one else is online right now.")
|
||||||
sender: "system",
|
|
||||||
content: "no one else is online right now.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
} else {
|
} else {
|
||||||
let onlineList = connectedPeers.compactMap { peerID in
|
let onlineList = connectedPeers.compactMap { peerID in
|
||||||
peerNicknames[peerID]
|
peerNicknames[peerID]
|
||||||
}.sorted().joined(separator: ", ")
|
}.sorted().joined(separator: ", ")
|
||||||
|
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("online users: \(onlineList)")
|
||||||
sender: "system",
|
|
||||||
content: "online users: \(onlineList)",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
case "/clear":
|
case "/clear":
|
||||||
// Clear messages based on current context
|
// Clear messages based on current context
|
||||||
@@ -2493,13 +2438,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
if let fingerprintStr = meshService.getPeerFingerprint(peerID) {
|
if let fingerprintStr = meshService.getPeerFingerprint(peerID) {
|
||||||
|
|
||||||
if SecureIdentityStateManager.shared.isBlocked(fingerprint: fingerprintStr) {
|
if SecureIdentityStateManager.shared.isBlocked(fingerprint: fingerprintStr) {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("\(nickname) is already blocked.")
|
||||||
sender: "system",
|
|
||||||
content: "\(nickname) is already blocked.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
} else {
|
} else {
|
||||||
// Update or create social identity with blocked status
|
// Update or create social identity with blocked status
|
||||||
if var identity = SecureIdentityStateManager.shared.getSocialIdentity(for: fingerprintStr) {
|
if var identity = SecureIdentityStateManager.shared.getSocialIdentity(for: fingerprintStr) {
|
||||||
@@ -2523,42 +2462,18 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
blockedUsers.insert(fingerprintStr)
|
blockedUsers.insert(fingerprintStr)
|
||||||
favoritePeers.remove(fingerprintStr)
|
favoritePeers.remove(fingerprintStr)
|
||||||
|
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("blocked \(nickname). you will no longer receive messages from them.")
|
||||||
sender: "system",
|
|
||||||
content: "blocked \(nickname). you will no longer receive messages from them.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot block \(nickname): unable to verify identity.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot block \(nickname): unable to verify identity.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot block \(nickname): user not found.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot block \(nickname): user not found.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// List blocked users
|
// List blocked users
|
||||||
if blockedUsers.isEmpty {
|
if blockedUsers.isEmpty {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("no blocked peers.")
|
||||||
sender: "system",
|
|
||||||
content: "no blocked peers.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
} else {
|
} else {
|
||||||
// Find nicknames for blocked users
|
// Find nicknames for blocked users
|
||||||
var blockedNicknames: [String] = []
|
var blockedNicknames: [String] = []
|
||||||
@@ -2573,13 +2488,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let blockedList = blockedNicknames.isEmpty ? "blocked peers (not currently online)" : blockedNicknames.sorted().joined(separator: ", ")
|
let blockedList = blockedNicknames.isEmpty ? "blocked peers (not currently online)" : blockedNicknames.sorted().joined(separator: ", ")
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("blocked peers: \(blockedList)")
|
||||||
sender: "system",
|
|
||||||
content: "blocked peers: \(blockedList)",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2601,48 +2510,18 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
// Update local set for UI
|
// Update local set for UI
|
||||||
blockedUsers.remove(fingerprintStr)
|
blockedUsers.remove(fingerprintStr)
|
||||||
|
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("unblocked \(nickname).")
|
||||||
sender: "system",
|
|
||||||
content: "unblocked \(nickname).",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("\(nickname) is not blocked.")
|
||||||
sender: "system",
|
|
||||||
content: "\(nickname) is not blocked.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot unblock \(nickname): unable to verify identity.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot unblock \(nickname): unable to verify identity.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("cannot unblock \(nickname): user not found.")
|
||||||
sender: "system",
|
|
||||||
content: "cannot unblock \(nickname): user not found.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("usage: /unblock <nickname>")
|
||||||
sender: "system",
|
|
||||||
content: "usage: /unblock <nickname>",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "/fav":
|
case "/fav":
|
||||||
@@ -2671,31 +2550,13 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
try? await self?.messageRouter?.sendFavoriteNotification(to: noisePublicKey, isFavorite: true)
|
try? await self?.messageRouter?.sendFavoriteNotification(to: noisePublicKey, isFavorite: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("added \(nickname) to favorites.")
|
||||||
sender: "system",
|
|
||||||
content: "added \(nickname) to favorites.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("can't find peer: \(nickname)")
|
||||||
sender: "system",
|
|
||||||
content: "can't find peer: \(nickname)",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("usage: /fav <nickname>")
|
||||||
sender: "system",
|
|
||||||
content: "usage: /fav <nickname>",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "/unfav":
|
case "/unfav":
|
||||||
@@ -2718,41 +2579,17 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
try? await self?.messageRouter?.sendFavoriteNotification(to: noisePublicKey, isFavorite: false)
|
try? await self?.messageRouter?.sendFavoriteNotification(to: noisePublicKey, isFavorite: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("removed \(nickname) from favorites.")
|
||||||
sender: "system",
|
|
||||||
content: "removed \(nickname) from favorites.",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("can't find peer: \(nickname)")
|
||||||
sender: "system",
|
|
||||||
content: "can't find peer: \(nickname)",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("usage: /unfav <nickname>")
|
||||||
sender: "system",
|
|
||||||
content: "usage: /unfav <nickname>",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "/testnostr":
|
case "/testnostr":
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("testing nostr relay connectivity...")
|
||||||
sender: "system",
|
|
||||||
content: "testing nostr relay connectivity...",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
|
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
if let relayManager = self.nostrRelayManager {
|
if let relayManager = self.nostrRelayManager {
|
||||||
@@ -2788,13 +2625,7 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// Unknown command
|
// Unknown command
|
||||||
let systemMessage = BitchatMessage(
|
addSystemMessage("unknown command: \(cmd).")
|
||||||
sender: "system",
|
|
||||||
content: "unknown command: \(cmd).",
|
|
||||||
timestamp: Date(),
|
|
||||||
isRelay: false
|
|
||||||
)
|
|
||||||
messages.append(systemMessage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3367,4 +3198,15 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Helper for System Messages
|
||||||
|
private func addSystemMessage(_ content: String, timestamp: Date = Date()) {
|
||||||
|
let systemMessage = BitchatMessage(
|
||||||
|
sender: "system",
|
||||||
|
content: content,
|
||||||
|
timestamp: timestamp,
|
||||||
|
isRelay: false
|
||||||
|
)
|
||||||
|
messages.append(systemMessage)
|
||||||
|
}
|
||||||
|
|
||||||
} // End of ChatViewModel class
|
} // End of ChatViewModel class
|
||||||
|
|||||||
@@ -271,7 +271,6 @@ struct ContentView: View {
|
|||||||
ForEach(windowedMessages, id: \.id) { message in
|
ForEach(windowedMessages, id: \.id) { message in
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
// Check if current user is mentioned
|
// Check if current user is mentioned
|
||||||
let _ = message.mentions?.contains(viewModel.nickname) ?? false
|
|
||||||
|
|
||||||
if message.sender == "system" {
|
if message.sender == "system" {
|
||||||
// System messages
|
// System messages
|
||||||
|
|||||||
@@ -138,44 +138,6 @@ class ShareViewController: SLComposeServiceViewController {
|
|||||||
|
|
||||||
// MARK: - Helper Methods
|
// 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) {
|
private func saveToSharedDefaults(content: String, type: String) {
|
||||||
// Use app groups to share data between extension and main app
|
// Use app groups to share data between extension and main app
|
||||||
guard let userDefaults = UserDefaults(suiteName: "group.chat.bitchat") else {
|
guard let userDefaults = UserDefaults(suiteName: "group.chat.bitchat") else {
|
||||||
|
|||||||
Reference in New Issue
Block a user