Join WebSocket contexts on reconnect

This commit is contained in:
Elara 2022-12-12 18:40:55 -08:00
parent 27c94b7d21
commit 5d53167775
3 changed files with 17 additions and 12 deletions

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 github.com/pelletier/go-toml/v2 v2.0.6
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/vmihailenco/msgpack/v5 v5.3.5 github.com/vmihailenco/msgpack/v5 v5.3.5
go.arsenm.dev/go-lemmy v0.0.0-20221213021222-a4a015a4cc2a go.arsenm.dev/go-lemmy v0.0.0-20221213023656-b38c6b0a5455
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334
go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e
) )

4
go.sum
View File

@ -45,8 +45,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.arsenm.dev/go-lemmy v0.0.0-20221213021222-a4a015a4cc2a h1:iBeRt2sU8Y3pwKPKTFnkIcTwFTvifyCLUtjjsj7CaWM= go.arsenm.dev/go-lemmy v0.0.0-20221213023656-b38c6b0a5455 h1:AUeVhWSB6Wzz6TDiMSi6TGrzXyPGg3flXdASs+42vTA=
go.arsenm.dev/go-lemmy v0.0.0-20221213021222-a4a015a4cc2a/go.mod h1:/XgX+cQqs9a2VJWwZ67wArjK2CVXWKdEEpHdAFbFRNQ= go.arsenm.dev/go-lemmy v0.0.0-20221213023656-b38c6b0a5455/go.mod h1:hLkcWy1iV2PlzZZVWjuV3Y3hMynM0k8g9Ul94CcusUM=
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 h1:S98LJOBmj1pAKSw94spJk6+n8ERlBNTxi4lt5B67nQo= go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334 h1:S98LJOBmj1pAKSw94spJk6+n8ERlBNTxi4lt5B67nQo=
go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw= go.arsenm.dev/logger v0.0.0-20221007032343-cbffce4f4334/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e h1:4XwLmFDvAKt7ZvS3E3hD2R++0wr75fBUEvXkK9dLXzk= go.arsenm.dev/pcre v0.0.0-20220530205550-74594f6c8b0e h1:4XwLmFDvAKt7ZvS3E3hD2R++0wr75fBUEvXkK9dLXzk=

23
main.go
View File

@ -45,17 +45,22 @@ func main() {
log.Info("Successfully logged in to Lemmy instance").Send() log.Info("Successfully logged in to Lemmy instance").Send()
err = c.Request(types.UserOpUserJoin, nil) c.SetConnectHandler(func() error {
if err != nil { err = c.Request(types.UserOpUserJoin, nil)
log.Fatal("Error joining WebSocket user context").Err(err).Send() if err != nil {
} log.Fatal("Error joining WebSocket user context").Err(err).Send()
}
err = c.Request(types.UserOpCommunityJoin, types.CommunityJoin{ err = c.Request(types.UserOpCommunityJoin, types.CommunityJoin{
CommunityID: 0, CommunityID: 0,
})
if err != nil {
log.Fatal("Error joining WebSocket community context").Err(err).Send()
}
return nil
}) })
if err != nil {
log.Fatal("Error joining WebSocket community context").Err(err).Send() c.ConnectHandler()
}
replyCh := make(chan replyJob, 200) replyCh := make(chan replyJob, 200)