Skip to content

Commit

Permalink
set LoginCookiesParams.Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Jan 3, 2025
1 parent ccebf1d commit 98b720e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
12 changes: 11 additions & 1 deletion pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
Expand Down Expand Up @@ -41,7 +42,16 @@ func NewClient(userLogin *bridgev2.UserLogin, client *gchatmeow.Client) *GChatCl
func (c *GChatClient) Connect(ctx context.Context) error {
c.client.OnConnect.AddObserver(func(interface{}) { c.onConnect(ctx) })
c.client.OnStreamEvent.AddObserver(func(evt interface{}) { c.onStreamEvent(ctx, evt) })
return c.client.Connect(ctx, time.Duration(90)*time.Minute)

err := c.client.Connect(ctx, time.Duration(90)*time.Minute)
if err != nil {
c.userLogin.BridgeState.Send(status.BridgeState{
StateEvent: status.StateBadCredentials,
Error: "googlechat-invalid-credentials",
Message: err.Error(),
})
}
return err
}

func (c *GChatClient) Disconnect() {
Expand Down
15 changes: 9 additions & 6 deletions pkg/connector/handlegchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) {
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventTyping, state.UserId.Id, state.StartTimestampUsec),
})
case proto.Event_READ_RECEIPT_CHANGED:
receipts := evt.Body.GetReadReceiptChanged().ReadReceiptSet.ReadReceipts
for _, receipt := range receipts {
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Receipt{
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventReadReceipt, receipt.User.UserId.Id, receipt.ReadTimeMicros),
ReadUpTo: time.UnixMicro(receipt.ReadTimeMicros),
})
changed := evt.Body.GetReadReceiptChanged()
if changed != nil {
receipts := changed.ReadReceiptSet.ReadReceipts
for _, receipt := range receipts {
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Receipt{
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventReadReceipt, receipt.User.UserId.Id, receipt.ReadTimeMicros),
ReadUpTo: time.UnixMicro(receipt.ReadTimeMicros),
})
}
}
case proto.Event_GROUP_UPDATED:
c.handleGroupUpdated(ctx, evt)
Expand Down
13 changes: 12 additions & 1 deletion pkg/connector/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@ type UserLoginMetadata struct {
var _ bridgev2.LoginProcessCookies = (*GChatCookieLogin)(nil)

func (gl *GChatCookieLogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
fields := make([]bridgev2.LoginCookieField, 5)
for i, key := range gchatmeow.CookieNames {
fields[i] = bridgev2.LoginCookieField{
ID: key,
Required: true,
Sources: []bridgev2.LoginCookieFieldSource{
{Type: bridgev2.LoginCookieTypeCookie, Name: key},
},
}
}
step := &bridgev2.LoginStep{
Type: bridgev2.LoginStepTypeCookies,
StepID: LoginStepIDCookies,
Instructions: "Enter a JSON object with your cookies, or a cURL command copied from browser devtools.",
CookiesParams: &bridgev2.LoginCookiesParams{
URL: "https://chat.google.com/",
URL: "https://chat.google.com/",
Fields: fields,
},
}
return step, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/gchatmeow/cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type Cookies struct {
}

var (
cookies = []string{"COMPASS", "SSID", "SID", "OSID", "HSID"}
CookieNames = []string{"COMPASS", "SSID", "SID", "OSID", "HSID"}
)

func (c *Cookies) UpdateValues(values map[string]string) {
r := reflect.ValueOf(c)
for _, key := range cookies {
for _, key := range CookieNames {
field := reflect.Indirect(r).FieldByName(key)
field.SetString(values[key])
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/msgconv/from-gchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (mc *MessageConverter) ToMatrix(ctx context.Context, portal *bridgev2.Porta
}
}

// cm.MergeCaption()
cm.MergeCaption()

return cm, nil
}
Expand Down

0 comments on commit 98b720e

Please sign in to comment.