Revert "Collapsed Discord.Models namespace, cleaned up Message cache"

This reverts commit 389372b93f.
This commit is contained in:
Brandon Smith
2015-08-09 11:29:56 -03:00
parent 389372b93f
commit a9c495090b
12 changed files with 60 additions and 102 deletions

63
.gitattributes vendored
View File

@@ -1,63 +0,0 @@
###############################################################################
# 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

View File

@@ -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")]

View File

@@ -49,9 +49,10 @@
<Compile Include="API\Models\ApiRequests.cs" />
<Compile Include="API\Endpoints.cs" />
<Compile Include="API\Models\WebSocketCommands.cs" />
<Compile Include="Role.cs" />
<Compile Include="ChatMessage.cs" />
<Compile Include="Channel.cs" />
<Compile Include="Models\Role.cs" />
<Compile Include="Models\ChatMessageReference.cs" />
<Compile Include="Models\ChatMessage.cs" />
<Compile Include="Models\Channel.cs" />
<Compile Include="DiscordWebSocket.Events.cs" />
<Compile Include="Helpers\Http.cs" />
<Compile Include="API\DiscordAPI.cs" />
@@ -61,8 +62,8 @@
<Compile Include="DiscordClient.Events.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DiscordWebSocket.cs" />
<Compile Include="Server.cs" />
<Compile Include="User.cs" />
<Compile Include="Models\Server.cs" />
<Compile Include="Models\User.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -1,4 +1,5 @@
using System;
using Discord.Models;
using System;
namespace Discord
{
@@ -97,35 +98,40 @@ namespace Discord
}
//Message
public sealed class MessageEventArgs : EventArgs
public sealed class MessageCreateEventArgs : EventArgs
{
public readonly ChatMessage Message;
internal MessageEventArgs(ChatMessage msg) { Message = msg; }
internal MessageCreateEventArgs(ChatMessage msg) { Message = msg; }
}
public sealed class MessageEventArgs : EventArgs
{
public readonly ChatMessageReference Message;
internal MessageEventArgs(ChatMessageReference msg) { Message = msg; }
}
public event EventHandler<MessageEventArgs> MessageCreated;
public event EventHandler<MessageCreateEventArgs> MessageCreated;
private void RaiseMessageCreated(ChatMessage msg)
{
if (MessageCreated != null)
MessageCreated(this, new MessageEventArgs(msg));
MessageCreated(this, new MessageCreateEventArgs(msg));
}
public event EventHandler<MessageEventArgs> MessageDeleted;
private void RaiseMessageDeleted(ChatMessage msg)
private void RaiseMessageDeleted(ChatMessageReference msg)
{
if (MessageDeleted != null)
MessageDeleted(this, new MessageEventArgs(msg));
}
public event EventHandler<MessageEventArgs> MessageUpdated;
private void RaiseMessageUpdated(ChatMessage msg)
private void RaiseMessageUpdated(ChatMessageReference msg)
{
if (MessageUpdated != null)
MessageUpdated(this, new MessageEventArgs(msg));
}
public event EventHandler<MessageEventArgs> MessageAcknowledged;
private void RaiseMessageAcknowledged(ChatMessage msg)
private void RaiseMessageAcknowledged(ChatMessageReference msg)
{
if (MessageAcknowledged != null)
MessageAcknowledged(this, new MessageEventArgs(msg));

View File

@@ -1,11 +1,13 @@
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
{
@@ -370,7 +372,7 @@ namespace Discord
var extendedModel = model as ExtendedServerInfo;
server.AFKChannelId = extendedModel.AFKChannelId;
server.AFKTimeout = extendedModel.AFKTimeout;
server.JoinedAt = extendedModel.JoinedAt ?? DateTime.MinValue;
server.JoinedAt = extendedModel.JoinedAt;
server.OwnerId = extendedModel.OwnerId;
server.Presence = extendedModel.Presence;
server.Region = extendedModel.Region;
@@ -418,7 +420,7 @@ namespace Discord
private Channel DeleteChannel(string id)
{
Channel channel = null;
if (_channels.TryRemove(id, out channel) && !channel.IsPrivate)
if (_channels.TryRemove(id, out channel))
{
bool ignored;
channel.Server._channels.TryRemove(id, out ignored);
@@ -427,10 +429,10 @@ namespace Discord
}
//TODO: Temporary measure, unsure if we want to store these or not.
private ChatMessage GetMessage(string id, string channelId)
private ChatMessageReference GetMessage(string id, string channelId)
{
if (id == null || channelId == null) return null;
return new ChatMessage(id, channelId, this);
return new ChatMessageReference(id, channelId, this);
}
private ChatMessage UpdateMessage(WebSocketEvents.MessageCreate model, bool addNew = true)
{

View File

@@ -114,14 +114,14 @@ namespace Discord
RaiseGotEvent(msg.Type, msg.Payload as JToken);
break;
default:
RaiseOnDebugMessage("Warning: Unknown WebSocket operation ID: " + msg.Operation);
RaiseOnDebugMessage("Unknown WebSocket operation ID: " + msg.Operation);
break;
}
builder.Clear();
}
}
catch (Exception ex) { RaiseOnDebugMessage($"Error: {ex.Message}"); }
catch { }
finally { _cancelToken.Cancel(); }
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json;
namespace Discord
namespace Discord.Models
{
public sealed class Channel
{

View File

@@ -1,23 +1,15 @@
using Newtonsoft.Json;
using System;
namespace Discord
namespace Discord.Models
{
public sealed class ChatMessage
public sealed class ChatMessage : ChatMessageReference
{
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); } }
@@ -27,11 +19,9 @@ namespace Discord
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()
{

View File

@@ -0,0 +1,22 @@
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;
}
}
}

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json;
namespace Discord
namespace Discord.Models
{
public sealed class Role
{

View File

@@ -4,7 +4,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace Discord
namespace Discord.Models
{
public sealed class Server
{

View File

@@ -1,6 +1,6 @@
using System;
namespace Discord
namespace Discord.Models
{
public sealed class User
{