1
0
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.

3 changed files with 1 additions and 25 deletions

View File

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Text.Json;
@ -9,7 +8,6 @@ using DHT.Server.Data;
using DHT.Server.Data.Filters;
using DHT.Server.Database;
using DHT.Server.Service;
using DHT.Utils.Collections;
using DHT.Utils.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
};
[SuppressMessage("ReSharper", "ConvertToLambdaExpression")]
private static IEnumerable<Attachment> ReadAttachments(JsonElement.ArrayEnumerator array, string path) => array.Select(ele => new Attachment {
Id = ele.RequireSnowflake("id", path),
Name = ele.RequireString("name", path),
Type = ele.HasKey("type") ? ele.RequireString("type", path) : null,
Url = ele.RequireString("url", 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 {

View File

@ -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;
}
}
}
}
}

View File

@ -7,6 +7,6 @@ using DHT.Utils;
namespace DHT.Utils {
static class Version {
public const string Tag = "35.2.0.0";
public const string Tag = "35.1.0.0";
}
}