mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
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.
This commit is contained in:
parent
40cfb9a4ea
commit
e57b301722
14 changed files with 191 additions and 132 deletions
|
@ -382,15 +382,23 @@ func Test_Profile(t *testing.T) {
|
|||
|
||||
// set avatar & displayname
|
||||
wantProfile.DisplayName = "Alice"
|
||||
wantProfile.AvatarURL = "mxc://aliceAvatar"
|
||||
err = db.SetDisplayName(ctx, aliceLocalpart, "Alice")
|
||||
assert.NoError(t, err, "unable to set displayname")
|
||||
err = db.SetAvatarURL(ctx, aliceLocalpart, "mxc://aliceAvatar")
|
||||
assert.NoError(t, err, "unable to set avatar url")
|
||||
// verify profile
|
||||
gotProfile, err = db.GetProfileByLocalpart(ctx, aliceLocalpart)
|
||||
assert.NoError(t, err, "unable to get profile by localpart")
|
||||
gotProfile, changed, err := db.SetDisplayName(ctx, aliceLocalpart, "Alice")
|
||||
assert.Equal(t, wantProfile, gotProfile)
|
||||
assert.NoError(t, err, "unable to set displayname")
|
||||
assert.True(t, changed)
|
||||
|
||||
wantProfile.AvatarURL = "mxc://aliceAvatar"
|
||||
gotProfile, changed, err = db.SetAvatarURL(ctx, aliceLocalpart, "mxc://aliceAvatar")
|
||||
assert.NoError(t, err, "unable to set avatar url")
|
||||
assert.Equal(t, wantProfile, gotProfile)
|
||||
assert.True(t, changed)
|
||||
|
||||
// Setting the same avatar again doesn't change anything
|
||||
wantProfile.AvatarURL = "mxc://aliceAvatar"
|
||||
gotProfile, changed, err = db.SetAvatarURL(ctx, aliceLocalpart, "mxc://aliceAvatar")
|
||||
assert.NoError(t, err, "unable to set avatar url")
|
||||
assert.Equal(t, wantProfile, gotProfile)
|
||||
assert.False(t, changed)
|
||||
|
||||
// search profiles
|
||||
searchRes, err := db.SearchProfiles(ctx, "Alice", 2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue