Don't clear puppets when phone ID changes

Otherwise the avatars will remain on the server and won't be properly reset
when new contact info comes in for the same user.
This commit is contained in:
Tulir Asokan 2024-03-01 14:42:40 +02:00
parent 072c002198
commit 89b9f46301
3 changed files with 2 additions and 22 deletions

View file

@ -33,9 +33,8 @@ func newPuppet(qh *dbutil.QueryHelper[*Puppet]) *Puppet {
} }
const ( const (
deleteAllPuppetsForUserQuery = "DELETE FROM puppet WHERE receiver=$1" getPuppetQuery = "SELECT id, receiver, phone, contact_id, name, name_set, avatar_hash, avatar_mxc, avatar_set, avatar_update_ts, contact_info_set FROM puppet WHERE id=$1 AND receiver=$2"
getPuppetQuery = "SELECT id, receiver, phone, contact_id, name, name_set, avatar_hash, avatar_mxc, avatar_set, avatar_update_ts, contact_info_set FROM puppet WHERE id=$1 AND receiver=$2" insertPuppetQuery = `
insertPuppetQuery = `
INSERT INTO puppet (id, receiver, phone, contact_id, name, name_set, avatar_hash, avatar_mxc, avatar_set, avatar_update_ts, contact_info_set) INSERT INTO puppet (id, receiver, phone, contact_id, name, name_set, avatar_hash, avatar_mxc, avatar_set, avatar_update_ts, contact_info_set)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
` `
@ -46,10 +45,6 @@ const (
` `
) )
func (pq *PuppetQuery) DeleteAllForUser(ctx context.Context, userID int) error {
return pq.Exec(ctx, deleteAllPuppetsForUserQuery, userID)
}
func (pq *PuppetQuery) Get(ctx context.Context, key Key) (*Puppet, error) { func (pq *PuppetQuery) Get(ctx context.Context, key Key) (*Puppet, error) {
return pq.QueryOne(ctx, getPuppetQuery, key.ID, key.Receiver) return pq.QueryOne(ctx, getPuppetQuery, key.ID, key.Receiver)
} }

View file

@ -60,20 +60,6 @@ func (br *GMBridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
return br.GetPuppetByKey(key, "") return br.GetPuppetByKey(key, "")
} }
func (br *GMBridge) DeleteAllPuppetsForUser(userID int) {
br.puppetsLock.Lock()
defer br.puppetsLock.Unlock()
err := br.DB.Puppet.DeleteAllForUser(context.Background(), userID)
if err != nil {
br.ZLog.Err(err).Msg("Failed to delete all ghosts for user from database")
}
for key, puppet := range br.puppetsByKey {
if puppet.Receiver == userID {
delete(br.puppetsByKey, key)
}
}
}
func (br *GMBridge) GetPuppetByKey(key database.Key, phone string) *Puppet { func (br *GMBridge) GetPuppetByKey(key database.Key, phone string) *Puppet {
br.puppetsLock.Lock() br.puppetsLock.Lock()
defer br.puppetsLock.Unlock() defer br.puppetsLock.Unlock()

View file

@ -783,7 +783,6 @@ func (user *User) ResetState() {
for _, portal := range portals { for _, portal := range portals {
portal.Delete(context.TODO()) portal.Delete(context.TODO())
} }
user.bridge.DeleteAllPuppetsForUser(user.RowID)
user.PhoneID = "" user.PhoneID = ""
go func() { go func() {
user.zlog.Debug().Msg("Cleaning up portal rooms in background") user.zlog.Debug().Msg("Cleaning up portal rooms in background")