Collapsed Discord.Models namespace, cleaned up Message cache
This commit is contained in:
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
||||
@@ -106,7 +106,7 @@ namespace Discord.API.Models
|
||||
[JsonProperty(PropertyName = "channels")]
|
||||
public ChannelInfo[] Channels;
|
||||
[JsonProperty(PropertyName = "joined_at")]
|
||||
public DateTime JoinedAt;
|
||||
public DateTime? JoinedAt;
|
||||
[JsonProperty(PropertyName = "members")]
|
||||
public MembershipInfo[] Members;
|
||||
[JsonProperty(PropertyName = "owner_id")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.Models
|
||||
namespace Discord
|
||||
{
|
||||
public sealed class Channel
|
||||
{
|
||||
@@ -1,15 +1,23 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.Models
|
||||
namespace Discord
|
||||
{
|
||||
public sealed class ChatMessage : ChatMessageReference
|
||||
public sealed class ChatMessage
|
||||
{
|
||||
private readonly DiscordClient _client;
|
||||
|
||||
public string Id { get; }
|
||||
|
||||
public bool IsMentioningEveryone { get; internal set; }
|
||||
public bool IsTTS { get; internal set; }
|
||||
public string Text { get; internal set; }
|
||||
public DateTime Timestamp { get; internal set; }
|
||||
|
||||
|
||||
public string ChannelId { get; internal set; }
|
||||
[JsonIgnore]
|
||||
public Channel Channel { get { return _client.GetChannel(ChannelId); } }
|
||||
|
||||
public string UserId { get; internal set; }
|
||||
[JsonIgnore]
|
||||
public User User { get { return _client.GetUser(UserId); } }
|
||||
@@ -19,9 +27,11 @@ namespace Discord.Models
|
||||
public object[] Embeds { get; internal set; }
|
||||
|
||||
internal ChatMessage(string id, string channelId, DiscordClient client)
|
||||
: base(id, channelId, client)
|
||||
{
|
||||
}
|
||||
Id = id;
|
||||
ChannelId = channelId;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -49,10 +49,9 @@
|
||||
<Compile Include="API\Models\ApiRequests.cs" />
|
||||
<Compile Include="API\Endpoints.cs" />
|
||||
<Compile Include="API\Models\WebSocketCommands.cs" />
|
||||
<Compile Include="Models\Role.cs" />
|
||||
<Compile Include="Models\ChatMessageReference.cs" />
|
||||
<Compile Include="Models\ChatMessage.cs" />
|
||||
<Compile Include="Models\Channel.cs" />
|
||||
<Compile Include="Role.cs" />
|
||||
<Compile Include="ChatMessage.cs" />
|
||||
<Compile Include="Channel.cs" />
|
||||
<Compile Include="DiscordWebSocket.Events.cs" />
|
||||
<Compile Include="Helpers\Http.cs" />
|
||||
<Compile Include="API\DiscordAPI.cs" />
|
||||
@@ -62,8 +61,8 @@
|
||||
<Compile Include="DiscordClient.Events.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="DiscordWebSocket.cs" />
|
||||
<Compile Include="Models\Server.cs" />
|
||||
<Compile Include="Models\User.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="User.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Discord.Models;
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
@@ -98,40 +97,35 @@ namespace Discord
|
||||
}
|
||||
|
||||
//Message
|
||||
public sealed class MessageCreateEventArgs : EventArgs
|
||||
{
|
||||
public readonly ChatMessage Message;
|
||||
internal MessageCreateEventArgs(ChatMessage msg) { Message = msg; }
|
||||
}
|
||||
public sealed class MessageEventArgs : EventArgs
|
||||
{
|
||||
public readonly ChatMessageReference Message;
|
||||
internal MessageEventArgs(ChatMessageReference msg) { Message = msg; }
|
||||
public readonly ChatMessage Message;
|
||||
internal MessageEventArgs(ChatMessage msg) { Message = msg; }
|
||||
}
|
||||
|
||||
public event EventHandler<MessageCreateEventArgs> MessageCreated;
|
||||
public event EventHandler<MessageEventArgs> MessageCreated;
|
||||
private void RaiseMessageCreated(ChatMessage msg)
|
||||
{
|
||||
if (MessageCreated != null)
|
||||
MessageCreated(this, new MessageCreateEventArgs(msg));
|
||||
MessageCreated(this, new MessageEventArgs(msg));
|
||||
}
|
||||
|
||||
public event EventHandler<MessageEventArgs> MessageDeleted;
|
||||
private void RaiseMessageDeleted(ChatMessageReference msg)
|
||||
private void RaiseMessageDeleted(ChatMessage msg)
|
||||
{
|
||||
if (MessageDeleted != null)
|
||||
MessageDeleted(this, new MessageEventArgs(msg));
|
||||
}
|
||||
|
||||
public event EventHandler<MessageEventArgs> MessageUpdated;
|
||||
private void RaiseMessageUpdated(ChatMessageReference msg)
|
||||
private void RaiseMessageUpdated(ChatMessage msg)
|
||||
{
|
||||
if (MessageUpdated != null)
|
||||
MessageUpdated(this, new MessageEventArgs(msg));
|
||||
}
|
||||
|
||||
public event EventHandler<MessageEventArgs> MessageAcknowledged;
|
||||
private void RaiseMessageAcknowledged(ChatMessageReference msg)
|
||||
private void RaiseMessageAcknowledged(ChatMessage msg)
|
||||
{
|
||||
if (MessageAcknowledged != null)
|
||||
MessageAcknowledged(this, new MessageEventArgs(msg));
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using Discord.API;
|
||||
using Discord.API.Models;
|
||||
using Discord.Helpers;
|
||||
using Discord.Models;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Role = Discord.Models.Role;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
@@ -372,7 +370,7 @@ namespace Discord
|
||||
var extendedModel = model as ExtendedServerInfo;
|
||||
server.AFKChannelId = extendedModel.AFKChannelId;
|
||||
server.AFKTimeout = extendedModel.AFKTimeout;
|
||||
server.JoinedAt = extendedModel.JoinedAt;
|
||||
server.JoinedAt = extendedModel.JoinedAt ?? DateTime.MinValue;
|
||||
server.OwnerId = extendedModel.OwnerId;
|
||||
server.Presence = extendedModel.Presence;
|
||||
server.Region = extendedModel.Region;
|
||||
@@ -420,7 +418,7 @@ namespace Discord
|
||||
private Channel DeleteChannel(string id)
|
||||
{
|
||||
Channel channel = null;
|
||||
if (_channels.TryRemove(id, out channel))
|
||||
if (_channels.TryRemove(id, out channel) && !channel.IsPrivate)
|
||||
{
|
||||
bool ignored;
|
||||
channel.Server._channels.TryRemove(id, out ignored);
|
||||
@@ -429,10 +427,10 @@ namespace Discord
|
||||
}
|
||||
|
||||
//TODO: Temporary measure, unsure if we want to store these or not.
|
||||
private ChatMessageReference GetMessage(string id, string channelId)
|
||||
private ChatMessage GetMessage(string id, string channelId)
|
||||
{
|
||||
if (id == null || channelId == null) return null;
|
||||
return new ChatMessageReference(id, channelId, this);
|
||||
return new ChatMessage(id, channelId, this);
|
||||
}
|
||||
private ChatMessage UpdateMessage(WebSocketEvents.MessageCreate model, bool addNew = true)
|
||||
{
|
||||
|
||||
@@ -114,14 +114,14 @@ namespace Discord
|
||||
RaiseGotEvent(msg.Type, msg.Payload as JToken);
|
||||
break;
|
||||
default:
|
||||
RaiseOnDebugMessage("Unknown WebSocket operation ID: " + msg.Operation);
|
||||
RaiseOnDebugMessage("Warning: Unknown WebSocket operation ID: " + msg.Operation);
|
||||
break;
|
||||
}
|
||||
|
||||
builder.Clear();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex) { RaiseOnDebugMessage($"Error: {ex.Message}"); }
|
||||
finally { _cancelToken.Cancel(); }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.Models
|
||||
{
|
||||
public class ChatMessageReference
|
||||
{
|
||||
protected readonly DiscordClient _client;
|
||||
|
||||
public string Id { get; }
|
||||
|
||||
public string ChannelId { get; }
|
||||
[JsonIgnore]
|
||||
public Channel Channel { get { return _client.GetChannel(ChannelId); } }
|
||||
|
||||
internal ChatMessageReference(string id, string channelId, DiscordClient client)
|
||||
{
|
||||
Id = id;
|
||||
ChannelId = channelId;
|
||||
_client = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.Models
|
||||
namespace Discord
|
||||
{
|
||||
public sealed class Role
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Models
|
||||
namespace Discord
|
||||
{
|
||||
public sealed class Server
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace Discord.Models
|
||||
namespace Discord
|
||||
{
|
||||
public sealed class User
|
||||
{
|
||||
Reference in New Issue
Block a user