(userID string, textjid string, token string, kill chan bool)
| 398 | GetS3Manager().EnsureClientFromDB(userID) |
| 399 | }(txtid) |
| 400 | } |
| 401 | } |
| 402 | err = rows.Err() |
| 403 | if err != nil { |
| 404 | log.Error().Err(err).Msg("DB Problem") |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | func parseJID(arg string) (types.JID, bool) { |
| 409 | if arg == "" { |
| 410 | return types.JID{}, false |
| 411 | } |
| 412 | if arg[0] == '+' { |
| 413 | arg = arg[1:] |
| 414 | } |
| 415 | if !strings.ContainsRune(arg, '@') { |
| 416 | return types.NewJID(arg, types.DefaultUserServer), true |
| 417 | } else { |
| 418 | recipient, err := types.ParseJID(arg) |
| 419 | if err != nil { |
| 420 | log.Error().Err(err).Msg("Invalid JID") |
| 421 | return recipient, false |
| 422 | } else if recipient.User == "" { |
| 423 | log.Error().Err(err).Msg("Invalid JID no server specified") |
| 424 | return recipient, false |
| 425 | } |
| 426 | return recipient, true |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | // jidUserKey returns the phone/account part shared by users.jid and |
| 431 | // whatsmeow_device.jid even when formats differ (380...:8@ vs 380...@). |
| 432 | func jidUserKey(jid string) string { |
| 433 | if jid == "" { |
| 434 | return "" |
| 435 | } |
| 436 | userPart := strings.SplitN(jid, "@", 2)[0] |
| 437 | return strings.SplitN(userPart, ":", 2)[0] |
| 438 | } |
| 439 | |
| 440 | // jidLookupCandidates builds JID variants to try with sqlstore.GetDevice before |
| 441 | // falling back to account-key matching across all stored devices. |
| 442 | func jidLookupCandidates(textjid string) []types.JID { |
| 443 | jid, ok := parseJID(textjid) |
| 444 | if !ok { |
| 445 | return nil |
| 446 | } |
| 447 | |
| 448 | seen := make(map[string]struct{}) |
| 449 | var candidates []types.JID |
| 450 | add := func(candidate types.JID) { |
| 451 | if candidate.IsEmpty() { |
| 452 | return |
| 453 | } |
| 454 | key := candidate.String() |
| 455 | if _, exists := seen[key]; exists { |
| 456 | return |
| 457 | } |
no test coverage detected