mirror of
				https://github.com/chylex/Discord-History-Tracker.git
				synced 2025-10-31 20:17:15 +01:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			578e51dc17
			...
			039c55eb1e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 039c55eb1e | |||
| a54242de8a | 
| @@ -1,5 +1,6 @@ | ||||
| using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | ||||
| using System.Diagnostics.CodeAnalysis; | ||||
| using System.Linq; | ||||
| using System.Net; | ||||
| using System.Text.Json; | ||||
| @@ -8,6 +9,7 @@ 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; | ||||
|  | ||||
| @@ -53,12 +55,16 @@ 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 { | ||||
|   | ||||
							
								
								
									
										18
									
								
								app/Utils/Collections/LinqExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								app/Utils/Collections/LinqExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| 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 { | ||||
| 	static class Version { | ||||
| 		public const string Tag = "35.1.0.0"; | ||||
| 		public const string Tag = "35.2.0.0"; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user