Ask plugin to perform search.
(user types.Uid, query string)
| 425 | |
| 426 | // Ask plugin to perform search. |
| 427 | func pluginFind(user types.Uid, query string) (string, []types.Subscription, error) { |
| 428 | if globals.plugins == nil { |
| 429 | return query, nil, nil |
| 430 | } |
| 431 | |
| 432 | find := &pbx.SearchQuery{ |
| 433 | UserId: user.UserId(), |
| 434 | Query: query, |
| 435 | } |
| 436 | for i := range globals.plugins { |
| 437 | p := &globals.plugins[i] |
| 438 | if !p.filterFind { |
| 439 | // Plugin cannot service Find requests |
| 440 | continue |
| 441 | } |
| 442 | |
| 443 | var ctx context.Context |
| 444 | var cancel context.CancelFunc |
| 445 | if p.timeout > 0 { |
| 446 | ctx, cancel = context.WithTimeout(context.Background(), p.timeout) |
| 447 | defer cancel() |
| 448 | } else { |
| 449 | ctx = context.Background() |
| 450 | } |
| 451 | resp, err := p.client.Find(ctx, find) |
| 452 | if err != nil { |
| 453 | logs.Warn.Println("plugins: Find call failed", p.name, err) |
| 454 | return "", nil, err |
| 455 | } |
| 456 | respStatus := resp.GetStatus() |
| 457 | // CONTINUE means default processing |
| 458 | if respStatus == pbx.RespCode_CONTINUE { |
| 459 | continue |
| 460 | } |
| 461 | // DROP means stop processing the request |
| 462 | if respStatus == pbx.RespCode_DROP { |
| 463 | return "", nil, nil |
| 464 | } |
| 465 | // REPLACE: query string was changed. Use the new one for further processing. |
| 466 | if respStatus == pbx.RespCode_REPLACE { |
| 467 | return resp.GetQuery(), nil, nil |
| 468 | } |
| 469 | // RESPOND: Plugin provided a specific response. Use it |
| 470 | return "", pbSubSliceDeserialize(resp.GetResult()), nil |
| 471 | } |
| 472 | |
| 473 | return query, nil, nil |
| 474 | } |
| 475 | |
| 476 | func pluginAccount(user *types.User, action int) { |
| 477 | if globals.plugins == nil { |