From 0f054c36e886dc8e2ac04f245f80f44791417965 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 24 Jul 2023 14:54:24 +0200 Subject: [PATCH] matrix: send 'connect' message upon cell creation --- matrix/matrix.go | 21 ++++++++++++--------- scopes.go | 6 ++++++ tests/matrix_test.go | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/matrix/matrix.go b/matrix/matrix.go index e344ec6..b1e0919 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -5,6 +5,7 @@ import ( "git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/core" "git.sr.ht/~cco/go-scopes/core/action" + "git.sr.ht/~cco/go-scopes/core/message" ) func Start(ctx lib.Context) { @@ -13,16 +14,18 @@ func Start(ctx lib.Context) { core.Start(ctx) } -type celLConfig struct { - *config.BaseCfg -} - func create(act lib.Action) bool { - ctx := act.Context() - //msg := act.Message() + msg := act.Message() //spec := act.ActionSpec() - cctx := ctx.ChildContext(config.Base("", core.Start)) - core.Start(cctx) - // msg.Sender().Cell().Send(message.New("matrix", "connect").WithSender(cctx)) + cctx := createCell(act.Context()) + nmsg := message.New("matrix", "connect").WithSender(cctx) + msg.Sender().Cell().Send(nmsg) return true } + +func createCell(ctx lib.Context) lib.Context { + cfg := config.Base("", core.Start) + cctx := ctx.ChildContext(cfg) + cfg.Starter()(cctx) + return cctx +} diff --git a/scopes.go b/scopes.go index 94d1d67..64a0291 100644 --- a/scopes.go +++ b/scopes.go @@ -16,6 +16,7 @@ type ContextState interface{} type Context interface { stdlib_context.Context + Addressable Config() Config Name() string Parent() Context @@ -56,6 +57,7 @@ type Addressable interface { type Address interface { fmt.Stringer + Addressable Url() string Service() string Interaction() (string, string) @@ -131,10 +133,14 @@ func HandleMsg(ctx Context, msg Message) bool { } func Send(ctx Context, addr Address, msg Message) { + if msg.Sender() == nil { + msg.WithSender(ctx) + } if svc, ok := ctx.Services()[addr.Service()]; ok { // TODO: check Address for sid, iid svc.Send(msg) } + // TODO: Warn().Msg("receiver not found") } func GetState[St ContextState](ctx Context) St { diff --git a/tests/matrix_test.go b/tests/matrix_test.go index 693fd8b..855c7c1 100644 --- a/tests/matrix_test.go +++ b/tests/matrix_test.go @@ -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), 8) } func MxTest(t *testing.T) {