MCPcopy Index your code
hub / github.com/tinode/chat / pluginFind

Function pluginFind

server/plugins.go:427–474  ·  view source on GitHub ↗

Ask plugin to perform search.

(user types.Uid, query string)

Source from the content-addressed store, hash-verified

425
426// Ask plugin to perform search.
427func 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
476func pluginAccount(user *types.User, action int) {
477 if globals.plugins == nil {

Callers 2

replyGetSubMethod · 0.85
replyGetTagsMethod · 0.85

Calls 7

pbSubSliceDeserializeFunction · 0.85
UserIdMethod · 0.80
PrintlnMethod · 0.80
GetResultMethod · 0.80
FindMethod · 0.65
GetStatusMethod · 0.45
GetQueryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…