Browse Source

Cleaned up nickname editing

pull/58/head
Voltana 9 years ago
parent
commit
de2068140d
3 changed files with 20 additions and 18 deletions
  1. +3
    -1
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +0
    -0
      src/Discord.Net/API/Client/Rest/UpdateOwnNick.cs
  3. +17
    -17
      src/Discord.Net/Models/User.cs

+ 3
- 1
src/Discord.Net.Net45/Discord.Net.csproj View File

@@ -337,6 +337,9 @@
<Compile Include="..\Discord.Net\API\Client\Rest\UpdateMessage.cs">
<Link>API\Client\Rest\UpdateMessage.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\UpdateOwnNick.cs">
<Link>API\Client\Rest\UpdateOwnNick.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\UpdateProfile.cs">
<Link>API\Client\Rest\UpdateProfile.cs</Link>
</Compile>
@@ -601,7 +604,6 @@
<Compile Include="..\Discord.Net\TaskManager.cs">
<Link>TaskManager.cs</Link>
</Compile>
<Compile Include="API\Client\Rest\UpdateOwnNick.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>


src/Discord.Net.Net45/API/Client/Rest/UpdateOwnNick.cs → src/Discord.Net/API/Client/Rest/UpdateOwnNick.cs View File


+ 17
- 17
src/Discord.Net/Models/User.cs View File

@@ -247,7 +247,7 @@ namespace Discord
LastActivityAt = activity ?? DateTime.UtcNow;
}

public Task Edit(bool? isMuted = null, bool? isDeafened = null, Channel voiceChannel = null, IEnumerable<Role> roles = null, string nickname = null)
public async Task Edit(bool? isMuted = null, bool? isDeafened = null, Channel voiceChannel = null, IEnumerable<Role> roles = null, string nickname = "")
{
if (Server == null) throw new InvalidOperationException("Unable to edit users in a private channel");

@@ -258,25 +258,25 @@ namespace Discord
.Distinct()
.ToArray();

var tasks = new List<Task>();
if (nickname != null && this == Server.CurrentUser)
bool isCurrentUser = Id == Server.CurrentUser.Id;
if (isCurrentUser && nickname != "")
{
var task = Client.ClientAPI.Send(new UpdateOwnNick(Server.Id, nickname));
if (isMuted == null && isDeafened == null && voiceChannel == null && roles == null)
return task;
tasks.Add(task);
nickname = null;
var request = new UpdateOwnNick(Server.Id, nickname);
await Client.ClientAPI.Send(request).ConfigureAwait(false);
nickname = "";
}
var request = new UpdateMemberRequest(Server.Id, Id)
if (!isCurrentUser || isMuted != null || isDeafened != null | voiceChannel != null || roles != null)
{
IsMuted = isMuted ?? IsServerMuted,
IsDeafened = isDeafened ?? IsServerDeafened,
VoiceChannelId = voiceChannel?.Id,
RoleIds = roleIds,
Nickname = nickname ?? Nickname
};
tasks.Add(Client.ClientAPI.Send(request));
return Task.WhenAll(tasks);
var request = new UpdateMemberRequest(Server.Id, Id)
{
IsMuted = isMuted ?? IsServerMuted,
IsDeafened = isDeafened ?? IsServerDeafened,
VoiceChannelId = voiceChannel?.Id,
RoleIds = roleIds,
Nickname = nickname ?? Nickname
};
await Client.ClientAPI.Send(request).ConfigureAwait(false);
}
}
public Task Kick()


Loading…
Cancel
Save