summaryrefslogtreecommitdiff
path: root/server/user/command.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-01-26 01:56:53 -0600
committercitrons <citrons@mondecitronne.com>2025-01-26 01:56:53 -0600
commit10b8a79389e7073f6bd65695c3d05c77b825bc33 (patch)
treeb7e6dbd84b5b2c960ab8aafc1f99c3950d679e44 /server/user/command.go
initial commit
Diffstat (limited to 'server/user/command.go')
-rw-r--r--server/user/command.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/server/user/command.go b/server/user/command.go
new file mode 100644
index 0000000..210dede
--- /dev/null
+++ b/server/user/command.go
@@ -0,0 +1,76 @@
+package user
+
+import (
+ "citrons.xyz/talk/server/session"
+ "citrons.xyz/talk/proto"
+)
+
+func (u *User) SendRequest(r session.Request) {
+ switch r.Cmd.Kind {
+
+ case "update":
+ if r.From.UserId != u.Id() {
+ r.Reply(proto.Fail{"forbidden", "", nil}.Cmd())
+ return
+ }
+ if len(r.Cmd.Args) != 1 {
+ r.ReplyInvalid()
+ return
+ }
+ upd := r.Cmd.Args[0]
+ if upd.Kind != "u" {
+ r.ReplyInvalid()
+ return
+ }
+ name := u.name
+ for k, v := range upd.Fields {
+ switch k {
+ case "":
+ name = v
+ default:
+ r.ReplyInvalid()
+ return
+ }
+ }
+ if name != u.name {
+ err := u.Rename(name)
+ if err != nil {
+ r.Reply(err.Cmd())
+ return
+ }
+ }
+ u.Stream.Event(r.Cmd)
+ r.Reply(proto.NewCmd("ok", ""))
+
+ case "i":
+ r.Reply(proto.NewCmd("i", "", u.GetInfo()))
+
+ case "s":
+ r.From.Subscribe(&u.Stream)
+ r.Reply(proto.NewCmd("i", "", u.GetInfo()))
+
+ case "u":
+ r.From.Unsubscribe(&u.Stream)
+ r.Reply(proto.NewCmd("ok", ""))
+
+ default:
+ 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.Reply(proto.NewCmd("ok", ""))
+
+ default:
+ r.ReplyInvalid()
+ }
+}