diff --git a/DiscordChatExporter.Core.Models/Attachment.cs b/DiscordChatExporter.Core.Models/Attachment.cs index 8a7d10e..5510445 100644 --- a/DiscordChatExporter.Core.Models/Attachment.cs +++ b/DiscordChatExporter.Core.Models/Attachment.cs @@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models { // https://discordapp.com/developers/docs/resources/channel#attachment-object - public partial class Attachment + public partial class Attachment : IHasId { public string Id { get; } diff --git a/DiscordChatExporter.Core.Models/Channel.cs b/DiscordChatExporter.Core.Models/Channel.cs index 34b8d91..1035030 100644 --- a/DiscordChatExporter.Core.Models/Channel.cs +++ b/DiscordChatExporter.Core.Models/Channel.cs @@ -2,13 +2,13 @@ { // https://discordapp.com/developers/docs/resources/channel#channel-object - public partial class Channel + public partial class Channel : IHasId { public string Id { get; } public string? ParentId { get; } - public string? GuildId { get; } + public string GuildId { get; } public string Name { get; } @@ -16,7 +16,7 @@ public ChannelType Type { get; } - public Channel(string id, string? parentId, string? guildId, string name, string? topic, ChannelType type) + public Channel(string id, string? parentId, string guildId, string name, string? topic, ChannelType type) { Id = id; ParentId = parentId; @@ -32,6 +32,6 @@ public partial class Channel { public static Channel CreateDeletedChannel(string id) => - new Channel(id, null, null, "deleted-channel", null, ChannelType.GuildTextChat); + new Channel(id, null, "unknown-guild", "deleted-channel", null, ChannelType.GuildTextChat); } } \ No newline at end of file diff --git a/DiscordChatExporter.Core.Models/Emoji.cs b/DiscordChatExporter.Core.Models/Emoji.cs index 19af4e4..1b21bd1 100644 --- a/DiscordChatExporter.Core.Models/Emoji.cs +++ b/DiscordChatExporter.Core.Models/Emoji.cs @@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models { // https://discordapp.com/developers/docs/resources/emoji#emoji-object - public partial class Emoji + public partial class Emoji : IHasId { public string? Id { get; } diff --git a/DiscordChatExporter.Core.Models/FileSize.cs b/DiscordChatExporter.Core.Models/FileSize.cs index d52464b..23ef46f 100644 --- a/DiscordChatExporter.Core.Models/FileSize.cs +++ b/DiscordChatExporter.Core.Models/FileSize.cs @@ -30,7 +30,6 @@ namespace DiscordChatExporter.Core.Models { get { - // Absolute value is used to deal with negative values if (Math.Abs(PetaBytes) >= 1) return PetaByteSymbol; @@ -54,7 +53,6 @@ namespace DiscordChatExporter.Core.Models { get { - // Absolute value is used to deal with negative values if (Math.Abs(PetaBytes) >= 1) return PetaBytes; diff --git a/DiscordChatExporter.Core.Models/Guild.cs b/DiscordChatExporter.Core.Models/Guild.cs index 97c7b9f..0f31838 100644 --- a/DiscordChatExporter.Core.Models/Guild.cs +++ b/DiscordChatExporter.Core.Models/Guild.cs @@ -2,7 +2,7 @@ { // https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object - public partial class Guild + public partial class Guild : IHasId { public string Id { get; } diff --git a/DiscordChatExporter.Core.Models/IHasId.cs b/DiscordChatExporter.Core.Models/IHasId.cs new file mode 100644 index 0000000..27ac643 --- /dev/null +++ b/DiscordChatExporter.Core.Models/IHasId.cs @@ -0,0 +1,7 @@ +namespace DiscordChatExporter.Core.Models +{ + public interface IHasId + { + string Id { get; } + } +} \ No newline at end of file diff --git a/DiscordChatExporter.Core.Models/IdBasedEqualityComparer.cs b/DiscordChatExporter.Core.Models/IdBasedEqualityComparer.cs new file mode 100644 index 0000000..1c77ad9 --- /dev/null +++ b/DiscordChatExporter.Core.Models/IdBasedEqualityComparer.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace DiscordChatExporter.Core.Models +{ + public partial class IdBasedEqualityComparer : IEqualityComparer + { + public bool Equals(IHasId? x, IHasId? y) => StringComparer.Ordinal.Equals(x?.Id, y?.Id); + + public int GetHashCode(IHasId obj) => StringComparer.Ordinal.GetHashCode(obj.Id); + } + + public partial class IdBasedEqualityComparer + { + public static IdBasedEqualityComparer Instance { get; } = new IdBasedEqualityComparer(); + } +} \ No newline at end of file diff --git a/DiscordChatExporter.Core.Models/Message.cs b/DiscordChatExporter.Core.Models/Message.cs index 7fe2135..7deacdc 100644 --- a/DiscordChatExporter.Core.Models/Message.cs +++ b/DiscordChatExporter.Core.Models/Message.cs @@ -5,7 +5,7 @@ namespace DiscordChatExporter.Core.Models { // https://discordapp.com/developers/docs/resources/channel#message-object - public class Message + public class Message : IHasId { public string Id { get; } diff --git a/DiscordChatExporter.Core.Models/Role.cs b/DiscordChatExporter.Core.Models/Role.cs index 4eb1b20..5409f21 100644 --- a/DiscordChatExporter.Core.Models/Role.cs +++ b/DiscordChatExporter.Core.Models/Role.cs @@ -2,7 +2,7 @@ { // https://discordapp.com/developers/docs/topics/permissions#role-object - public partial class Role + public partial class Role : IHasId { public string Id { get; } diff --git a/DiscordChatExporter.Core.Models/User.cs b/DiscordChatExporter.Core.Models/User.cs index ae33ba2..2114aac 100644 --- a/DiscordChatExporter.Core.Models/User.cs +++ b/DiscordChatExporter.Core.Models/User.cs @@ -4,7 +4,7 @@ namespace DiscordChatExporter.Core.Models { // https://discordapp.com/developers/docs/topics/permissions#role-object - public partial class User + public partial class User : IHasId { public string Id { get; }