From 4e46b6cad58b6a4f0e9235a267c817e239b42334 Mon Sep 17 00:00:00 2001 From: citrons Date: Thu, 5 Jun 2025 14:57:45 -0500 Subject: automatically rejoin channels on reconnect --- client/application.go | 28 +++++++++++++++++++++++++++- server/user/user.go | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/client/application.go b/client/application.go index 388272f..338faeb 100644 --- a/client/application.go +++ b/client/application.go @@ -47,7 +47,6 @@ func (a *application) OnConnect() { a.connected = true a.reconnecting = false a.cache = object.NewCache(a) - a.windowCache = window.NewCache() a.cmdWindow.info("connected to %s", a.Client.Address) } @@ -56,6 +55,7 @@ func (a *application) OnDisconnect(err error) { a.authenticated = false a.uid = "" a.prompts = nil + a.windowCache = window.NewCache() if !a.reconnecting { a.cmdWindow.err( "disconnected from %s: %s\nreconnecting...", a.Client.Address, err, @@ -150,7 +150,27 @@ func (a *application) auth(name string, authCallback func(success bool)) { func (a *application) onAuth() { a.Request(proto.NewCmd("channels", ""), func(response proto.Command) { if response.Kind == "channels" { + previousChannels := make(channelList, len(a.channelList)) + copy(previousChannels, a.channelList) + a.channelList.setChannels(response.Args) + + u := a.cache.Get(a.uid) + if u.Fields["anonymous"] == "yes" { + for _, c := range previousChannels { + cb := func(response proto.Command) { + if response.Kind == "ok" { + a.channelList = append(a.channelList, c) + } + w := a.windowCache.Get(c.location) + switch w.(type) { + case *channelWindow: + w.(*channelWindow).endOfHistory = false + } + } + a.Request(proto.NewCmd("join", c.location.id), cb) + } + } } }) } @@ -189,6 +209,12 @@ func (a *application) join(channelName string) { case "ok": a.channelList.add(channelName, channelLocation {id: ch.Id}) a.goTo(channelLocation {id: ch.Id}) + + w := a.windowCache.Get(channelLocation {id: ch.Id}) + switch w.(type) { + case *channelWindow: + w.(*channelWindow).endOfHistory = false + } case "fail": if len(response.Args) > 0 { f := proto.Fail(response.Args[0]) diff --git a/server/user/user.go b/server/user/user.go index fa5f37b..4d1d936 100644 --- a/server/user/user.go +++ b/server/user/user.go @@ -104,6 +104,11 @@ func (u *User) GetInfo() proto.Object { if u.status != "" { i["status"] = u.status } + if u.Anonymous { + i["anonymous"] = "yes" + } else { + i["anonymous"] = "no" + } return proto.Object {"u", u.id, i} } -- cgit v1.2.3