diff options
| author | raven <citrons@mondecitronne.com> | 2025-10-22 15:48:40 -0500 |
|---|---|---|
| committer | raven <citrons@mondecitronne.com> | 2025-10-22 16:23:32 -0500 |
| commit | 4b54a1d11fd0fa355b244637612a3fd0af18c60c (patch) | |
| tree | 43a2d2d1feff2caf40a2e33b6ac4d61185708ab3 | |
| parent | 9126f2329aa21645e0d5622b0eeed402273efa95 (diff) | |
events generated from other clients on the same account
| -rw-r--r-- | client/application.go | 22 | ||||
| -rw-r--r-- | client/channel_window.go | 11 | ||||
| -rw-r--r-- | server/channel/channel.go | 14 | ||||
| -rw-r--r-- | server/channel/command.go | 6 | ||||
| -rw-r--r-- | server/server/command.go | 1 | ||||
| -rw-r--r-- | server/user/user.go | 1 |
6 files changed, 42 insertions, 13 deletions
diff --git a/client/application.go b/client/application.go index eb72d14..d396f24 100644 --- a/client/application.go +++ b/client/application.go @@ -78,11 +78,20 @@ func (a *application) OnEvent(cmd proto.Command) { } case "delete": a.cache.Gone(cmd.Target) + fallthrough + case "leave": cl := channelLocation {id: cmd.Target} - if a.windowCache.Get(cl) != nil { - a.windowCache.Evict(cl) - a.removeFromHistory(cl) + w := a.windowCache.Get(cl) + if w != nil { + w.(*channelWindow).onLeaveChannel() } + a.channelList.remove(cl) + case "join": + a.cache.Fetch(cmd.Target, func(ch *proto.Object) { + if ch != nil { + a.newChannel(*ch) + } + }) } } @@ -103,11 +112,8 @@ func (a *application) OnResponse(requestId string, cmd proto.Command) { if len(cmd.Args) > 0 { a.cmdWindow.info("your name is: %s", cmd.Args[0].Fields[""]) } - case "p": - if len(cmd.Args) > 0 { - a.onPut(cmd.Target, cmd.Args[0]) - } } + a.OnEvent(cmd) } func (a *application) onUpdate(target string, update proto.Object) { @@ -248,6 +254,7 @@ func (a *application) join(channelName string) { case *channelWindow: w.(*channelWindow).endOfHistory = false } + a.goTo(channelLocation {id: ch.Id}) case "fail": if len(response.Args) > 0 { f := proto.Fail(response.Args[0]) @@ -283,6 +290,7 @@ func (a *application) createChannel(name string) { case "create": if len(response.Args) > 0 { a.newChannel(response.Args[0]) + a.goTo(channelLocation {id: response.Args[0].Id}) } case "fail": if len(response.Args) > 0 { diff --git a/client/channel_window.go b/client/channel_window.go index cb6aff2..50b7165 100644 --- a/client/channel_window.go +++ b/client/channel_window.go @@ -57,6 +57,11 @@ func (cw *channelWindow) getChannel() *proto.Object { return globalApp.cache.Get(cw.location.id) } +func (cw *channelWindow) isDirect() bool { + ch := cw.getChannel() + return ch != nil && ch.Kind == "direct-channel" +} + func (cw *channelWindow) watchUser(uid string) { if !cw.watchedUsers[uid] { globalApp.cache.Watch(uid) @@ -147,6 +152,12 @@ func (cw *channelWindow) replyTo(id string) { func (cw *channelWindow) leaveChannel() { globalApp.Request(proto.NewCmd("leave", cw.location.id), nil) + if !cw.isDirect() { + cw.onLeaveChannel() + } +} + +func (cw *channelWindow) onLeaveChannel() { globalApp.windowCache.Evict(cw.location) globalApp.removeFromHistory(cw.location) globalApp.channelList.remove(cw.location) diff --git a/server/channel/channel.go b/server/channel/channel.go index 81d5439..9ec0b41 100644 --- a/server/channel/channel.go +++ b/server/channel/channel.go @@ -178,7 +178,7 @@ func (c *Channel) Rename(name string) *proto.Fail { return nil } -func (c *Channel) Put(m proto.Object) proto.Object { +func (c *Channel) Put(m proto.Object, From *session.Session) proto.Object { m.Id = proto.GenId() m.Fields["t"] = proto.Timestamp() err := c.kind.db.Update(func(tx *bolt.Tx) error { @@ -206,7 +206,7 @@ func (c *Channel) Put(m proto.Object) proto.Object { log.Fatal("error updating database: ", err) } for s, _ := range c.Stream.Subscribers() { - if m.Fields["f"] == s.UserId { + if From == s { continue } if c.GetMembership(s.UserId).See { @@ -284,20 +284,26 @@ func (c *Channel) History(min, max int) []proto.Object { } func (c *Channel) Join(u *user.User) *proto.Fail { + if c.isDirect { + return &proto.Fail {"invalid", "", nil} + } if c.GetMembership(u.Id()).Yes { return nil } c.SetMembership(u.Id(), c.GetDefaultMembership()) - c.Put(proto.Object{"join", "", map[string]string {"f": u.Id()}}) + c.Put(proto.Object{"join", "", map[string]string {"f": u.Id()}}, nil) return nil } func (c *Channel) Leave(u *user.User) *proto.Fail { + if c.isDirect { + return &proto.Fail {"invalid", "", nil} + } if !c.GetMembership(u.Id()).Yes { return nil } c.SetMembership(u.Id(), Membership {Yes: false}) - c.Put(proto.Object{"leave", "", map[string]string {"f": u.Id()}}) + c.Put(proto.Object{"leave", "", map[string]string {"f": u.Id()}}, nil) return nil } diff --git a/server/channel/command.go b/server/channel/command.go index 04e45a2..92ae2cc 100644 --- a/server/channel/command.go +++ b/server/channel/command.go @@ -46,7 +46,7 @@ func (c *Channel) SendRequest(r session.Request) { } m.Fields["f"] = r.From.UserId - r.Reply(proto.NewCmd("p", c.id, c.Put(m))) + r.Reply(proto.NewCmd("p", c.id, c.Put(m, r.From))) case "i": r.Reply(proto.NewCmd("i", "", c.InfoFor(r.From.UserId))) @@ -66,6 +66,7 @@ func (c *Channel) SendRequest(r session.Request) { r.Reply(err.Cmd()) } else { r.ReplyOk() + u.PrivateStream.Event(proto.NewCmd("join", c.id)) } case "leave": @@ -75,6 +76,7 @@ func (c *Channel) SendRequest(r session.Request) { r.Reply(err.Cmd()) } else { r.ReplyOk() + u.PrivateStream.Event(proto.NewCmd("leave", c.id)) } case "delete": @@ -249,7 +251,7 @@ func (c *Channel) SendRequest(r session.Request) { return } c.SetMembership(id, new) - c.Put(o) + c.Put(o, r.From) i := new.GetInfo() i.Fields[""] = id diff --git a/server/server/command.go b/server/server/command.go index e8ced39..75f3bc0 100644 --- a/server/server/command.go +++ b/server/server/command.go @@ -104,6 +104,7 @@ func (s *server) SendRequest(r session.Request) { u := s.world.GetObject(r.From.UserId).(*user.User) c.Join(u) c.SetMembership(u.Id(), channel.CreatorMembership) + u.PrivateStream.Event(proto.NewCmd("join", c.Id())) r.Reply(proto.NewCmd("create", "", c.InfoFor(r.From.UserId))) default: r.ReplyInvalid() diff --git a/server/user/user.go b/server/user/user.go index 7f272c1..311a1b8 100644 --- a/server/user/user.go +++ b/server/user/user.go @@ -21,6 +21,7 @@ type User struct { status string description string Stream session.Stream + PrivateStream session.Stream anonymous bool } |
