[backend/federation] Fixup hashtags in incoming notes (ISH-421)
This commit is contained in:
parent
f45b020699
commit
5182d1bbbb
1 changed files with 10 additions and 3 deletions
|
@ -82,6 +82,8 @@ public class NoteService(
|
||||||
throw GracefulException.UnprocessableEntity("Cannot reply to a pure renote");
|
throw GracefulException.UnprocessableEntity("Cannot reply to a pure renote");
|
||||||
if (user.IsSuspended)
|
if (user.IsSuspended)
|
||||||
throw GracefulException.Forbidden("User is suspended");
|
throw GracefulException.Forbidden("User is suspended");
|
||||||
|
if (attachments != null && attachments.Any(p => p.UserId != user.Id))
|
||||||
|
throw GracefulException.UnprocessableEntity("Refusing to create note with files belonging to someone else");
|
||||||
|
|
||||||
poll?.Choices.RemoveAll(string.IsNullOrWhiteSpace);
|
poll?.Choices.RemoveAll(string.IsNullOrWhiteSpace);
|
||||||
if (poll is { Choices.Count: < 2 })
|
if (poll is { Choices.Count: < 2 })
|
||||||
|
@ -135,9 +137,6 @@ public class NoteService(
|
||||||
text = MfmSerializer.Serialize(nodes);
|
text = MfmSerializer.Serialize(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attachments != null && attachments.Any(p => p.UserId != user.Id))
|
|
||||||
throw GracefulException.UnprocessableEntity("Refusing to create note with files belonging to someone else");
|
|
||||||
|
|
||||||
if (cw != null && string.IsNullOrWhiteSpace(cw))
|
if (cw != null && string.IsNullOrWhiteSpace(cw))
|
||||||
cw = null;
|
cw = null;
|
||||||
|
|
||||||
|
@ -153,6 +152,14 @@ public class NoteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags = ResolveHashtags(text, asNote);
|
var tags = ResolveHashtags(text, asNote);
|
||||||
|
if (tags.Count > 0 && text != null && asNote != null)
|
||||||
|
{
|
||||||
|
// @formatter:off
|
||||||
|
var match = asNote.Tags?.OfType<ASHashtag>().Where(p => p.Name != null && p.Href != null) ?? [];
|
||||||
|
//TODO: refactor this to use the nodes object instead of matching on text
|
||||||
|
text = match.Aggregate(text, (current, tag) => current.Replace($"[#{tag.Name!.TrimStart('#')}]({tag.Href})", $"#{tag.Name!.TrimStart('#')}"));
|
||||||
|
// @formatter:on
|
||||||
|
}
|
||||||
|
|
||||||
var mastoReplyUserId = reply?.UserId != user.Id
|
var mastoReplyUserId = reply?.UserId != user.Id
|
||||||
? reply?.UserId
|
? reply?.UserId
|
||||||
|
|
Loading…
Add table
Reference in a new issue