[backend/masto-client] Improve quote handling (ISH-176)
This commit is contained in:
parent
e65c76ca39
commit
d4fe223552
1 changed files with 28 additions and 7 deletions
|
@ -7,6 +7,9 @@ using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
using Iceshrimp.Backend.Core.Extensions;
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
|
using Iceshrimp.Backend.Core.Helpers.LibMfm.Parsing;
|
||||||
|
using Iceshrimp.Backend.Core.Helpers.LibMfm.Serialization;
|
||||||
|
using Iceshrimp.Backend.Core.Helpers.LibMfm.Types;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
using Iceshrimp.Backend.Core.Services;
|
using Iceshrimp.Backend.Core.Services;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
|
@ -338,8 +341,24 @@ public class StatusController(
|
||||||
? await db.DriveFiles.Where(p => request.MediaIds.Contains(p.Id)).ToListAsync()
|
? await db.DriveFiles.Where(p => request.MediaIds.Contains(p.Id)).ToListAsync()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
var lastToken = request.Text?.Split(' ').LastOrDefault();
|
string? quoteUri = null;
|
||||||
var quoteUri = token.AutoDetectQuotes && (lastToken?.StartsWith("https://") ?? false) ? lastToken : null;
|
string? newText = null;
|
||||||
|
|
||||||
|
if (token.AutoDetectQuotes && request.Text != null)
|
||||||
|
{
|
||||||
|
var parsed = MfmParser.Parse(request.Text);
|
||||||
|
quoteUri = MfmParser.Parse(request.Text).LastOrDefault() switch
|
||||||
|
{
|
||||||
|
MfmUrlNode urlNode => urlNode.Url,
|
||||||
|
MfmLinkNode linkNode => linkNode.Url,
|
||||||
|
_ => quoteUri
|
||||||
|
};
|
||||||
|
|
||||||
|
if (quoteUri != null)
|
||||||
|
parsed = parsed.SkipLast(1);
|
||||||
|
newText = MfmSerializer.Serialize(parsed).Trim();
|
||||||
|
}
|
||||||
|
|
||||||
var quote = request.QuoteId != null
|
var quote = request.QuoteId != null
|
||||||
? await db.Notes
|
? await db.Notes
|
||||||
.IncludeCommonProperties()
|
.IncludeCommonProperties()
|
||||||
|
@ -349,17 +368,19 @@ public class StatusController(
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
quote ??= quoteUri != null
|
quote ??= quoteUri != null
|
||||||
? lastToken?.StartsWith($"https://{config.Value.WebDomain}/notes/") ?? false
|
? quoteUri.StartsWith($"https://{config.Value.WebDomain}/notes/")
|
||||||
? await db.Notes.IncludeCommonProperties()
|
? await db.Notes.IncludeCommonProperties()
|
||||||
.FirstOrDefaultAsync(p => p.Id ==
|
.FirstOrDefaultAsync(p => p.Id ==
|
||||||
lastToken.Substring($"https://{config.Value.WebDomain}/notes/"
|
quoteUri.Substring($"https://{config.Value.WebDomain}/notes/"
|
||||||
.Length))
|
.Length))
|
||||||
: await db.Notes.IncludeCommonProperties()
|
: await db.Notes.IncludeCommonProperties()
|
||||||
.FirstOrDefaultAsync(p => p.Uri == quoteUri || p.Url == quoteUri)
|
.FirstOrDefaultAsync(p => p.Uri == quoteUri || p.Url == quoteUri)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (quote != null && quoteUri != null && request.QuoteId == null && request.Text != null)
|
List<string?> urls = quote == null ? [] : [quote.Url, quote.Uri, quote.GetPublicUriOrNull(config.Value)];
|
||||||
request.Text = request.Text[..(request.Text.Length - quoteUri.Length - 1)];
|
|
||||||
|
if (quote != null && request.Text != null && newText != null && urls.OfType<string>().Contains(quoteUri))
|
||||||
|
request.Text = newText;
|
||||||
|
|
||||||
var note = await noteSvc.CreateNoteAsync(user, visibility, request.Text, request.Cw, reply, quote, attachments,
|
var note = await noteSvc.CreateNoteAsync(user, visibility, request.Text, request.Cw, reply, quote, attachments,
|
||||||
poll, request.LocalOnly);
|
poll, request.LocalOnly);
|
||||||
|
|
Loading…
Add table
Reference in a new issue