feature: support reading multiple activities (#1520)
This commit is contained in:
@@ -19,5 +19,9 @@ namespace Discord
|
|||||||
/// Gets the set of clients where this user is currently active.
|
/// Gets the set of clients where this user is currently active.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IImmutableSet<ClientType> ActiveClients { get; }
|
IImmutableSet<ClientType> ActiveClients { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of activities that this user currently has available.
|
||||||
|
/// </summary>
|
||||||
|
IImmutableList<IActivity> Activities { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Discord.API
|
namespace Discord.API
|
||||||
@@ -26,5 +27,9 @@ namespace Discord.API
|
|||||||
// "client_status": { "desktop": "dnd", "mobile": "dnd" }
|
// "client_status": { "desktop": "dnd", "mobile": "dnd" }
|
||||||
[JsonProperty("client_status")]
|
[JsonProperty("client_status")]
|
||||||
public Optional<Dictionary<string, string>> ClientStatus { get; set; }
|
public Optional<Dictionary<string, string>> ClientStatus { get; set; }
|
||||||
|
[JsonProperty("activities")]
|
||||||
|
public List<Game> Activities { get; set; }
|
||||||
|
[JsonProperty("premium_since")]
|
||||||
|
public Optional<DateTimeOffset?> PremiumSince { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual IImmutableSet<ClientType> ActiveClients => ImmutableHashSet<ClientType>.Empty;
|
public virtual IImmutableSet<ClientType> ActiveClients => ImmutableHashSet<ClientType>.Empty;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
public virtual IImmutableList<IActivity> Activities => ImmutableList<IActivity>.Empty;
|
||||||
|
/// <inheritdoc />
|
||||||
public virtual bool IsWebhook => false;
|
public virtual bool IsWebhook => false;
|
||||||
|
|
||||||
internal RestUser(BaseDiscordClient discord, ulong id)
|
internal RestUser(BaseDiscordClient discord, ulong id)
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
var user = SocketGlobalUser.Create(this, state, model);
|
var user = SocketGlobalUser.Create(this, state, model);
|
||||||
user.GlobalUser.AddRef();
|
user.GlobalUser.AddRef();
|
||||||
user.Presence = new SocketPresence(UserStatus.Online, null, null);
|
user.Presence = new SocketPresence(UserStatus.Online, null, null, null);
|
||||||
return user;
|
return user;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -450,7 +450,7 @@ namespace Discord.WebSocket
|
|||||||
return;
|
return;
|
||||||
var status = Status;
|
var status = Status;
|
||||||
var statusSince = _statusSince;
|
var statusSince = _statusSince;
|
||||||
CurrentUser.Presence = new SocketPresence(status, Activity, null);
|
CurrentUser.Presence = new SocketPresence(status, Activity, null, null);
|
||||||
|
|
||||||
var gameModel = new GameModel();
|
var gameModel = new GameModel();
|
||||||
// Discord only accepts rich presence over RPC, don't even bother building a payload
|
// Discord only accepts rich presence over RPC, don't even bother building a payload
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ namespace Discord.WebSocket
|
|||||||
Nickname = model.Nick.Value;
|
Nickname = model.Nick.Value;
|
||||||
if (model.Roles.IsSpecified)
|
if (model.Roles.IsSpecified)
|
||||||
UpdateRoles(model.Roles.Value);
|
UpdateRoles(model.Roles.Value);
|
||||||
|
if (model.PremiumSince.IsSpecified)
|
||||||
|
_premiumSinceTicks = model.PremiumSince.Value?.UtcTicks;
|
||||||
}
|
}
|
||||||
private void UpdateRoles(ulong[] roleIds)
|
private void UpdateRoles(ulong[] roleIds)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,16 +18,20 @@ namespace Discord.WebSocket
|
|||||||
public IActivity Activity { get; }
|
public IActivity Activity { get; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IImmutableSet<ClientType> ActiveClients { get; }
|
public IImmutableSet<ClientType> ActiveClients { get; }
|
||||||
internal SocketPresence(UserStatus status, IActivity activity, IImmutableSet<ClientType> activeClients)
|
/// <inheritdoc />
|
||||||
|
public IImmutableList<IActivity> Activities { get; }
|
||||||
|
internal SocketPresence(UserStatus status, IActivity activity, IImmutableSet<ClientType> activeClients, IImmutableList<IActivity> activities)
|
||||||
{
|
{
|
||||||
Status = status;
|
Status = status;
|
||||||
Activity = activity;
|
Activity = activity;
|
||||||
ActiveClients = activeClients;
|
ActiveClients = activeClients ?? ImmutableHashSet<ClientType>.Empty;
|
||||||
|
Activities = activities ?? ImmutableList<IActivity>.Empty;
|
||||||
}
|
}
|
||||||
internal static SocketPresence Create(Model model)
|
internal static SocketPresence Create(Model model)
|
||||||
{
|
{
|
||||||
var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault());
|
var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault());
|
||||||
return new SocketPresence(model.Status, model.Game?.ToEntity(), clients);
|
var activities = ConvertActivitiesList(model.Activities);
|
||||||
|
return new SocketPresence(model.Status, model.Game?.ToEntity(), clients, activities);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="IReadOnlyCollection{T}"/> containing all of the client types
|
/// Creates a new <see cref="IReadOnlyCollection{T}"/> containing all of the client types
|
||||||
@@ -53,6 +57,25 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
return set.ToImmutableHashSet();
|
return set.ToImmutableHashSet();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="IReadOnlyCollection{T}"/> containing all the activities
|
||||||
|
/// that a user has from the data supplied in the Presence update frame.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="activities">
|
||||||
|
/// A list of <see cref="API.Game"/>.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// A list of all <see cref="IActivity"/> that this user currently has available.
|
||||||
|
/// </returns>
|
||||||
|
private static IImmutableList<IActivity> ConvertActivitiesList(IList<API.Game> activities)
|
||||||
|
{
|
||||||
|
if (activities == null || activities.Count == 0)
|
||||||
|
return ImmutableList<IActivity>.Empty;
|
||||||
|
var list = new List<IActivity>();
|
||||||
|
foreach (var activity in activities)
|
||||||
|
list.Add(activity.ToEntity());
|
||||||
|
return list.ToImmutableList();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the status of the user.
|
/// Gets the status of the user.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool IsWebhook => false;
|
public override bool IsWebhook => false;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null); } set { } }
|
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <exception cref="NotSupportedException">This field is not supported for an unknown user.</exception>
|
/// <exception cref="NotSupportedException">This field is not supported for an unknown user.</exception>
|
||||||
internal override SocketGlobalUser GlobalUser =>
|
internal override SocketGlobalUser GlobalUser =>
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ namespace Discord.WebSocket
|
|||||||
public UserStatus Status => Presence.Status;
|
public UserStatus Status => Presence.Status;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IImmutableSet<ClientType> ActiveClients => Presence.ActiveClients ?? ImmutableHashSet<ClientType>.Empty;
|
public IImmutableSet<ClientType> ActiveClients => Presence.ActiveClients ?? ImmutableHashSet<ClientType>.Empty;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IImmutableList<IActivity> Activities => Presence.Activities ?? ImmutableList<IActivity>.Empty;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets mutual guilds shared with this user.
|
/// Gets mutual guilds shared with this user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool IsWebhook => true;
|
public override bool IsWebhook => true;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null); } set { } }
|
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } }
|
||||||
internal override SocketGlobalUser GlobalUser =>
|
internal override SocketGlobalUser GlobalUser =>
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user