···3737 if (!str) return 0
3838 return str.match(/\n/g)?.length ?? 0
3939}
4040+4141+// Augments search query with additional syntax like `from:me`
4242+export function augmentSearchQuery(query: string, {did}: {did?: string}) {
4343+ // Don't do anything if there's no DID
4444+ if (!did) {
4545+ return query
4646+ }
4747+4848+ // We don't want to replace substrings that are being "quoted" because those
4949+ // are exact string matches, so what we'll do here is to split them apart
5050+5151+ // Even-indexed strings are unquoted, odd-indexed strings are quoted
5252+ const splits = query.split(/("(?:[^"\\]|\\.)*")/g)
5353+5454+ return splits
5555+ .map((str, idx) => {
5656+ if (idx % 2 === 0) {
5757+ return str.replaceAll(/(^|\s)from:me(\s|$)/g, `$1${did}$2`)
5858+ }
5959+6060+ return str
6161+ })
6262+ .join('')
6363+}