mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2024-11-25 14:42:44 +01:00
Compare commits
No commits in common. "039c55eb1e9338879eb6f789ac04f0d56c40b4de" and "578e51dc173f03ffd0dbe1b52e1ff4caeef3b8d5" have entirely different histories.
039c55eb1e
...
578e51dc17
@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -9,7 +8,6 @@ using DHT.Server.Data;
|
|||||||
using DHT.Server.Data.Filters;
|
using DHT.Server.Data.Filters;
|
||||||
using DHT.Server.Database;
|
using DHT.Server.Database;
|
||||||
using DHT.Server.Service;
|
using DHT.Server.Service;
|
||||||
using DHT.Utils.Collections;
|
|
||||||
using DHT.Utils.Http;
|
using DHT.Utils.Http;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
@ -55,16 +53,12 @@ namespace DHT.Server.Endpoints {
|
|||||||
Reactions = json.HasKey("reactions") ? ReadReactions(json.RequireArray("reactions", path + ".reactions"), path + ".reactions[]").ToImmutableArray() : ImmutableArray<Reaction>.Empty
|
Reactions = json.HasKey("reactions") ? ReadReactions(json.RequireArray("reactions", path + ".reactions"), path + ".reactions[]").ToImmutableArray() : ImmutableArray<Reaction>.Empty
|
||||||
};
|
};
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "ConvertToLambdaExpression")]
|
|
||||||
private static IEnumerable<Attachment> ReadAttachments(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Attachment {
|
private static IEnumerable<Attachment> ReadAttachments(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Attachment {
|
||||||
Id = ele.RequireSnowflake("id", path),
|
Id = ele.RequireSnowflake("id", path),
|
||||||
Name = ele.RequireString("name", path),
|
Name = ele.RequireString("name", path),
|
||||||
Type = ele.HasKey("type") ? ele.RequireString("type", path) : null,
|
Type = ele.HasKey("type") ? ele.RequireString("type", path) : null,
|
||||||
Url = ele.RequireString("url", path),
|
Url = ele.RequireString("url", path),
|
||||||
Size = (ulong) ele.RequireLong("size", path)
|
Size = (ulong) ele.RequireLong("size", path)
|
||||||
}).DistinctByKeyStable(static attachment => {
|
|
||||||
// Some Discord messages have duplicate attachments with the same id for unknown reasons.
|
|
||||||
return attachment.Id;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
private static IEnumerable<Embed> ReadEmbeds(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Embed {
|
private static IEnumerable<Embed> ReadEmbeds(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Embed {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace DHT.Utils.Collections {
|
|
||||||
public static class LinqExtensions {
|
|
||||||
public static IEnumerable<TItem> DistinctByKeyStable<TItem, TKey>(this IEnumerable<TItem> collection, Func<TItem, TKey> getKeyFromItem) where TKey : IEquatable<TKey> {
|
|
||||||
HashSet<TKey>? seenKeys = null;
|
|
||||||
|
|
||||||
foreach (var item in collection) {
|
|
||||||
seenKeys ??= new HashSet<TKey>();
|
|
||||||
|
|
||||||
if (seenKeys.Add(getKeyFromItem(item))) {
|
|
||||||
yield return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,6 +7,6 @@ using DHT.Utils;
|
|||||||
|
|
||||||
namespace DHT.Utils {
|
namespace DHT.Utils {
|
||||||
static class Version {
|
static class Version {
|
||||||
public const string Tag = "35.2.0.0";
|
public const string Tag = "35.1.0.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user