MCPcopy
hub / github.com/tinode/chat / rewriteTag

Function rewriteTag

server/utils.go:377–401  ·  view source on GitHub ↗

rewriteTag attempts to match the original token against the email and telephone number. The tag is expected to be in lowercase. On success, it returns a slice with the original tag and the tag with the corresponding prefix. It returns an empty slice if the tag is invalid. TODO: consider inferring co

(orig, countryCode string)

Source from the content-addressed store, hash-verified

375// empty slice if the tag is invalid.
376// TODO: consider inferring country code from user location.
377func rewriteTag(orig, countryCode string) []string {
378 // Check if the tag already has a prefix e.g. basic:alice.
379 if prefixedTagRegexp.MatchString(orig) {
380 return []string{orig}
381 }
382
383 // Check if token can be rewritten by any of the validators
384 param := map[string]any{"countryCode": countryCode}
385 for name, conf := range globals.validators {
386 if conf.addToTags {
387 val := store.Store.GetValidator(name)
388 if tag, _ := val.PreCheck(orig, param); tag != "" {
389 return []string{orig, tag}
390 }
391 }
392 }
393
394 if tagRegexp.MatchString(orig) {
395 return []string{orig}
396 }
397
398 // invalid generic tag
399
400 return nil
401}
402
403// rewriteTagSlice calls rewriteTag for each slice member and return a new slice with original and converted values.
404func rewriteTagSlice(tags []string, countryCode string) []string {

Callers 2

rewriteTagSliceFunction · 0.85
replyGetSubMethod · 0.85

Calls 2

GetValidatorMethod · 0.65
PreCheckMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…