commit
9729af9d17
9 changed files with 43 additions and 40 deletions
|
@ -4,5 +4,6 @@
|
|||
{
|
||||
public string Domain { get; set; }
|
||||
public string AdminEmail { get; set; }
|
||||
public bool ResolveMentionsInProfiles { get; set; }
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ namespace BirdsiteLive.Domain
|
|||
var to = $"{actorUrl}/followers";
|
||||
var apPublic = "https://www.w3.org/ns/activitystreams#Public";
|
||||
|
||||
var extractedTags = _statusExtractor.ExtractTags(tweet.MessageContent);
|
||||
var extractedTags = _statusExtractor.Extract(tweet.MessageContent);
|
||||
_statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention"));
|
||||
|
||||
string inReplyTo = null;
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace BirdsiteLive.Domain.Tools
|
|||
{
|
||||
public interface IStatusExtractor
|
||||
{
|
||||
(string content, Tag[] tags) ExtractTags(string messageContent);
|
||||
(string content, Tag[] tags) Extract(string messageContent, bool extractMentions = true);
|
||||
}
|
||||
|
||||
public class StatusExtractor : IStatusExtractor
|
||||
|
@ -36,7 +36,7 @@ namespace BirdsiteLive.Domain.Tools
|
|||
}
|
||||
#endregion
|
||||
|
||||
public (string content, Tag[] tags) ExtractTags(string messageContent)
|
||||
public (string content, Tag[] tags) Extract(string messageContent, bool extractMentions = true)
|
||||
{
|
||||
var tags = new List<Tag>();
|
||||
messageContent = $" {messageContent} ";
|
||||
|
@ -102,22 +102,25 @@ namespace BirdsiteLive.Domain.Tools
|
|||
}
|
||||
|
||||
// Extract Mentions
|
||||
var mentionMatch = OrderByLength(_mentionRegex.Matches(messageContent));
|
||||
foreach (Match m in mentionMatch.OrderByDescending(x => x.Length))
|
||||
if (extractMentions)
|
||||
{
|
||||
var mention = m.ToString().Replace("@", string.Empty).Replace("\n", string.Empty).Trim();
|
||||
var url = $"https://{_instanceSettings.Domain}/users/{mention}";
|
||||
var name = $"@{mention}@{_instanceSettings.Domain}";
|
||||
|
||||
tags.Add(new Tag
|
||||
var mentionMatch = OrderByLength(_mentionRegex.Matches(messageContent));
|
||||
foreach (Match m in mentionMatch.OrderByDescending(x => x.Length))
|
||||
{
|
||||
name = name,
|
||||
href = url,
|
||||
type = "Mention"
|
||||
});
|
||||
var mention = m.ToString().Replace("@", string.Empty).Replace("\n", string.Empty).Trim();
|
||||
var url = $"https://{_instanceSettings.Domain}/users/{mention}";
|
||||
var name = $"@{mention}@{_instanceSettings.Domain}";
|
||||
|
||||
messageContent = Regex.Replace(messageContent, m.ToString(),
|
||||
$@" <span class=""h-card""><a href=""https://{_instanceSettings.Domain}/@{mention}"" class=""u-url mention"">@<span>{mention}</span></a></span>");
|
||||
tags.Add(new Tag
|
||||
{
|
||||
name = name,
|
||||
href = url,
|
||||
type = "Mention"
|
||||
});
|
||||
|
||||
messageContent = Regex.Replace(messageContent, m.ToString(),
|
||||
$@" <span class=""h-card""><a href=""https://{_instanceSettings.Domain}/@{mention}"" class=""u-url mention"">@<span>{mention}</span></a></span>");
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up return lines
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace BirdsiteLive.Domain
|
|||
var description = twitterUser.Description;
|
||||
if (!string.IsNullOrWhiteSpace(description))
|
||||
{
|
||||
var extracted = _statusExtractor.ExtractTags(description);
|
||||
var extracted = _statusExtractor.Extract(description, _instanceSettings.ResolveMentionsInProfiles);
|
||||
description = extracted.content;
|
||||
|
||||
_statisticsHandler.ExtractedDescription(extracted.tags.Count(x => x.type == "Mention"));
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
//TODO handle error
|
||||
}
|
||||
|
||||
await Task.Delay(SyncPeriod * 1000 * 60, ct);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<Version>0.7.0</Version>
|
||||
<Version>0.8.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -125,10 +125,7 @@ namespace BirdsiteLive.Controllers
|
|||
var activity = ApDeserializer.ProcessActivity(body);
|
||||
// Do something
|
||||
var signature = r.Headers["Signature"].First();
|
||||
|
||||
Console.WriteLine(body);
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
switch (activity?.type)
|
||||
{
|
||||
case "Follow":
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
"AllowedHosts": "*",
|
||||
"Instance": {
|
||||
"Domain": "domain.name",
|
||||
"AdminEmail": "me@domain.name"
|
||||
"AdminEmail": "me@domain.name",
|
||||
"ResolveMentionsInProfiles": true
|
||||
},
|
||||
"Db": {
|
||||
"Type": "postgres",
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.IsTrue(result.content.Contains("Bla."));
|
||||
|
@ -46,7 +46,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.IsTrue(result.content.Contains("Bla."));
|
||||
|
@ -62,7 +62,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(0, result.tags.Length);
|
||||
|
@ -80,7 +80,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(0, result.tags.Length);
|
||||
|
@ -98,7 +98,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(0, result.tags.Length);
|
||||
|
@ -116,7 +116,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(0, result.tags.Length);
|
||||
|
@ -136,7 +136,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -157,7 +157,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -178,7 +178,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -199,7 +199,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(4, result.tags.Length);
|
||||
|
@ -219,7 +219,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -240,7 +240,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -261,7 +261,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -282,7 +282,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(4, result.tags.Length);
|
||||
|
@ -302,7 +302,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(5, result.tags.Length);
|
||||
|
@ -325,7 +325,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
@ -345,7 +345,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
|
|||
#endregion
|
||||
|
||||
var service = new StatusExtractor(_settings);
|
||||
var result = service.ExtractTags(message);
|
||||
var result = service.Extract(message);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(1, result.tags.Length);
|
||||
|
|
Reference in a new issue