[backend/api] Try reconstructing threads when importing notes and escape mentions

This commit is contained in:
pancakes 2025-03-13 12:44:23 +10:00 committed by Iceshrimp development
parent 0a0fb9bfb4
commit 4dac165978

View file

@ -65,20 +65,22 @@ public class ImportExportService(
if (notes == null)
throw GracefulException.BadRequest("File is not an Iceshrimp note export");
notes = notes.Where(p => p is
{
LocalOnly: false,
Poll: null,
RenoteId: null,
ReplyId: null,
Visibility: Note.NoteVisibility.Public or Note.NoteVisibility.Home,
VisibleUserIds: []
})
.OrderByDescending(p => p.Id)
.ToList();
notes = notes.FindAll(p => p is
{
LocalOnly: false,
Poll: null,
Visibility: Note.NoteVisibility.Public or Note.NoteVisibility.Home,
VisibleUserIds: []
});
var importedNotes = new Dictionary<string, Note>();
foreach (var exportNote in notes)
{
if (exportNote.ReplyId != null && !importedNotes.ContainsKey(exportNote.ReplyId))
continue;
if (exportNote.RenoteId != null && !importedNotes.ContainsKey(exportNote.RenoteId))
continue;
var attachments = new List<DriveFile>();
foreach (var exportNoteFile in exportNote.Files)
{
@ -91,13 +93,17 @@ public class ImportExportService(
{
User = user,
Visibility = exportNote.Visibility,
Text = exportNote.Text,
Text = exportNote.Text?.Replace("@", "@\\"),
Cw = exportNote.Cw,
Reply = exportNote.ReplyId != null ? importedNotes.GetValueOrDefault(exportNote.ReplyId) : null,
Renote = exportNote.RenoteId != null ? importedNotes.GetValueOrDefault(exportNote.RenoteId) : null,
Attachments = attachments.Count != 0 ? attachments : null,
CreatedAt = exportNote.CreatedAt
};
await noteSvc.CreateNoteAsync(note);
var newNote = await noteSvc.CreateNoteAsync(note);
importedNotes.Add(exportNote.Id, newNote);
}
}
}