Browse Source

Fixed EditProfile not caching changes

tags/docs-0.9
RogueException 9 years ago
parent
commit
d9bfc5fef4
4 changed files with 18 additions and 14 deletions
  1. +3
    -3
      src/Discord.Net/API/Messages/Users.cs
  2. +9
    -7
      src/Discord.Net/DiscordAPIClient.cs
  3. +1
    -1
      src/Discord.Net/DiscordClient.Users.cs
  4. +5
    -3
      src/Discord.Net/DiscordClient.cs

+ 3
- 3
src/Discord.Net/API/Messages/Users.cs View File

@@ -33,13 +33,13 @@ namespace Discord.API
{
[JsonProperty("password")]
public string CurrentPassword;
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("email")]
public string Email;
[JsonProperty("new_password")]
public string Password;
[JsonProperty("username", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("username")]
public string Username;
[JsonProperty("avatar", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("avatar")]
public string Avatar;
}
public sealed class EditUserResponse : UserInfo { }


+ 9
- 7
src/Discord.Net/DiscordAPIClient.cs View File

@@ -303,22 +303,24 @@ namespace Discord

return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId));
}
public Task<EditServerResponse> EditServer(long serverId, string name = null, string region = null, Stream icon = null, ImageType iconType = ImageType.Png)
public Task<EditServerResponse> EditServer(long serverId, string name = null, string region = null,
Stream icon = null, ImageType iconType = ImageType.Png, string existingIcon = null)
{
if (serverId <= 0) throw new ArgumentOutOfRangeException(nameof(serverId));

var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(icon, iconType) };
var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(icon, iconType, existingIcon) };
return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request);
}

//User
public Task<EditUserResponse> EditProfile(string currentPassword = "",
string username = null, string email = null, string password = null,
Stream avatar = null, ImageType avatarType = ImageType.Png)
Stream avatar = null, ImageType avatarType = ImageType.Png, string existingAvatar = null)
{
if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword));
var request = new EditUserRequest { CurrentPassword = currentPassword, Username = username, Email = email, Password = password, Avatar = Base64Picture(avatar, avatarType) };
var request = new EditUserRequest { CurrentPassword = currentPassword, Username = username,
Email = email, Password = password, Avatar = Base64Picture(avatar, avatarType, existingAvatar) };
return _rest.Patch<EditUserResponse>(Endpoints.UserMe, request);
}

@@ -326,10 +328,10 @@ namespace Discord
public Task<GetRegionsResponse> GetVoiceRegions()
=> _rest.Get<GetRegionsResponse>(Endpoints.VoiceRegions);

private string Base64Picture(Stream stream, ImageType type)
private string Base64Picture(Stream stream, ImageType type, string existingId)
{
if (type == ImageType.None)
return "";
return null;
else if (stream != null)
{
byte[] bytes = new byte[stream.Length - stream.Position];
@@ -339,7 +341,7 @@ namespace Discord
string imageType = type == ImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64";
return $"data:{imageType},{base64}";
}
return null;
return existingId;
}
}
}

+ 1
- 1
src/Discord.Net/DiscordClient.Users.cs View File

@@ -275,7 +275,7 @@ namespace Discord

await _api.EditProfile(currentPassword: currentPassword,
username: username ?? _privateUser?.Name, email: email ?? _privateUser?.Global.Email, password: password,
avatar: avatar, avatarType: avatarType);
avatar: avatar, avatarType: avatarType, existingAvatar: _privateUser?.AvatarId);

if (password != null)
{


+ 5
- 3
src/Discord.Net/DiscordClient.cs View File

@@ -814,10 +814,12 @@ namespace Discord
case "USER_UPDATE":
{
var data = e.Payload.ToObject<UserUpdateEvent>(_webSocket.Serializer);
var user = _globalUsers[data.Id];
if (user != null)
var globalUser = _globalUsers[data.Id];
if (globalUser != null)
{
user.Update(data);
globalUser.Update(data);
foreach (var user in globalUser.Memberships)
user.Update(data);
RaiseProfileUpdated();
}
}


Loading…
Cancel
Save