mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-14 05:12:26 +03:00
mas: handle 3pids from mas
This commit is contained in:
parent
5cffc2c257
commit
811a504e01
5 changed files with 91 additions and 19 deletions
|
@ -353,6 +353,41 @@ func (d *Database) SaveThreePIDAssociation(
|
|||
})
|
||||
}
|
||||
|
||||
// BulkSaveThreePIDAssociation recreates 3PIDs for a user.
|
||||
// If the third-party identifier is already part of an association, returns Err3PIDInUse.
|
||||
// Returns an error if there was a problem talking to the database.
|
||||
func (d *Database) BulkSaveThreePIDAssociation(ctx context.Context, threePIDs []authtypes.ThreePID, localpart string, serverName spec.ServerName) (err error) {
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
oldThreePIDs, err := d.ThreePIDs.SelectThreePIDsForLocalpart(ctx, localpart, serverName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, t := range oldThreePIDs {
|
||||
if err := d.ThreePIDs.DeleteThreePID(ctx, txn, t.Address, t.Medium); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, t := range threePIDs {
|
||||
// if 3PID is associated with another user, return Err3PIDInUse
|
||||
user, _, err := d.ThreePIDs.SelectLocalpartForThreePID(
|
||||
ctx, txn, t.Address, t.Medium,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(user) > 0 && user != localpart {
|
||||
return Err3PIDInUse
|
||||
}
|
||||
|
||||
if err = d.ThreePIDs.InsertThreePID(ctx, txn, t.Address, t.Medium, localpart, serverName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// RemoveThreePIDAssociation removes the association involving a given third-party
|
||||
// identifier.
|
||||
// If no association exists involving this third-party identifier, returns nothing.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue