From 8cc6c00db33db727a29f6aef7d8e9a78523bc6e0 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 29 May 2025 13:26:17 -0400 Subject: [PATCH] messages can be replied to with internalAPI and, they save correctly. which is why they weren't getting guids :face_palm: see #25 --- .../DiscordInterface/DiscordInterface.cs | 4 +--- Rememberer.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs index 44a21e3..42e39db 100644 --- a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs +++ b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs @@ -208,8 +208,6 @@ public class DiscordInterface : ProtocolInterface var m = Rememberer.SearchMessage(mi => mi.ExternalId == dMessage.Id.ToString() && mi.Protocol == Protocol) ?? new() { - //I don't understand why messages need to have their Ids specified but no other entity does. shrug dot emoji - Id = Guid.NewGuid(), Protocol = Protocol }; @@ -226,7 +224,6 @@ public class DiscordInterface : ProtocolInterface m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt; m.Channel = UpsertChannel(dMessage.Channel); m.Author = UpsertAccount(dMessage.Author, m.Channel); - Console.WriteLine($"received message; author: {m.Author.DisplayName}, {m.Author.Id}"); if (dMessage.Channel is IGuildChannel) { m.Author.DisplayName = (dMessage.Author as IGuildUser).DisplayName;//discord forgot how display names work. @@ -235,6 +232,7 @@ public class DiscordInterface : ProtocolInterface && (dMessage.MentionedUserIds?.FirstOrDefault(muid => muid == client.CurrentUser.Id) > 0)); Rememberer.RememberMessage(m); + Console.WriteLine($"received message; author: {m.Author.DisplayName}, {m.Author.Id}. messageid:{m.Id}"); return m; } internal Channel UpsertChannel(IMessageChannel channel) diff --git a/Rememberer.cs b/Rememberer.cs index bcff5ed..c45c798 100644 --- a/Rememberer.cs +++ b/Rememberer.cs @@ -84,8 +84,15 @@ public static class Rememberer public static void RememberMessage(Message toRemember) { dbAccessSemaphore.Wait(); - toRemember.Channel ??= new() { Messages = [toRemember] }; - db.Update(toRemember.Channel); + toRemember.Channel ??= new(); + toRemember.Channel.Messages ??= []; + if (!toRemember.Channel.Messages.Contains(toRemember)) + { + toRemember.Channel.Messages.Add(toRemember); + db.Update(toRemember.Channel); + // db.SaveChanges(); + } + db.Update(toRemember); db.SaveChanges(); dbAccessSemaphore.Release(); } @@ -129,9 +136,9 @@ public static class Rememberer ForgetChannel(childChannel); } } - if(toForget.Users?.Count > 0) + if (toForget.Users?.Count > 0) { - foreach(var account in toForget.Users.ToList()) + foreach (var account in toForget.Users.ToList()) { ForgetAccount(account); }