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