[backend/api] Try reconstructing threads when importing notes and escape mentions
This commit is contained in:
parent
0a0fb9bfb4
commit
4dac165978
1 changed files with 19 additions and 13 deletions
|
@ -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
|
||||
notes = notes.FindAll(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();
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue