Fix some bugs
This commit is contained in:
parent
63284481d7
commit
2b37a6d718
6 changed files with 21 additions and 11 deletions
|
@ -40,6 +40,7 @@ func (user *User) SwitchCustomMXID(accessToken string, mxid id.UserID) error {
|
|||
if mxid != user.MXID {
|
||||
return errors.New("mismatching mxid")
|
||||
}
|
||||
user.DoublePuppetIntent = nil
|
||||
user.AccessToken = accessToken
|
||||
return user.startCustomMXID(false)
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ func (user *User) clearCustomMXID() {
|
|||
}
|
||||
|
||||
func (user *User) startCustomMXID(reloginOnFail bool) error {
|
||||
if len(user.AccessToken) == 0 {
|
||||
if len(user.AccessToken) == 0 || user.DoublePuppetIntent != nil {
|
||||
return nil
|
||||
}
|
||||
intent, err := user.newDoublePuppetIntent()
|
||||
|
|
|
@ -74,20 +74,20 @@ type Message struct {
|
|||
|
||||
func (msg *Message) Scan(row dbutil.Scannable) (*Message, error) {
|
||||
var ts int64
|
||||
err := row.Scan(&msg.Chat.ID, &msg.Chat.Receiver, &msg.ID, &msg.MXID, &msg.Sender, &msg.Timestamp)
|
||||
err := row.Scan(&msg.Chat.ID, &msg.Chat.Receiver, &msg.ID, &msg.MXID, &msg.Sender, &ts)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ts != 0 {
|
||||
msg.Timestamp = time.UnixMilli(ts)
|
||||
msg.Timestamp = time.UnixMicro(ts)
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (msg *Message) sqlVariables() []any {
|
||||
return []any{msg.Chat.ID, msg.Chat.Receiver, msg.ID, msg.MXID, msg.Sender, msg.Timestamp.UnixMilli()}
|
||||
return []any{msg.Chat.ID, msg.Chat.Receiver, msg.ID, msg.MXID, msg.Sender, msg.Timestamp.UnixMicro()}
|
||||
}
|
||||
|
||||
func (msg *Message) Insert(ctx context.Context) error {
|
||||
|
|
|
@ -112,7 +112,7 @@ func (portal *Portal) sqlVariables() []any {
|
|||
if portal.OtherUserID != "" {
|
||||
otherUserID = &portal.OtherUserID
|
||||
}
|
||||
return []any{portal.ID, portal.Receiver, selfUserID, otherUserID, mxid, portal.Name, portal.NameSet, portal.AvatarID, portal.AvatarMXC, portal.AvatarSet, portal.Encrypted, portal.InSpace}
|
||||
return []any{portal.ID, portal.Receiver, selfUserID, otherUserID, mxid, portal.Name, portal.NameSet, portal.AvatarID, &portal.AvatarMXC, portal.AvatarSet, portal.Encrypted, portal.InSpace}
|
||||
}
|
||||
|
||||
func (portal *Portal) Insert(ctx context.Context) error {
|
||||
|
|
|
@ -44,7 +44,7 @@ func (pq *PuppetQuery) GetAll(ctx context.Context) ([]*Puppet, error) {
|
|||
}
|
||||
|
||||
func (pq *PuppetQuery) Get(ctx context.Context, key Key) (*Puppet, error) {
|
||||
return get[*Puppet](pq, ctx, "SELECT id, receiver, phone, name, name_set, avatar_id, avatar_mxc, avatar_set, contact_info_set FROM puppet WHERE phone=$1 AND receiver=$2", key.ID, key.Receiver)
|
||||
return get[*Puppet](pq, ctx, "SELECT id, receiver, phone, name, name_set, avatar_id, avatar_mxc, avatar_set, contact_info_set FROM puppet WHERE id=$1 AND receiver=$2", key.ID, key.Receiver)
|
||||
}
|
||||
|
||||
type Puppet struct {
|
||||
|
@ -71,7 +71,7 @@ func (puppet *Puppet) Scan(row dbutil.Scannable) (*Puppet, error) {
|
|||
}
|
||||
|
||||
func (puppet *Puppet) sqlVariables() []any {
|
||||
return []any{puppet.ID, puppet.Receiver, puppet.Phone, puppet.Name, puppet.NameSet, puppet.AvatarID, puppet.AvatarMXC, puppet.AvatarSet, puppet.ContactInfoSet}
|
||||
return []any{puppet.ID, puppet.Receiver, puppet.Phone, puppet.Name, puppet.NameSet, puppet.AvatarID, &puppet.AvatarMXC, puppet.AvatarSet, puppet.ContactInfoSet}
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Insert(ctx context.Context) error {
|
||||
|
|
10
portal.go
10
portal.go
|
@ -305,6 +305,7 @@ func (portal *Portal) isOutgoingMessage(evt *binary.Message) id.EventID {
|
|||
defer portal.outgoingMessagesLock.Unlock()
|
||||
evtID, ok := portal.outgoingMessages[evt.TmpId]
|
||||
if ok {
|
||||
delete(portal.outgoingMessages, evt.TmpId)
|
||||
portal.markHandled(evt, map[string]id.EventID{"": evtID}, true)
|
||||
return evtID
|
||||
}
|
||||
|
@ -492,14 +493,17 @@ func (portal *Portal) UpdateName(name string, updateInfo bool) bool {
|
|||
|
||||
func (portal *Portal) UpdateMetadata(user *User, info *binary.Conversation) []id.UserID {
|
||||
participants := portal.SyncParticipants(user, info)
|
||||
if portal.IsPrivateChat() {
|
||||
return participants
|
||||
}
|
||||
update := false
|
||||
if portal.SelfUserID != info.SelfParticipantID {
|
||||
portal.SelfUserID = info.SelfParticipantID
|
||||
update = true
|
||||
}
|
||||
if portal.MXID != "" {
|
||||
update = portal.addToPersonalSpace(user) || update
|
||||
}
|
||||
if portal.shouldSetDMRoomMetadata() {
|
||||
update = portal.UpdateName(info.Name, false) || update
|
||||
}
|
||||
// TODO avatar
|
||||
if update {
|
||||
err := portal.Update(context.TODO())
|
||||
|
|
5
user.go
5
user.go
|
@ -438,8 +438,12 @@ func (user *User) Connect() bool {
|
|||
} else if user.Session == nil {
|
||||
return false
|
||||
}
|
||||
if len(user.AccessToken) == 0 {
|
||||
user.tryAutomaticDoublePuppeting()
|
||||
}
|
||||
user.zlog.Debug().Msg("Connecting to Google Messages")
|
||||
user.BridgeState.Send(status.BridgeState{StateEvent: status.StateConnecting, Error: WAConnecting})
|
||||
user.createClient()
|
||||
err := user.Client.Connect(user.Session.WebAuthKey)
|
||||
if err != nil {
|
||||
user.zlog.Err(err).Msg("Error connecting to Google Messages")
|
||||
|
@ -523,6 +527,7 @@ func (user *User) HandleEvent(event interface{}) {
|
|||
// These should be here
|
||||
user.zlog.Info().Msg(v.URL)
|
||||
case *events.PairSuccessful:
|
||||
user.tryAutomaticDoublePuppeting()
|
||||
user.Phone = v.PairDeviceData.Mobile.RegistrationID
|
||||
user.Session.PhoneInfo = v.PairDeviceData.Mobile
|
||||
user.Session.BrowserInfo = v.PairDeviceData.Browser
|
||||
|
|
Loading…
Reference in a new issue