diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-12 15:19:56 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-12 15:24:48 -0500 |
| commit | 6e9496323fbdfbe2b60122ce68cf3791ccb2910d (patch) | |
| tree | e9e88b894b56441b1b5591f626c776224dc0669c /server | |
| parent | ececa97d9ee6a435f81756bc25e25ed80285d20b (diff) | |
object.Tombstone
Diffstat (limited to 'server')
| -rw-r--r-- | server/channel/channel.go | 17 | ||||
| -rw-r--r-- | server/channel/command.go | 17 | ||||
| -rw-r--r-- | server/object/tombstone.go | 29 | ||||
| -rw-r--r-- | server/user/command.go | 17 | ||||
| -rw-r--r-- | server/user/user.go | 20 |
5 files changed, 36 insertions, 64 deletions
diff --git a/server/channel/channel.go b/server/channel/channel.go index 6ef21ba..3cb6f60 100644 --- a/server/channel/channel.go +++ b/server/channel/channel.go @@ -14,7 +14,6 @@ type ChannelStore struct { world *object.World byName map[string]*Channel directChannels map[string]*Channel - deleted map[string]Tombstone } type Channel struct { @@ -29,14 +28,9 @@ type Channel struct { Stream session.Stream } -type Tombstone struct { - name string -} - func NewStore(world *object.World) *ChannelStore { return &ChannelStore { world, make(map[string]*Channel), make(map[string]*Channel), - make(map[string]Tombstone), } } @@ -209,8 +203,9 @@ func (c *Channel) Delete() { delete(c.store.byName, validate.Fold(c.name)) c.store.world.RemoveObject(c.id) - deleted := Tombstone {c.name} - c.store.deleted[c.id] = deleted + deleted := object.Tombstone { + c.id, map[string]string {"": c.name, "kind": c.Kind()}, + } c.store.world.PutObject(c.id, deleted) } @@ -228,9 +223,3 @@ func (c *Channel) InfoFor(uid string) proto.Object { c.Kind(), c.id, map[string]string {"": c.NameFor(uid)}, } } - -func (t Tombstone) GetInfo() proto.Object { - return proto.Object { - "gone", "", map[string]string {"": t.name, "kind": "channel"}, - } -} diff --git a/server/channel/command.go b/server/channel/command.go index 3434326..1171d2f 100644 --- a/server/channel/command.go +++ b/server/channel/command.go @@ -262,20 +262,3 @@ func (c *Channel) SendRequest(r session.Request) { r.ReplyInvalid() } } - -func (t Tombstone) SendRequest(r session.Request) { - switch r.Cmd.Kind { - - case "update": - r.Reply(proto.Fail{"bad-target", "", nil}.Cmd()) - - case "i", "s": - r.Reply(proto.NewCmd("i", "", t.GetInfo())) - - case "u": - r.ReplyOk() - - default: - r.ReplyInvalid() - } -} diff --git a/server/object/tombstone.go b/server/object/tombstone.go new file mode 100644 index 0000000..05d9600 --- /dev/null +++ b/server/object/tombstone.go @@ -0,0 +1,29 @@ +package object + +import ( + "citrons.xyz/talk/proto" + "citrons.xyz/talk/server/session" +) + +type Tombstone struct { + Id string + Fields map[string]string +} + +func (t Tombstone) InfoFor(uid string) proto.Object { + return proto.Object {"gone", t.Id, t.Fields} +} + +func (t Tombstone) SendRequest(r session.Request) { + switch r.Cmd.Kind { + + case "i", "s": + r.Reply(proto.NewCmd("i", "", t.InfoFor(r.From.UserId))) + + case "u": + r.ReplyOk() + + default: + r.Reply(proto.Fail{"bad-target", "", nil}.Cmd()) + } +} diff --git a/server/user/command.go b/server/user/command.go index 6eef81b..14a8b57 100644 --- a/server/user/command.go +++ b/server/user/command.go @@ -65,20 +65,3 @@ func (u *User) SendRequest(r session.Request) { r.ReplyInvalid() } } - -func (t Tombstone) SendRequest(r session.Request) { - switch r.Cmd.Kind { - - case "update": - r.Reply(proto.Fail{"bad-target", "", nil}.Cmd()) - - case "i", "s": - r.Reply(proto.NewCmd("i", "", t.GetInfo())) - - case "u": - r.ReplyOk() - - default: - r.ReplyInvalid() - } -} diff --git a/server/user/user.go b/server/user/user.go index fb1022f..17063b4 100644 --- a/server/user/user.go +++ b/server/user/user.go @@ -10,7 +10,6 @@ import ( type UserStore struct { world *object.World byName map[string]*User - gone map[string]Tombstone } type User struct { @@ -24,14 +23,8 @@ type User struct { Anonymous bool } -type Tombstone struct { - name string -} - func NewStore(world *object.World) *UserStore { - return &UserStore { - world, make(map[string]*User), make(map[string]Tombstone), - } + return &UserStore {world, make(map[string]*User)} } func (us *UserStore) CreateUser(name string) (*User, *proto.Fail) { @@ -94,8 +87,9 @@ func (u *User) Delete() { delete(u.store.byName, validate.Fold(u.name)) u.store.world.RemoveObject(u.id) - gone := Tombstone {u.name} - u.store.gone[u.id] = gone + gone := object.Tombstone { + u.id, map[string]string {"": u.name, "kind": "u"}, + } u.store.world.PutObject(u.id, gone) } @@ -111,9 +105,3 @@ func (u *User) InfoFor(uid string) proto.Object { } return proto.Object {"u", u.id, i} } - -func (t Tombstone) GetInfo() proto.Object { - return proto.Object { - "gone", "", map[string]string {"": t.name, "kind": "u"}, - } -} |
