commit
e78d37eb02
4 changed files with 39 additions and 7 deletions
|
@ -46,6 +46,17 @@ namespace BirdsiteLive.Domain
|
|||
var extractedTags = _statusExtractor.Extract(tweet.MessageContent);
|
||||
_statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention"));
|
||||
|
||||
// Replace RT by a link
|
||||
var content = extractedTags.content;
|
||||
if (content.Contains("{RT}") && tweet.IsRetweet)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(tweet.RetweetUrl))
|
||||
content = content.Replace("{RT}",
|
||||
$@"<a href=""{tweet.RetweetUrl}"" rel=""nofollow noopener noreferrer"" target=""_blank"">RT</a>");
|
||||
else
|
||||
content = content.Replace("{RT}", "RT");
|
||||
}
|
||||
|
||||
string inReplyTo = null;
|
||||
if (tweet.InReplyToStatusId != default)
|
||||
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount.ToLowerInvariant()}/statuses/{tweet.InReplyToStatusId}";
|
||||
|
@ -67,7 +78,7 @@ namespace BirdsiteLive.Domain
|
|||
cc = new string[0],
|
||||
|
||||
sensitive = false,
|
||||
content = $"<p>{extractedTags.content}</p>",
|
||||
content = $"<p>{content}</p>",
|
||||
attachment = Convert(tweet.Media),
|
||||
tag = extractedTags.tags
|
||||
};
|
||||
|
|
|
@ -26,25 +26,44 @@ namespace BirdsiteLive.Twitter.Extractors
|
|||
Media = ExtractMedia(tweet.Media),
|
||||
CreatedAt = tweet.CreatedAt.ToUniversalTime(),
|
||||
IsReply = tweet.InReplyToUserId != null,
|
||||
IsThread = tweet.InReplyToUserId != null && tweet.InReplyToUserId == tweet.CreatedBy.Id
|
||||
IsThread = tweet.InReplyToUserId != null && tweet.InReplyToUserId == tweet.CreatedBy.Id,
|
||||
IsRetweet = tweet.IsRetweet || tweet.QuotedStatusId != null,
|
||||
RetweetUrl = ExtractRetweetUrl(tweet)
|
||||
};
|
||||
|
||||
return extractedTweet;
|
||||
}
|
||||
|
||||
private string ExtractRetweetUrl(ITweet tweet)
|
||||
{
|
||||
if (tweet.IsRetweet && tweet.FullText.Contains("https://t.co/"))
|
||||
{
|
||||
var retweetId = tweet.FullText.Split(new[] { "https://t.co/" }, StringSplitOptions.RemoveEmptyEntries).Last();
|
||||
return $"https://t.co/{retweetId}";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ExtractMessage(ITweet tweet)
|
||||
{
|
||||
var tweetUrls = tweet.Media.Select(x => x.URL).Distinct();
|
||||
var message = tweet.FullText;
|
||||
foreach (var tweetUrl in tweetUrls)
|
||||
message = message.Replace(tweetUrl, string.Empty).Trim();
|
||||
{
|
||||
if(tweet.IsRetweet)
|
||||
message = tweet.RetweetedTweet.FullText.Replace(tweetUrl, string.Empty).Trim();
|
||||
else
|
||||
message = message.Replace(tweetUrl, string.Empty).Trim();
|
||||
}
|
||||
|
||||
if (tweet.QuotedTweet != null) message = $"[Quote RT]{Environment.NewLine}{message}";
|
||||
if (tweet.QuotedTweet != null) message = $"[Quote {{RT}}]{Environment.NewLine}{message}";
|
||||
if (tweet.IsRetweet)
|
||||
{
|
||||
if (tweet.RetweetedTweet != null)
|
||||
message = $"[RT @{tweet.RetweetedTweet.CreatedBy.ScreenName}]{Environment.NewLine}{tweet.RetweetedTweet.FullText}";
|
||||
message = $"[{{RT}} @{tweet.RetweetedTweet.CreatedBy.ScreenName}]{Environment.NewLine}{message}";
|
||||
else
|
||||
message = message.Replace("RT", "[RT]");
|
||||
message = message.Replace("RT", "[{{RT}}]");
|
||||
}
|
||||
|
||||
// Expand URLs
|
||||
|
|
|
@ -13,5 +13,7 @@ namespace BirdsiteLive.Twitter.Models
|
|||
public string InReplyToAccount { get; set; }
|
||||
public bool IsReply { get; set; }
|
||||
public bool IsThread { get; set; }
|
||||
public bool IsRetweet { get; set; }
|
||||
public string RetweetUrl { get; set; }
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<Version>0.12.0</Version>
|
||||
<Version>0.12.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Reference in a new issue