[parsing] Fix compatibility with the new F# reference type nullability checks

This commit is contained in:
Laura Hausmann 2024-09-12 20:44:27 +02:00
parent e3bce3bc0e
commit a18c1c59ea
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 15 additions and 9 deletions

View file

@ -5,6 +5,7 @@ using Iceshrimp.Backend.Core.Helpers.LibMfm.Parsing;
using Iceshrimp.Backend.Core.Helpers.LibMfm.Serialization;
using Microsoft.Extensions.Options;
using Microsoft.FSharp.Collections;
using Microsoft.FSharp.Core;
using static Iceshrimp.Parsing.MfmNodeTypes;
namespace Iceshrimp.Backend.Core.Federation.ActivityPub;
@ -75,8 +76,10 @@ public class MentionsResolver(
if (resolvedUser != null)
{
return new MfmMentionNode($"@{resolvedUser.Username}@{resolvedUser.Host}",
resolvedUser.Username, resolvedUser.Host);
return resolvedUser.Host == null
? new MfmMentionNode($"@{resolvedUser.Username}", resolvedUser.Username, FSharpOption<string>.None)
: new MfmMentionNode($"@{resolvedUser.Username}@{resolvedUser.Host}", resolvedUser.Username,
FSharpOption<string>.Some(resolvedUser.Host));
}
return new MfmPlainNode($"@{node.Acct}");

View file

@ -43,10 +43,12 @@
}
@if (NoteDraft.Cw != null)
{
<input @bind="NoteDraft.Cw" class="input cw-field" placeholder="Content Warning" aria-label="content warning"/>
<input @bind="NoteDraft.Cw" class="input cw-field" placeholder="Content Warning"
aria-label="content warning"/>
<hr class="separator"/>
}
<textarea @ref="Textarea" @bind="NoteDraft.Text" class="textarea" placeholder="@TextPlaceholder" rows="5" cols="35" autofocus="autofocus" aria-label="note text"></textarea>
<textarea @ref="Textarea" @bind="NoteDraft.Text" class="textarea" placeholder="@TextPlaceholder" rows="5"
cols="35" autofocus="autofocus" aria-label="note text"></textarea>
<div class="footer">
<button class="btn" title="@Loc["Upload file"]" @onclick="OpenUpload" aria-label="upload">
<Icon Name="Icons.Upload" Size="1.3rem"></Icon>
@ -54,7 +56,8 @@
<button class="btn" title="@Loc["Content warning"]" @onclick="ToggleCw" aria-label="content warning">
<Icon Name="Icons.EyeSlash" Size="1.3rem"></Icon>
</button>
<button @ref="EmojiButton" class="btn" title="@Loc["Emoji"]" @onclick="ToggleEmojiPicker" aria-label="emoji">
<button @ref="EmojiButton" class="btn" title="@Loc["Emoji"]" @onclick="ToggleEmojiPicker"
aria-label="emoji">
<Icon Name="Icons.Smiley" Size="1.3rem"></Icon>
</button>
<div class="file-input">
@ -201,7 +204,7 @@
}
var current = $"@{SessionService.Current.Username}@{SessionService.Current.Host}";
var mfmNodes = Mfm.parse(noteBase.Text);
var mfmNodes = noteBase.Text != null ? Mfm.parse(noteBase.Text) : [];
foreach (var node in mfmNodes)
{
if (node is MfmNodeTypes.MfmMentionNode mentionNode)

View file

@ -375,7 +375,7 @@ module private MfmParser =
.>> clearParen
>>= fun uri ->
match Uri.TryCreate(uri, UriKind.Absolute) with
| true, finalUri ->
| true, NonNullQuick finalUri ->
match finalUri.Scheme with
| "http" -> preturn (MfmUrlNode(uri, false) :> MfmNode)
| "https" -> preturn (MfmUrlNode(uri, false) :> MfmNode)
@ -388,7 +388,7 @@ module private MfmParser =
>>. manyCharsTill anyChar (skipChar '>')
>>= fun uri ->
match Uri.TryCreate(uri, UriKind.Absolute) with
| true, finalUri ->
| true, NonNullQuick finalUri ->
match finalUri.Scheme with
| "http" -> preturn (MfmUrlNode(uri, true) :> MfmNode)
| "https" -> preturn (MfmUrlNode(uri, true) :> MfmNode)
@ -406,7 +406,7 @@ module private MfmParser =
.>> clearParen
>>= fun ((silent, text), uri) ->
match Uri.TryCreate(uri, UriKind.Absolute) with
| true, finalUri ->
| true, NonNullQuick finalUri ->
match finalUri.Scheme with
| "http" -> preturn (MfmLinkNode(uri, text, silent.IsSome) :> MfmNode)
| "https" -> preturn (MfmLinkNode(uri, text, silent.IsSome) :> MfmNode)