Skip to content

Commit

Permalink
client: Implement Disconnect/Logout/IsLoggedIn/IsThisUser
Browse files Browse the repository at this point in the history
  • Loading branch information
purpshell committed Oct 9, 2024
1 parent 3f647b6 commit 6fd7913
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
_ bridgev2.ReadReceiptHandlingNetworkAPI = (*TwitterClient)(nil)
)

func NewTwitterClient(ctx context.Context, tc *TwitterConnector, login *bridgev2.UserLogin) (*TwitterClient, error) {
func NewTwitterClient(ctx context.Context, login *bridgev2.UserLogin) *TwitterClient {
log := zerolog.Ctx(ctx).With().
Str("component", "twitter_client").
Str("user_login_id", string(login.ID)).
Expand All @@ -69,7 +69,7 @@ func NewTwitterClient(ctx context.Context, tc *TwitterConnector, login *bridgev2

twitClient.client.SetEventHandler(twitClient.HandleTwitterEvent)

return twitClient, nil
return twitClient
}

func (tc *TwitterClient) Connect(ctx context.Context) error {
Expand Down
22 changes: 2 additions & 20 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ package connector
import (
"context"
"fmt"
"log"

"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"

"go.mau.fi/mautrix-twitter/pkg/twittermeow"
twitCookies "go.mau.fi/mautrix-twitter/pkg/twittermeow/cookies"
"go.mau.fi/mautrix-twitter/pkg/twittermeow/data/types"
)

type TwitterConnector struct {
Expand All @@ -46,8 +41,6 @@ func (tc *TwitterConnector) Init(bridge *bridgev2.Bridge) {
}

func (tc *TwitterConnector) Start(_ context.Context) error {

log.Println("starting....")
return nil
}

Expand Down Expand Up @@ -82,19 +75,8 @@ type UserLoginMetadata struct {
Cookies string
}

func (tc *TwitterConnector) LoadUserLogin(_ context.Context, login *bridgev2.UserLogin) error {
meta := login.Metadata.(*UserLoginMetadata)
clientOpts := &twittermeow.ClientOpts{
Cookies: twitCookies.NewCookiesFromString(meta.Cookies),
WithJOTClient: true,
}
twitClient := &TwitterClient{
connector: tc,
userLogin: login,
client: twittermeow.NewClient(clientOpts, login.Log),
userCache: make(map[string]types.User),
}
twitClient.client.SetEventHandler(twitClient.HandleTwitterEvent)
func (tc *TwitterConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) error {
twitClient := NewTwitterClient(ctx, login)

_, currentUser, err := twitClient.client.LoadMessagesPage()
if err != nil {
Expand Down

0 comments on commit 6fd7913

Please sign in to comment.