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

Function pluginMessage

server/plugins.go:598–630  ·  view source on GitHub ↗

Message accepted for delivery

(data *MsgServerData, action int)

Source from the content-addressed store, hash-verified

596
597// Message accepted for delivery
598func pluginMessage(data *MsgServerData, action int) {
599 if globals.plugins == nil || action != plgActCreate {
600 return
601 }
602
603 var event *pbx.MessageEvent
604 for i := range globals.plugins {
605 p := &globals.plugins[i]
606 if p.filterMessage == nil || p.filterMessage.byAction&action == 0 {
607 // Plugin is not interested in Message actions
608 continue
609 }
610
611 if event == nil {
612 event = &pbx.MessageEvent{
613 Action: pluginActionToCrud(action),
614 Msg: pbServDataSerialize(data).Data,
615 }
616 }
617
618 var ctx context.Context
619 var cancel context.CancelFunc
620 if p.timeout > 0 {
621 ctx, cancel = context.WithTimeout(context.Background(), p.timeout)
622 defer cancel()
623 } else {
624 ctx = context.Background()
625 }
626 if _, err := p.client.Message(ctx, event); err != nil {
627 logs.Warn.Println("plugins: Message call failed", p.name, err)
628 }
629 }
630}
631
632// Returns false to skip, true to process
633func pluginDoFiltering(filter *PluginFilter, msg *ClientComMessage) bool {

Callers 1

Calls 4

pluginActionToCrudFunction · 0.85
pbServDataSerializeFunction · 0.85
PrintlnMethod · 0.80
MessageMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…