Browse Source

Added support for last_message_id

pull/371/head
ObsidianMinor 8 years ago
parent
commit
26ba1a6092
11 changed files with 19 additions and 0 deletions
  1. +1
    -0
      src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs
  2. +2
    -0
      src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
  3. +3
    -0
      src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
  4. +2
    -0
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  5. +1
    -0
      src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs
  6. +1
    -0
      src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs
  7. +1
    -0
      src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs
  8. +1
    -0
      src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs
  9. +2
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  10. +3
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  11. +2
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

+ 1
- 0
src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs View File

@@ -14,6 +14,7 @@ namespace Discord
/// <summary> Sends a file to this text channel, with an optional caption. </summary> /// <summary> Sends a file to this text channel, with an optional caption. </summary>
Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null); Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null);


ulong? LastMessageId { get; }
/// <summary> Gets a message from this message channel with the given id, or null if not found. </summary> /// <summary> Gets a message from this message channel with the given id, or null if not found. </summary>
Task<IMessage> GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task<IMessage> GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the last N messages from this message channel. </summary> /// <summary> Gets the last N messages from this message channel. </summary>


+ 2
- 0
src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs View File

@@ -14,6 +14,7 @@ namespace Discord.Rest
{ {
public RestUser CurrentUser { get; private set; } public RestUser CurrentUser { get; private set; }
public RestUser Recipient { get; private set; } public RestUser Recipient { get; private set; }
public ulong? LastMessageId { get; private set; }


public IReadOnlyCollection<RestUser> Users => ImmutableArray.Create(CurrentUser, Recipient); public IReadOnlyCollection<RestUser> Users => ImmutableArray.Create(CurrentUser, Recipient);


@@ -32,6 +33,7 @@ namespace Discord.Rest
internal override void Update(Model model) internal override void Update(Model model)
{ {
Recipient.Update(model.Recipients.Value[0]); Recipient.Update(model.Recipients.Value[0]);
LastMessageId = model.LastMessageId;
} }


public override async Task UpdateAsync(RequestOptions options = null) public override async Task UpdateAsync(RequestOptions options = null)


+ 3
- 0
src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs View File

@@ -16,6 +16,7 @@ namespace Discord.Rest
private ImmutableDictionary<ulong, RestGroupUser> _users; private ImmutableDictionary<ulong, RestGroupUser> _users;


public string Name { get; private set; } public string Name { get; private set; }
public ulong? LastMessageId { get; private set; }


public IReadOnlyCollection<RestGroupUser> Users => _users.ToReadOnlyCollection(); public IReadOnlyCollection<RestGroupUser> Users => _users.ToReadOnlyCollection();
public IReadOnlyCollection<RestGroupUser> Recipients public IReadOnlyCollection<RestGroupUser> Recipients
@@ -40,6 +41,8 @@ namespace Discord.Rest


if (model.Recipients.IsSpecified) if (model.Recipients.IsSpecified)
UpdateUsers(model.Recipients.Value); UpdateUsers(model.Recipients.Value);

LastMessageId = model.LastMessageId;
} }
internal void UpdateUsers(API.User[] models) internal void UpdateUsers(API.User[] models)
{ {


+ 2
- 0
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -13,6 +13,7 @@ namespace Discord.Rest
public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel
{ {
public string Topic { get; private set; } public string Topic { get; private set; }
public ulong? LastMessageId { get; private set; }


public string Mention => MentionUtils.MentionChannel(Id); public string Mention => MentionUtils.MentionChannel(Id);


@@ -31,6 +32,7 @@ namespace Discord.Rest
base.Update(model); base.Update(model);


Topic = model.Topic.Value; Topic = model.Topic.Value;
LastMessageId = model.LastMessageId;
} }


public async Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null) public async Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null)


+ 1
- 0
src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs View File

