[backend/core] Fix CW edits not being processed correctly, replace CW line endings during note ingest
This commit is contained in:
parent
2453e0f673
commit
010dd2bb96
2 changed files with 39 additions and 8 deletions
|
@ -0,0 +1,28 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20241214232528_NormalizeCwLineEndings")]
|
||||||
|
public partial class NormalizeCwLineEndings : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.Sql("""
|
||||||
|
UPDATE "note" SET "text" = regexp_replace("cw", '\r\n', '\n', 'g') WHERE "cw" ~ '\r\n';
|
||||||
|
UPDATE "note" SET "text" = regexp_replace("cw", '\r', '\n', 'g') WHERE "cw" ~ '\r';
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -180,7 +180,7 @@ public class NoteService(
|
||||||
mentionsResolver.ResolveMentions(data.ParsedText, data.User.Host, mentions, splitDomainMapping);
|
mentionsResolver.ResolveMentions(data.ParsedText, data.User.Host, mentions, splitDomainMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Cw = data.Cw?.Trim();
|
data.Cw = data.Cw?.ReplaceLineEndings("\n").Trim();
|
||||||
if (data.Cw != null && string.IsNullOrWhiteSpace(data.Cw))
|
if (data.Cw != null && string.IsNullOrWhiteSpace(data.Cw))
|
||||||
data.Cw = null;
|
data.Cw = null;
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ public class NoteService(
|
||||||
mentionsResolver.ResolveMentions(data.ParsedText, note.User.Host, mentions, splitDomainMapping);
|
mentionsResolver.ResolveMentions(data.ParsedText, note.User.Host, mentions, splitDomainMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Cw = data.Cw?.Trim();
|
data.Cw = data.Cw?.ReplaceLineEndings("\n").Trim();
|
||||||
if (data.Cw != null && string.IsNullOrWhiteSpace(data.Cw))
|
if (data.Cw != null && string.IsNullOrWhiteSpace(data.Cw))
|
||||||
data.Cw = null;
|
data.Cw = null;
|
||||||
|
|
||||||
|
@ -576,7 +576,6 @@ public class NoteService(
|
||||||
|
|
||||||
if (note.User.IsLocalUser && data.ParsedText != null)
|
if (note.User.IsLocalUser && data.ParsedText != null)
|
||||||
data.Emoji = (await emojiSvc.ResolveEmojiAsync(data.ParsedText)).Select(p => p.Id).ToList();
|
data.Emoji = (await emojiSvc.ResolveEmojiAsync(data.ParsedText)).Select(p => p.Id).ToList();
|
||||||
|
|
||||||
if (data.Emoji != null && !note.Emojis.IsEquivalent(data.Emoji))
|
if (data.Emoji != null && !note.Emojis.IsEquivalent(data.Emoji))
|
||||||
note.Emojis = data.Emoji;
|
note.Emojis = data.Emoji;
|
||||||
else if (data.Emoji == null && note.Emojis.Count != 0)
|
else if (data.Emoji == null && note.Emojis.Count != 0)
|
||||||
|
@ -622,7 +621,6 @@ public class NoteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
var attachments = data.Attachments?.ToList() ?? [];
|
var attachments = data.Attachments?.ToList() ?? [];
|
||||||
|
|
||||||
var inlineMediaUrls = data.ParsedText != null ? GetInlineMediaUrls(data.ParsedText) : [];
|
var inlineMediaUrls = data.ParsedText != null ? GetInlineMediaUrls(data.ParsedText) : [];
|
||||||
var newMediaUrls = data.Attachments?.Select(p => p.Url) ?? [];
|
var newMediaUrls = data.Attachments?.Select(p => p.Url) ?? [];
|
||||||
var missingUrls = inlineMediaUrls.Except(newMediaUrls).ToArray();
|
var missingUrls = inlineMediaUrls.Except(newMediaUrls).ToArray();
|
||||||
|
@ -648,6 +646,9 @@ public class NoteService(
|
||||||
note.CombinedAltText = string.Join(' ', combinedAltText);
|
note.CombinedAltText = string.Join(' ', combinedAltText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
note.Text = data.Text = data.ParsedText?.Serialize();
|
||||||
|
note.Cw = data.Cw;
|
||||||
|
|
||||||
var isPollEdited = false;
|
var isPollEdited = false;
|
||||||
|
|
||||||
var poll = data.Poll;
|
var poll = data.Poll;
|
||||||
|
@ -665,7 +666,11 @@ public class NoteService(
|
||||||
await EnqueuePollExpiryTaskAsync(note.Poll);
|
await EnqueuePollExpiryTaskAsync(note.Poll);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!note.Poll.Choices.SequenceEqual(poll.Choices) || note.Poll.Multiple != poll.Multiple)
|
if (
|
||||||
|
!note.Poll.Choices.SequenceEqual(poll.Choices)
|
||||||
|
|| note.Poll.Multiple != poll.Multiple
|
||||||
|
|| note.Text != noteEdit.Text
|
||||||
|
)
|
||||||
{
|
{
|
||||||
isPollEdited = true;
|
isPollEdited = true;
|
||||||
|
|
||||||
|
@ -720,8 +725,6 @@ public class NoteService(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
note.Text = data.Text = data.ParsedText?.Serialize();
|
|
||||||
|
|
||||||
var isEdit = data.ASNote is not ASQuestion
|
var isEdit = data.ASNote is not ASQuestion
|
||||||
|| poll == null
|
|| poll == null
|
||||||
|| isPollEdited
|
|| isPollEdited
|
||||||
|
|
Loading…
Add table
Reference in a new issue