diff --git a/config/config.go b/config/config.go index 7e601a0..b0978ef 100644 --- a/config/config.go +++ b/config/config.go @@ -30,7 +30,7 @@ func (cfg *defcfg) Actions() []lib.ActionConfig { } func (cfg *defcfg) AddAction(pattern string, specs ...lib.ActionSpec) { - act := ActionConfig(pattern, specs) + act := actionConfig(pattern, specs) cfg.actions = append(cfg.actions, act) } @@ -142,7 +142,7 @@ func (act *action) Specs() []lib.ActionSpec { return act.specs } -func ActionConfig(pat string, specs []lib.ActionSpec) *action { +func actionConfig(pat string, specs []lib.ActionSpec) *action { return &action{ pattern: pattern(strings.Split(pat, "|")), specs: specs, @@ -159,6 +159,10 @@ func (p pattern) Slice() []string { return []string(p) } +func Pattern(p ...string) lib.Pattern { + return pattern(p) +} + // overridable settings type Settings map[string]string diff --git a/core/action/action.go b/core/action/action.go index 7ec6fb7..8b04d0c 100644 --- a/core/action/action.go +++ b/core/action/action.go @@ -22,6 +22,11 @@ func (spec *baseSpec) Receivers() []lib.Addressable { } func (spec *baseSpec) AddReceiver(rcv lib.Addressable) { + for _, r := range spec.receivers { + if r == rcv { + return + } + } spec.receivers = append(spec.receivers, rcv) } diff --git a/matrix/matrix.go b/matrix/matrix.go index e8edc8a..9752516 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -31,7 +31,7 @@ func createCell(ctx lib.Context) lib.Context { func connect(src, tgt lib.Context, msg lib.Message) { cfg := src.Config() - pattern := "matrix|data" + pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String() for _, act := range cfg.Actions() { if act.Pattern().String() == pattern { for _, spec := range act.Specs() { diff --git a/tests/etc/etc_mx.go b/tests/etc/etc_mx.go index 70dcfba..79e3a8f 100644 --- a/tests/etc/etc_mx.go +++ b/tests/etc/etc_mx.go @@ -23,7 +23,7 @@ func ConfigMx() lib.Config { app_c.AddAction("demo", action.Base(action.Forward, "test-receiver")) test_rcvr := config.Default("test-receiver") - test_rcvr.AddAction("demo", action.Base(AH_MxReceiver)) + test_rcvr.AddAction("data", action.Base(AH_MxReceiver)) cell_0 := matrix.DefaultConfig("cell-0") diff --git a/tests/matrix_test.go b/tests/matrix_test.go index 4658b48..2c88c4d 100644 --- a/tests/matrix_test.go +++ b/tests/matrix_test.go @@ -1,4 +1,4 @@ -package scopes +package scopes_test import ( "os" @@ -16,7 +16,7 @@ func TestMatrixApp(tb *tbase.T) { t := testing.SetUpApp(tb, etc.ConfigMx()) t.Run("app-matrix", MxTest) t.TearDownApp("matrix") - t.AssertEqual(t.LogCheck(logfile, true), 7) + t.AssertEqual(t.LogCheck(logfile, true), 13) } func MxTest(t *testing.T) { @@ -26,13 +26,15 @@ func MxTest(t *testing.T) { rcvr := ctx.Services()["test-receiver"] msg := message.New("matrix", "create").WithSender(rcvr) c0.Send(msg) + msg = message.New("matrix", "data") + c0.Send(msg) } // action handlers func MxReceiver(act lib.Action) bool { t := testing.GetT(act.Context()) - t.AssertEqual(act.Message().Action(), "demo") + t.AssertEqual(act.Message().Action(), "data") return true }