Fixed EditProfile not caching changes
This commit is contained in:
@@ -33,13 +33,13 @@ namespace Discord.API
|
|||||||
{
|
{
|
||||||
[JsonProperty("password")]
|
[JsonProperty("password")]
|
||||||
public string CurrentPassword;
|
public string CurrentPassword;
|
||||||
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("email")]
|
||||||
public string Email;
|
public string Email;
|
||||||
[JsonProperty("new_password")]
|
[JsonProperty("new_password")]
|
||||||
public string Password;
|
public string Password;
|
||||||
[JsonProperty("username", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("username")]
|
||||||
public string Username;
|
public string Username;
|
||||||
[JsonProperty("avatar", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("avatar")]
|
||||||
public string Avatar;
|
public string Avatar;
|
||||||
}
|
}
|
||||||
public sealed class EditUserResponse : UserInfo { }
|
public sealed class EditUserResponse : UserInfo { }
|
||||||
|
|||||||
@@ -303,22 +303,24 @@ namespace Discord
|
|||||||
|
|
||||||
return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId));
|
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));
|
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);
|
return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
//User
|
//User
|
||||||
public Task<EditUserResponse> EditProfile(string currentPassword = "",
|
public Task<EditUserResponse> EditProfile(string currentPassword = "",
|
||||||
string username = null, string email = null, string password = null,
|
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));
|
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);
|
return _rest.Patch<EditUserResponse>(Endpoints.UserMe, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,10 +328,10 @@ namespace Discord
|
|||||||
public Task<GetRegionsResponse> GetVoiceRegions()
|
public Task<GetRegionsResponse> GetVoiceRegions()
|
||||||
=> _rest.Get<GetRegionsResponse>(Endpoints.VoiceRegions);
|
=> _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)
|
if (type == ImageType.None)
|
||||||
return "";
|
return null;
|
||||||
else if (stream != null)
|
else if (stream != null)
|
||||||
{
|
{
|
||||||
byte[] bytes = new byte[stream.Length - stream.Position];
|
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";
|
string imageType = type == ImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64";
|
||||||
return $"data:{imageType},{base64}";
|
return $"data:{imageType},{base64}";
|
||||||
}
|
}
|
||||||
return null;
|
return existingId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ namespace Discord
|
|||||||
|
|
||||||
await _api.EditProfile(currentPassword: currentPassword,
|
await _api.EditProfile(currentPassword: currentPassword,
|
||||||
username: username ?? _privateUser?.Name, email: email ?? _privateUser?.Global.Email, password: password,
|
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)
|
if (password != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -814,10 +814,12 @@ namespace Discord
|
|||||||
case "USER_UPDATE":
|
case "USER_UPDATE":
|
||||||
{
|
{
|
||||||
var data = e.Payload.ToObject<UserUpdateEvent>(_webSocket.Serializer);
|
var data = e.Payload.ToObject<UserUpdateEvent>(_webSocket.Serializer);
|
||||||
var user = _globalUsers[data.Id];
|
var globalUser = _globalUsers[data.Id];
|
||||||
if (user != null)
|
if (globalUser != null)
|
||||||
{
|
{
|
||||||
user.Update(data);
|
globalUser.Update(data);
|
||||||
|
foreach (var user in globalUser.Memberships)
|
||||||
|
user.Update(data);
|
||||||
RaiseProfileUpdated();
|
RaiseProfileUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user