tweak mentions

This commit is contained in:
Vincent Cloutier 2023-01-21 13:41:15 -05:00
parent 6aa36f8d38
commit 6bc915f97d
5 changed files with 20 additions and 15 deletions

View file

@ -5,6 +5,6 @@ namespace BirdsiteLive.Common.Regexes
public class UserRegexes
{
public static readonly Regex TwitterAccount = new Regex(@"^[a-zA-Z0-9_]+$");
public static readonly Regex Mention = new Regex(@"(.?)@([a-zA-Z0-9_]+)(\s|$|[\[\]<>,;:'\.!?/|-]|(. ))");
public static readonly Regex Mention = new Regex(@"(.?)@([a-zA-Z0-9_]+)(\s|$|[\[\]<>,;:'\.!?/—\|-]|(. ))");
}
}

View file

@ -108,7 +108,7 @@ namespace BirdsiteLive.Domain.Tools
}
var url = $"https://{_instanceSettings.Domain}/users/{mention.ToLower()}";
var name = $"@{mention}";
var name = $"@{mention.ToLower()}";
if (tags.All(x => x.href != url))
{
@ -121,7 +121,7 @@ namespace BirdsiteLive.Domain.Tools
}
messageContent = Regex.Replace(messageContent, Regex.Escape(m.Groups[0].ToString()),
$@"{m.Groups[1]}<span class=""h-card""><a href=""{url}"" class=""u-url mention"">@<span>{mention}</span></a></span>{m.Groups[3]}");
$@"{m.Groups[1]}<span class=""h-card""><a href=""{url}"" class=""u-url mention"">@<span>{mention.ToLower()}</span></a></span>{m.Groups[3]}");
}
}

View file

@ -35,7 +35,7 @@ namespace BirdsiteLive.Twitter.Tools
_logger = logger;
aTimer = new System.Timers.Timer();
aTimer.Interval = 45 * 1000;
aTimer.Interval = 20 * 1000;
aTimer.Elapsed += async (sender, e) => await RefreshCred();
aTimer.Start();

View file

@ -390,7 +390,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
public void Extract_TagsWithPunctuations_Test()
{
#region Stubs
var message = $"this: @amberfloio. @StellantisNAs";
var message = $"this: @amberfloio. @VP—and @StellantisNAs";
#endregion
#region Mocks
@ -402,13 +402,18 @@ namespace BirdsiteLive.Domain.Tests.Tools
#region Validations
logger.VerifyAll();
Assert.AreEqual(2, result.tags.Length);
Assert.AreEqual(3, result.tags.Length);
Assert.AreEqual("@amberfloio", result.tags.First().name);
Assert.AreEqual("Mention", result.tags.First().type);
Assert.AreEqual("https://domain.name/users/amberfloio", result.tags.First().href);
Assert.AreEqual("@vp", result.tags[0].name);
Assert.AreEqual("Mention", result.tags[0].type);
Assert.AreEqual("https://domain.name/users/vp", result.tags[0].href);
Assert.AreEqual("@StellantisNA", result.tags.Last().name);
Assert.AreEqual("@amberfloio", result.tags[1].name);
Assert.AreEqual("Mention", result.tags[1].type);
Assert.AreEqual("https://domain.name/users/amberfloio", result.tags[1].href);
Assert.AreEqual("@stellantisna", result.tags.Last().name);
Assert.AreEqual("Mention", result.tags.Last().type);
Assert.AreEqual("https://domain.name/users/stellantisna", result.tags.Last().href);
@ -437,8 +442,8 @@ namespace BirdsiteLive.Domain.Tests.Tools
Assert.AreEqual("Mention", result.tags.First().type);
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/users/photos_floues"" class=""u-url mention"">@<span>photos_floues</span></a></span>"));
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/users/kiwixoffline"" class=""u-url mention"">@<span>KiwixOffline</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/photos_floues"" class=""u-url mention"">@<span>photos_floues</span></a></span>"));
Assert.IsTrue(result.content.Contains(@"Cc <span class=""h-card""><a href=""https://domain.name/users/pyb75"" class=""u-url mention"">@<span>Pyb75</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/photos_floues"" class=""u-url mention"">@<span>photos_floues</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/kiwixoffline"" class=""u-url mention"">@<span>KiwixOffline</span></a></span>"));
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/users/kiwixoffline"" class=""u-url mention"">@<span>kiwixoffline</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/photos_floues"" class=""u-url mention"">@<span>photos_floues</span></a></span>"));
Assert.IsTrue(result.content.Contains(@"Cc <span class=""h-card""><a href=""https://domain.name/users/pyb75"" class=""u-url mention"">@<span>pyb75</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/photos_floues"" class=""u-url mention"">@<span>photos_floues</span></a></span> <span class=""h-card""><a href=""https://domain.name/users/kiwixoffline"" class=""u-url mention"">@<span>kiwixoffline</span></a></span>"));
#endregion
}
@ -564,12 +569,12 @@ namespace BirdsiteLive.Domain.Tests.Tools
#region Validations
logger.VerifyAll();
Assert.AreEqual(1, result.tags.Length);
Assert.AreEqual("@myNickName", result.tags.First().name);
Assert.AreEqual("@mynickname", result.tags.First().name);
Assert.AreEqual("Mention", result.tags.First().type);
Assert.AreEqual("https://domain.name/users/mynickname", result.tags.First().href);
Assert.IsTrue(result.content.Contains("Bla!"));
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/users/mynickname"" class=""u-url mention"">@<span>myNickName</span></a></span>"));
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/users/mynickname"" class=""u-url mention"">@<span>mynickname</span></a></span>"));
#endregion
}

View file

@ -49,7 +49,7 @@ namespace BirdsiteLive.ActivityPub.Tests
{
var tweets = await _tweetService.GetTimelineAsync("grantimahara", default);
Assert.IsTrue(tweets[0].IsReply);
Assert.AreEqual(tweets.Length, 40);
Assert.IsTrue(tweets.Length > 30);
}
}