work in progress: matrix; message: sender as Addressable type

This commit is contained in:
Helmut Merz 2023-07-24 10:32:25 +02:00
parent f55416dddf
commit 9a609ce880
5 changed files with 49 additions and 8 deletions

View file

@ -42,7 +42,7 @@ func (h *head) Item() string {
type message struct {
*head
sender lib.Address
sender lib.Addressable
payload lib.Payload
}
@ -50,7 +50,7 @@ func (msg *message) Head() lib.MsgHead {
return msg
}
func (msg *message) Sender() lib.Address {
func (msg *message) Sender() lib.Addressable {
return msg.sender
}
@ -58,7 +58,7 @@ func (msg *message) Payload() lib.Payload {
return msg.payload
}
func (msg *message) WithSender(s lib.Address) lib.Message {
func (msg *message) WithSender(s lib.Addressable) lib.Message {
msg.sender = s
return msg
}

View file

@ -1 +1,17 @@
package matrix
import (
lib "git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/core"
"git.sr.ht/~cco/go-scopes/core/action"
)
func Start(ctx lib.Context) {
cfg := ctx.Config()
cfg.AddAction("create", action.Base(create))
core.Start(ctx)
}
func create(act lib.Action) bool {
return true
}

View file

@ -41,12 +41,17 @@ type MsgHead interface {
type Message interface {
MsgHead
Head() MsgHead
Sender() Address
Sender() Addressable
Payload() Payload
WithSender(Address) Message
WithSender(Addressable) Message
WithPayload(Payload) Message
}
type Addressable interface {
Address() Address
Cell() Context
}
type Address interface {
fmt.Stringer
Url() string

View file

@ -8,6 +8,7 @@ import (
"git.sr.ht/~cco/go-scopes/core"
"git.sr.ht/~cco/go-scopes/core/action"
"git.sr.ht/~cco/go-scopes/logging"
"git.sr.ht/~cco/go-scopes/matrix"
)
func ConfigMx() lib.Config {
@ -25,7 +26,9 @@ func ConfigMx() lib.Config {
test_rcvr := b("test-receiver", core.Start).
AddAction("demo", action.Base(AH_MxReceiver))
app_c.Add(test_rcvr)
cell_0 := b("cell-0", matrix.Start)
app_c.Add(cell_0, test_rcvr)
return app_c
}

View file

@ -4,7 +4,9 @@ import (
"os"
tbase "testing"
lib "git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/common/testing"
"git.sr.ht/~cco/go-scopes/core/message"
"git.sr.ht/~cco/go-scopes/tests/etc"
)
@ -14,10 +16,25 @@ 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), 3)
t.AssertEqual(t.LogCheck(logfile, true), 6)
}
func MxTest(t *testing.T) {
ctx := t.Ctx
t.AssertEqual(len(ctx.Services()), 2)
t.AssertEqual(len(ctx.Services()), 3)
rcvr := message.SimpleAddress("cell-0")
msg := message.SimpleMessage("create")
lib.Send(ctx, rcvr, msg)
}
// action handlers
func MxReceiver(act lib.Action) bool {
t := testing.GetT(act.Context())
t.AssertEqual(act.Message().Action(), "demo")
return true
}
func init() {
etc.AH_MxReceiver = MxReceiver
}