@@ -12,6 +12,7 @@ namespace Discord.Rest
{ {
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id); public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
public string Mention => MentionUtils.MentionChannel(Id); public string Mention => MentionUtils.MentionChannel(Id);
public ulong? LastMessageId { get; private set; }


internal RestVirtualMessageChannel(BaseDiscordClient discord, ulong id) internal RestVirtualMessageChannel(BaseDiscordClient discord, ulong id)
: base(discord, id) : base(discord, id)


+ 1
- 0
src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs View File

@@ -12,6 +12,7 @@ namespace Discord.Rpc
public class RpcDMChannel : RpcChannel, IRpcMessageChannel, IRpcPrivateChannel, IDMChannel public class RpcDMChannel : RpcChannel, IRpcMessageChannel, IRpcPrivateChannel, IDMChannel
{ {
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; }
public ulong? LastMessageId { get { throw new NotSupportedException(); } }


internal RpcDMChannel(DiscordRpcClient discord, ulong id) internal RpcDMChannel(DiscordRpcClient discord, ulong id)
: base(discord, id) : base(discord, id)


+ 1
- 0
src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs View File

@@ -13,6 +13,7 @@ namespace Discord.Rpc
{ {
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; }
public IReadOnlyCollection<RpcVoiceState> VoiceStates { get; private set; } public IReadOnlyCollection<RpcVoiceState> VoiceStates { get; private set; }
public ulong? LastMessageId { get { throw new NotSupportedException(); } }


internal RpcGroupChannel(DiscordRpcClient discord, ulong id) internal RpcGroupChannel(DiscordRpcClient discord, ulong id)
: base(discord, id) : base(discord, id)


+ 1
- 0
src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs View File

@@ -15,6 +15,7 @@ namespace Discord.Rpc
public class RpcTextChannel : RpcGuildChannel, IRpcMessageChannel, ITextChannel public class RpcTextChannel : RpcGuildChannel, IRpcMessageChannel, ITextChannel
{ {
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; }
public ulong? LastMessageId { get { throw new NotSupportedException(); } }


public string Mention => MentionUtils.MentionChannel(Id); public string Mention => MentionUtils.MentionChannel(Id);




+ 2
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs View File

@@ -16,6 +16,7 @@ namespace Discord.WebSocket
private readonly MessageCache _messages; private readonly MessageCache _messages;


public SocketUser Recipient { get; private set; } public SocketUser Recipient { get; private set; }
public ulong? LastMessageId { get; private set; }


public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>(); public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>();
public new IReadOnlyCollection<SocketUser> Users => ImmutableArray.Create(Discord.CurrentUser, Recipient); public new IReadOnlyCollection<SocketUser> Users => ImmutableArray.Create(Discord.CurrentUser, Recipient);
@@ -36,6 +37,7 @@ namespace Discord.WebSocket
internal override void Update(ClientState state, Model model) internal override void Update(ClientState state, Model model)
{ {
Recipient.Update(state, model.Recipients.Value[0]); Recipient.Update(state, model.Recipients.Value[0]);
LastMessageId = model.LastMessageId;
} }


public Task CloseAsync(RequestOptions options = null) public Task CloseAsync(RequestOptions options = null)


+ 3
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

@@ -23,6 +23,7 @@ namespace Discord.WebSocket
private ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates; private ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates;


public string Name { get; private set; } public string Name { get; private set; }
public ulong? LastMessageId { get; private set; }


public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>(); public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>();
public new IReadOnlyCollection<SocketGroupUser> Users => _users.ToReadOnlyCollection(); public new IReadOnlyCollection<SocketGroupUser> Users => _users.ToReadOnlyCollection();
@@ -52,6 +53,8 @@ namespace Discord.WebSocket


if (model.Recipients.IsSpecified) if (model.Recipients.IsSpecified)
UpdateUsers(state, model.Recipients.Value); UpdateUsers(state, model.Recipients.Value);

LastMessageId = model.LastMessageId;
} }
private void UpdateUsers(ClientState state, UserModel[] models) private void UpdateUsers(ClientState state, UserModel[] models)
{ {


+ 2
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -17,6 +17,7 @@ namespace Discord.WebSocket
private readonly MessageCache _messages; private readonly MessageCache _messages;


public string Topic { get; private set; } public string Topic { get; private set; }
public ulong? LastMessageId { get; private set; }


public string Mention => MentionUtils.MentionChannel(Id); public string Mention => MentionUtils.MentionChannel(Id);
public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>(); public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>();
@@ -42,6 +43,7 @@ namespace Discord.WebSocket
base.Update(state, model); base.Update(state, model);


Topic = model.Topic.Value; Topic = model.Topic.Value;
LastMessageId = model.LastMessageId;
} }


public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null) public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null)


Loading…
Cancel
Save