matrix: send 'connect' message upon cell creation

This commit is contained in:
Helmut Merz 2023-07-24 14:54:24 +02:00
parent 5a7cbba536
commit 0f054c36e8
3 changed files with 19 additions and 10 deletions

View file

@ -5,6 +5,7 @@ import (
"git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/core" "git.sr.ht/~cco/go-scopes/core"
"git.sr.ht/~cco/go-scopes/core/action" "git.sr.ht/~cco/go-scopes/core/action"
"git.sr.ht/~cco/go-scopes/core/message"
) )
func Start(ctx lib.Context) { func Start(ctx lib.Context) {
@ -13,16 +14,18 @@ func Start(ctx lib.Context) {
core.Start(ctx) core.Start(ctx)
} }
type celLConfig struct {
*config.BaseCfg
}
func create(act lib.Action) bool { func create(act lib.Action) bool {
ctx := act.Context() msg := act.Message()
//msg := act.Message()
//spec := act.ActionSpec() //spec := act.ActionSpec()
cctx := ctx.ChildContext(config.Base("", core.Start)) cctx := createCell(act.Context())
core.Start(cctx) nmsg := message.New("matrix", "connect").WithSender(cctx)
// msg.Sender().Cell().Send(message.New("matrix", "connect").WithSender(cctx)) msg.Sender().Cell().Send(nmsg)
return true return true
} }
func createCell(ctx lib.Context) lib.Context {
cfg := config.Base("", core.Start)
cctx := ctx.ChildContext(cfg)
cfg.Starter()(cctx)
return cctx
}

View file

@ -16,6 +16,7 @@ type ContextState interface{}
type Context interface { type Context interface {
stdlib_context.Context stdlib_context.Context
Addressable
Config() Config Config() Config
Name() string Name() string
Parent() Context Parent() Context
@ -56,6 +57,7 @@ type Addressable interface {
type Address interface { type Address interface {
fmt.Stringer fmt.Stringer
Addressable
Url() string Url() string
Service() string Service() string
Interaction() (string, string) Interaction() (string, string)
@ -131,10 +133,14 @@ func HandleMsg(ctx Context, msg Message) bool {
} }
func Send(ctx Context, addr Address, msg Message) { func Send(ctx Context, addr Address, msg Message) {
if msg.Sender() == nil {
msg.WithSender(ctx)
}
if svc, ok := ctx.Services()[addr.Service()]; ok { if svc, ok := ctx.Services()[addr.Service()]; ok {
// TODO: check Address for sid, iid // TODO: check Address for sid, iid
svc.Send(msg) svc.Send(msg)
} }
// TODO: Warn().Msg("receiver not found")
} }
func GetState[St ContextState](ctx Context) St { func GetState[St ContextState](ctx Context) St {

View file

@ -16,7 +16,7 @@ func TestMatrixApp(tb *tbase.T) {
t := testing.SetUpApp(tb, etc.ConfigMx()) t := testing.SetUpApp(tb, etc.ConfigMx())
t.Run("app-matrix", MxTest) t.Run("app-matrix", MxTest)
t.TearDownApp("matrix") t.TearDownApp("matrix")
t.AssertEqual(t.LogCheck(logfile, true), 7) t.AssertEqual(t.LogCheck(logfile, true), 8)
} }
func MxTest(t *testing.T) { func MxTest(t *testing.T) {