mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 02:25:20 +00:00
Trim trailing/leading spaces in geohash nicknames and tag emission
Sanitize Nostr 'n' tag values on ingest and emit by trimming whitespace/newlines to prevent trailing spaces in displayed usernames. Local nickname is already trimmed on focus loss and submit.
This commit is contained in:
@@ -107,7 +107,7 @@ struct NostrProtocol {
|
|||||||
teleported: Bool = false
|
teleported: Bool = false
|
||||||
) throws -> NostrEvent {
|
) throws -> NostrEvent {
|
||||||
var tags = [["g", geohash]]
|
var tags = [["g", geohash]]
|
||||||
if let nickname = nickname, !nickname.isEmpty {
|
if let nickname = nickname?.trimmingCharacters(in: .whitespacesAndNewlines), !nickname.isEmpty {
|
||||||
tags.append(["n", nickname])
|
tags.append(["n", nickname])
|
||||||
}
|
}
|
||||||
if teleported {
|
if teleported {
|
||||||
|
|||||||
@@ -897,7 +897,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
if Date().timeIntervalSince(eventTime) < 15 { return }
|
if Date().timeIntervalSince(eventTime) < 15 { return }
|
||||||
}
|
}
|
||||||
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
||||||
let nick = nickTag[1]
|
let nick = nickTag[1].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
self.geoNicknames[event.pubkey.lowercased()] = nick
|
self.geoNicknames[event.pubkey.lowercased()] = nick
|
||||||
}
|
}
|
||||||
// Store mapping for geohash sender IDs used in messages (ensures consistent colors)
|
// Store mapping for geohash sender IDs used in messages (ensures consistent colors)
|
||||||
@@ -1616,7 +1616,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
|||||||
}
|
}
|
||||||
// Cache nickname from tag if present
|
// Cache nickname from tag if present
|
||||||
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 {
|
||||||
let nick = nickTag[1]
|
let nick = nickTag[1].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
self.geoNicknames[event.pubkey.lowercased()] = nick
|
self.geoNicknames[event.pubkey.lowercased()] = nick
|
||||||
}
|
}
|
||||||
// If this pubkey is blocked, skip mapping, participants, and timeline
|
// If this pubkey is blocked, skip mapping, participants, and timeline
|
||||||
|
|||||||
Reference in New Issue
Block a user