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:
parent
072c002198
commit
89b9f46301
3 changed files with 2 additions and 22 deletions
|
@ -33,7 +33,6 @@ 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)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
14
puppet.go
14
puppet.go
|
@ -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()
|
||||||
|
|
1
user.go
1
user.go
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue