summaryrefslogtreecommitdiff
path: root/client/application.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-05 14:57:45 -0500
committercitrons <citrons@mondecitronne.com>2025-06-07 16:02:18 -0500
commit4e46b6cad58b6a4f0e9235a267c817e239b42334 (patch)
treec0da8bab94148ef26c3624477a4a26f4fdd3fed7 /client/application.go
parentcf78bc0515fa38a6cc570afd7a7e0000bdcda09e (diff)
automatically rejoin channels on reconnect
Diffstat (limited to 'client/application.go')
-rw-r--r--client/application.go28
1 files changed, 27 insertions, 1 deletions
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])