Skip to content

Commit

Permalink
Merge pull request #74 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
0.12.1 PR
  • Loading branch information
NicolasConstant authored Jan 30, 2021
2 parents f721f30 + 739f7aa commit e78d37e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/BirdsiteLive.Domain/StatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public Note GetStatus(string username, ExtractedTweet tweet)
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}";
Expand All @@ -67,7 +78,7 @@ public Note GetStatus(string username, ExtractedTweet tweet)
cc = new string[0],

sensitive = false,
content = $"<p>{extractedTags.content}</p>",
content = $"<p>{content}</p>",
attachment = Convert(tweet.Media),
tag = extractedTags.tags
};
Expand Down
29 changes: 24 additions & 5 deletions src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,44 @@ public ExtractedTweet Extract(ITweet tweet)
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
Expand Down
2 changes: 2 additions & 0 deletions src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class ExtractedTweet
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; }
}
}
2 changes: 1 addition & 1 deletion src/BirdsiteLive/BirdsiteLive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit e78d37e

Please sign in to comment.