Skip to content

Commit

Permalink
client: switch to userBoot
Browse files Browse the repository at this point in the history
Fixes #54
  • Loading branch information
tulir committed Dec 11, 2024
1 parent 4d5a798 commit ebd6f7e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module go.mau.fi/mautrix-slack

go 1.22.0

toolchain go1.23.3
toolchain go1.23.4

require (
github.com/lib/pq v1.10.9
github.com/rs/zerolog v1.33.0
github.com/slack-go/slack v0.13.1
github.com/stretchr/testify v1.9.0
github.com/slack-go/slack v0.15.0
github.com/stretchr/testify v1.10.0
github.com/yuin/goldmark v1.7.8
go.mau.fi/util v0.8.2
golang.org/x/net v0.31.0
golang.org/x/net v0.32.0
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.22.1-0.20241202131110-166ba04aae02
maunium.net/go/mautrix v0.22.1-0.20241211205709-48b7b3aca5b7
)

require (
Expand All @@ -34,13 +34,13 @@ require (
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.mau.fi/zeroconfig v0.1.3 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
maunium.net/go/mauflag v1.0.0 // indirect
)

replace github.com/slack-go/slack => github.com/beeper/slackgo v0.0.0-20240930085310-1180a3fa18e0
replace github.com/slack-go/slack => github.com/beeper/slackgo v0.0.0-20241211205744-f532856a1038
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/beeper/slackgo v0.0.0-20240930085310-1180a3fa18e0 h1:pbcHKPrs8QOscKJPVQe2Fuar5xskeF9Tf/xrGcqkgf0=
github.com/beeper/slackgo v0.0.0-20240930085310-1180a3fa18e0/go.mod h1:K+6JA6FP9/mILahVr6VH67l83p0sWkayPiDOBhzKWlo=
github.com/beeper/slackgo v0.0.0-20241211205744-f532856a1038 h1:zP5Yl+MGAfNgbuyf1zP7YoXYIndra3iEknlILyUCPko=
github.com/beeper/slackgo v0.0.0-20241211205744-f532856a1038/go.mod h1:axoegr/0xf8uWt4I+coY6x+CVKPbWGs4YqpoYbCBRr8=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -38,8 +38,8 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand All @@ -55,21 +55,21 @@ go.mau.fi/util v0.8.2 h1:zWbVHwdRKwI6U9AusmZ8bwgcLosikwbb4GGqLrNr1YE=
go.mau.fi/util v0.8.2/go.mod h1:BHHC9R2WLMJd1bwTZfTcFxUgRFmUgUmiWcT4RbzUgiA=
go.mau.fi/zeroconfig v0.1.3 h1:As9wYDKmktjmNZW5i1vn8zvJlmGKHeVxHVIBMXsm4kM=
go.mau.fi/zeroconfig v0.1.3/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
Expand All @@ -78,5 +78,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/mautrix v0.22.1-0.20241202131110-166ba04aae02 h1:g8L4GpOhyg5EuXtASDKyU9Cg79ZjATlUnh+giFumQgc=
maunium.net/go/mautrix v0.22.1-0.20241202131110-166ba04aae02/go.mod h1:oqwf9WYC/brqucM+heYk4gX11O59nP+ljvyxVhndFIM=
maunium.net/go/mautrix v0.22.1-0.20241211205709-48b7b3aca5b7 h1:g2RMNtD/VysyFimay8SrMMUSFxzGvhPzD0bmQOV8NgA=
maunium.net/go/mautrix v0.22.1-0.20241211205709-48b7b3aca5b7/go.mod h1:oqwf9WYC/brqucM+heYk4gX11O59nP+ljvyxVhndFIM=
16 changes: 10 additions & 6 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type SlackClient struct {
SocketMode *socketmode.Client
UserID string
TeamID string
BootResp *slack.ClientBootResponse
BootResp *slack.ClientUserBootResponse
TeamPortal *bridgev2.Portal
IsRealUser bool
Ghost *bridgev2.Ghost
Expand Down Expand Up @@ -162,10 +162,14 @@ func (s *SlackClient) Connect(ctx context.Context) {
})
return
}
var bootResp *slack.ClientBootResponse
var bootResp *slack.ClientUserBootResponse
if s.IsRealUser {
var err error
bootResp, err = s.Client.ClientBootContext(ctx)
err := s.Client.FetchVersionData(ctx)
if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to fetch version data")
}
// TODO do actual warm boots by saving last received ts somewhere
bootResp, err = s.Client.ClientUserBootContext(ctx, time.Time{})
if err != nil {
s.handleBootError(ctx, err)
return
Expand All @@ -183,7 +187,7 @@ func (s *SlackClient) Connect(ctx context.Context) {
s.handleBootError(ctx, err)
return
}
bootResp = &slack.ClientBootResponse{
bootResp = &slack.ClientUserBootResponse{
Self: *userResp,
Team: *teamResp,
}
Expand All @@ -199,7 +203,7 @@ func (s *SlackClient) Connect(ctx context.Context) {
}
}

func (s *SlackClient) connect(ctx context.Context, bootResp *slack.ClientBootResponse) error {
func (s *SlackClient) connect(ctx context.Context, bootResp *slack.ClientUserBootResponse) error {
s.initialConnect = time.Now()
s.BootResp = bootResp
err := s.syncTeamPortal(ctx)
Expand Down
9 changes: 8 additions & 1 deletion pkg/connector/login-cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package connector
import (
"context"
"fmt"
"time"

"github.com/rs/zerolog"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"

Expand Down Expand Up @@ -127,7 +129,12 @@ func (s *SlackTokenLogin) Cancel() {}
func (s *SlackTokenLogin) SubmitCookies(ctx context.Context, input map[string]string) (*bridgev2.LoginStep, error) {
token, cookieToken := input["auth_token"], input["cookie_token"]
client := makeSlackClient(&s.User.Log, token, cookieToken, "")
info, err := client.ClientBootContext(ctx)
err := client.FetchVersionData(ctx)
if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to fetch version data")
return nil, err
}
info, err := client.ClientUserBootContext(ctx, time.Time{})
if err != nil {
return nil, fmt.Errorf("client.boot failed: %w", err)
}
Expand Down

0 comments on commit ebd6f7e

Please sign in to comment.