aboutsummaryrefslogtreecommitdiff
path: root/userapi/storage/shared/storage.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-10-21 10:48:25 +0200
committerGitHub <noreply@github.com>2022-10-21 10:48:25 +0200
commite57b30172227c4a0b7de15ba635b20921dedda5e (patch)
treefa73a898b6a58d2250e2e7c6fd7b7f5df8b0f7f2 /userapi/storage/shared/storage.go
parent40cfb9a4ea23f1c9214553255feb296c2578b213 (diff)
Set `display_name` and/or `avatar_url` for server notices (#2820)
This should fix #2815 by making sure we actually set the `display_name` and/or `avatar_url` and create the needed membership event. To avoid creating a new membership event when starting Dendrite, `SetAvatarURL` and `SetDisplayName` now return a `Changed` value, which also makes the regular endpoints idempotent.
Diffstat (limited to 'userapi/storage/shared/storage.go')
-rw-r--r--userapi/storage/shared/storage.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/userapi/storage/shared/storage.go b/userapi/storage/shared/storage.go
index 4e28f7b5..f8b6ad31 100644
--- a/userapi/storage/shared/storage.go
+++ b/userapi/storage/shared/storage.go
@@ -96,20 +96,24 @@ func (d *Database) GetProfileByLocalpart(
// localpart. Returns an error if something went wrong with the SQL query
func (d *Database) SetAvatarURL(
ctx context.Context, localpart string, avatarURL string,
-) error {
- return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
- return d.Profiles.SetAvatarURL(ctx, txn, localpart, avatarURL)
+) (profile *authtypes.Profile, changed bool, err error) {
+ err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
+ profile, changed, err = d.Profiles.SetAvatarURL(ctx, txn, localpart, avatarURL)
+ return err
})
+ return
}
// SetDisplayName updates the display name of the profile associated with the given
// localpart. Returns an error if something went wrong with the SQL query
func (d *Database) SetDisplayName(
ctx context.Context, localpart string, displayName string,
-) error {
- return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
- return d.Profiles.SetDisplayName(ctx, txn, localpart, displayName)
+) (profile *authtypes.Profile, changed bool, err error) {
+ err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
+ profile, changed, err = d.Profiles.SetDisplayName(ctx, txn, localpart, displayName)
+ return err
})
+ return
}
// SetPassword sets the account password to the given hash.