mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-10-18 07:33:46 +00:00
Route mention autocomplete through shared SafeRegex pattern.
Add MessageFormattingEngine.Patterns.mentionAutocomplete and use it from AutocompleteService so mention matching compiles through the same fail-closed helper as message formatting.
This commit is contained in:
parent
2be79766cf
commit
b8f495d362
@ -10,9 +10,7 @@ import Foundation
|
||||
|
||||
/// Manages autocomplete functionality for chat
|
||||
final class AutocompleteService {
|
||||
/// Compiled via `SafeRegex` so a bad pattern logs and disables matching
|
||||
/// instead of silently returning nil forever (`try?` did the latter).
|
||||
private let mentionRegex = SafeRegex.compile("@([\\p{L}0-9_]*)$")
|
||||
private typealias Patterns = MessageFormattingEngine.Patterns
|
||||
|
||||
/// Get autocomplete suggestions for current text
|
||||
func getSuggestions(for text: String, peers: [String], cursorPosition: Int) -> (suggestions: [String], range: NSRange?) {
|
||||
@ -45,7 +43,7 @@ final class AutocompleteService {
|
||||
|
||||
private func getMentionSuggestions(_ text: String, peers: [String]) -> ([String], NSRange)? {
|
||||
let nsText = text as NSString
|
||||
let matches = mentionRegex.matches(
|
||||
let matches = Patterns.mentionAutocomplete.matches(
|
||||
in: text,
|
||||
options: [],
|
||||
range: NSRange(location: 0, length: nsText.length)
|
||||
|
||||
@ -43,6 +43,9 @@ final class MessageFormattingEngine {
|
||||
|
||||
static let mention = SafeRegex.compile("@([\\p{L}0-9_]+(?:#[a-fA-F0-9]{4})?)")
|
||||
|
||||
/// Trailing partial `@nickname` at the composer cursor — autocomplete only.
|
||||
static let mentionAutocomplete = SafeRegex.compile("@([\\p{L}0-9_]*)$")
|
||||
|
||||
static let cashu = SafeRegex.compile("\\bcashu[AB][A-Za-z0-9._-]{40,}\\b")
|
||||
|
||||
static let bolt11 = SafeRegex.compile("(?i)\\bln(bc|tb|bcrt)[0-9][a-z0-9]{50,}\\b")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user