mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 19:05:20 +00:00
PeerID 4/n: BitchatMessage.senderPeerID + String equality (#739)
This commit is contained in:
@@ -153,7 +153,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
|
||||
@MainActor
|
||||
private func normalizedSenderKey(for message: BitchatMessage) -> String {
|
||||
if let spid = message.senderPeerID {
|
||||
if let spid = message.senderPeerID?.id {
|
||||
if spid.hasPrefix("nostr:") || spid.hasPrefix("nostr_") {
|
||||
let bare: String = {
|
||||
if spid.hasPrefix("nostr:") { return String(spid.dropFirst(6)) }
|
||||
@@ -1967,7 +1967,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
if let gh = currentGeohash {
|
||||
if var arr = geoTimelines[gh] {
|
||||
arr.removeAll { msg in
|
||||
if let spid = msg.senderPeerID, spid.hasPrefix("nostr") {
|
||||
if let spid = msg.senderPeerID?.id, spid.hasPrefix("nostr") {
|
||||
if let full = nostrKeyMapping[spid]?.lowercased() { return full == hex }
|
||||
}
|
||||
return false
|
||||
@@ -1978,7 +1978,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
switch activeChannel {
|
||||
case .location:
|
||||
messages.removeAll { msg in
|
||||
if let spid = msg.senderPeerID, spid.hasPrefix("nostr") {
|
||||
if let spid = msg.senderPeerID?.id , spid.hasPrefix("nostr") {
|
||||
if let full = nostrKeyMapping[spid]?.lowercased() { return full == hex }
|
||||
}
|
||||
return false
|
||||
@@ -2676,7 +2676,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
|
||||
// Store the Nostr pubkey if provided (for messages from unknown senders)
|
||||
if let nostrPubkey = notification.userInfo?["nostrPubkey"] as? String,
|
||||
let senderPeerID = message.senderPeerID {
|
||||
let senderPeerID = message.senderPeerID?.id {
|
||||
// Store mapping for read receipts
|
||||
nostrKeyMapping[senderPeerID] = nostrPubkey
|
||||
}
|
||||
@@ -3296,7 +3296,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
func formatMessageAsText(_ message: BitchatMessage, colorScheme: ColorScheme) -> AttributedString {
|
||||
// Determine if this message was sent by self (mesh, geo, or DM)
|
||||
let isSelf: Bool = {
|
||||
if let spid = message.senderPeerID {
|
||||
if let spid = message.senderPeerID?.id {
|
||||
// In geohash channels, compare against our per-geohash nostr short ID
|
||||
if case .location(let ch) = activeChannel, spid.hasPrefix("nostr:") {
|
||||
if let myGeo = try? NostrIdentityBridge.deriveIdentity(forGeohash: ch.geohash) {
|
||||
@@ -3331,7 +3331,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
let fontWeight: Font.Weight = isSelf ? .bold : .medium
|
||||
senderStyle.font = .bitchatSystem(size: 14, weight: fontWeight, design: .monospaced)
|
||||
// Make sender clickable: encode senderPeerID into a custom URL
|
||||
if let spid = message.senderPeerID, let url = URL(string: "bitchat://user/\(spid.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? spid)") {
|
||||
if let spid = message.senderPeerID?.id, let url = URL(string: "bitchat://user/\(spid.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? spid)") {
|
||||
senderStyle.link = url
|
||||
}
|
||||
|
||||
@@ -3862,7 +3862,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
|
||||
@MainActor
|
||||
private func peerColor(for message: BitchatMessage, isDark: Bool) -> Color {
|
||||
if let spid = message.senderPeerID {
|
||||
if let spid = message.senderPeerID?.id {
|
||||
if spid.hasPrefix("nostr:") || spid.hasPrefix("nostr_") {
|
||||
let bare: String = {
|
||||
if spid.hasPrefix("nostr:") { return String(spid.dropFirst(6)) }
|
||||
@@ -5654,7 +5654,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
/// Check if a message should be blocked based on sender
|
||||
@MainActor
|
||||
private func isMessageBlocked(_ message: BitchatMessage) -> Bool {
|
||||
if let peerID = message.senderPeerID ?? getPeerIDForNickname(message.sender) {
|
||||
if let peerID = message.senderPeerID?.id ?? getPeerIDForNickname(message.sender) {
|
||||
// Check mesh/known peers first
|
||||
if isPeerBlocked(peerID) { return true }
|
||||
// Check geohash (Nostr) blocks using mapping to full pubkey
|
||||
@@ -5694,7 +5694,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
originalSender: message.originalSender,
|
||||
isPrivate: message.isPrivate,
|
||||
recipientNickname: message.recipientNickname,
|
||||
senderPeerID: message.senderPeerID,
|
||||
senderPeerID: message.senderPeerID?.id,
|
||||
mentions: message.mentions,
|
||||
deliveryStatus: message.deliveryStatus
|
||||
)
|
||||
@@ -5802,7 +5802,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
@MainActor
|
||||
private func handlePrivateMessage(_ message: BitchatMessage) {
|
||||
SecureLogger.debug("📥 handlePrivateMessage called for message from \(message.sender)", category: .session)
|
||||
let senderPeerID = message.senderPeerID ?? getPeerIDForNickname(message.sender)
|
||||
let senderPeerID = message.senderPeerID?.id ?? getPeerIDForNickname(message.sender)
|
||||
|
||||
guard let peerID = senderPeerID else {
|
||||
SecureLogger.warning("⚠️ Could not get peer ID for sender \(message.sender)", category: .session)
|
||||
@@ -5912,7 +5912,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
readerNickname: nickname
|
||||
)
|
||||
|
||||
let recipientID = message.senderPeerID ?? peerID
|
||||
let recipientID = message.senderPeerID?.id ?? peerID
|
||||
|
||||
Task { @MainActor in
|
||||
var originalTransport: String? = nil
|
||||
@@ -5944,7 +5944,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
if isMessageBlocked(finalMessage) { return }
|
||||
|
||||
// Classify origin: geochat if senderPeerID starts with 'nostr:', else mesh (or system)
|
||||
let isGeo = finalMessage.senderPeerID?.hasPrefix("nostr:") == true
|
||||
let isGeo = finalMessage.senderPeerID?.isGeoChat == true
|
||||
|
||||
// Apply per-sender and per-content rate limits (drop if exceeded)
|
||||
if finalMessage.sender != "system" {
|
||||
|
||||
Reference in New Issue
Block a user