From 9e3b3992dde8c14822ef2f1be380ef68f98bd09c Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Fri, 27 Jan 2023 12:32:18 -0500 Subject: [PATCH] use native links for QT --- src/BirdsiteLive.Twitter/TwitterTweetsService.cs | 8 ++++++-- .../BirdsiteLive.Twitter.Tests/TimelineTests.cs | 11 ++++++++--- src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs | 13 ++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index 688c738..6877649 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -30,15 +30,17 @@ namespace BirdsiteLive.Twitter private readonly ICachedTwitterUserService _twitterUserService; private readonly ITwitterUserDal _twitterUserDal; private readonly ILogger _logger; + private readonly InstanceSettings _instanceSettings; private HttpClient _httpClient = new HttpClient(); #region Ctor - public TwitterTweetsService(ITwitterAuthenticationInitializer twitterAuthenticationInitializer, ITwitterStatisticsHandler statisticsHandler, ICachedTwitterUserService twitterUserService, ITwitterUserDal twitterUserDal, ILogger logger) + public TwitterTweetsService(ITwitterAuthenticationInitializer twitterAuthenticationInitializer, ITwitterStatisticsHandler statisticsHandler, ICachedTwitterUserService twitterUserService, ITwitterUserDal twitterUserDal, InstanceSettings instanceSettings, ILogger logger) { _twitterAuthenticationInitializer = twitterAuthenticationInitializer; _statisticsHandler = statisticsHandler; _twitterUserService = twitterUserService; _twitterUserDal = twitterUserDal; + _instanceSettings = instanceSettings; _logger = logger; } #endregion @@ -285,7 +287,9 @@ namespace BirdsiteLive.Twitter string quoteTweetLink = tweet.GetProperty("content").GetProperty("itemContent") .GetProperty("tweet_results").GetProperty("result").GetProperty("legacy") .GetProperty("quoted_status_permalink").GetProperty("expanded").GetString(); - MessageContent = MessageContent + "\n" + quoteTweetLink; + quoteTweetLink = quoteTweetLink.Replace("https://twitter.com/", $"https://{_instanceSettings.Domain}/users/"); + quoteTweetLink = quoteTweetLink.Replace("/status/", "/statuses/"); + MessageContent = MessageContent + "\n\n" + quoteTweetLink; } var extractedTweet = new ExtractedTweet { diff --git a/src/Tests/BirdsiteLive.Twitter.Tests/TimelineTests.cs b/src/Tests/BirdsiteLive.Twitter.Tests/TimelineTests.cs index 8f28c0d..5e72859 100644 --- a/src/Tests/BirdsiteLive.Twitter.Tests/TimelineTests.cs +++ b/src/Tests/BirdsiteLive.Twitter.Tests/TimelineTests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using BirdsiteLive.Twitter; using BirdsiteLive.Twitter.Tools; using BirdsiteLive.Statistics.Domain; +using BirdsiteLive.Common.Settings; using Moq; using BirdsiteLive.DAL.Contracts; using BirdsiteLive.DAL.Models; @@ -21,9 +22,13 @@ namespace BirdsiteLive.ActivityPub.Tests var logger2 = new Mock>(MockBehavior.Strict); var logger3 = new Mock>(); var stats = new Mock(); - var settings = new Mock(); var twitterDal = new Mock(); + var settings = new InstanceSettings + { + Domain = "domain.name" + }; + twitterDal .Setup(x => x.GetTwitterUserAsync( It.Is(y => true) @@ -32,8 +37,8 @@ namespace BirdsiteLive.ActivityPub.Tests ITwitterAuthenticationInitializer auth = new TwitterAuthenticationInitializer(logger1.Object); ITwitterUserService user = new TwitterUserService(auth, stats.Object, logger2.Object); - ICachedTwitterUserService user2 = new CachedTwitterUserService(user, settings.Object); - _tweetService = new TwitterTweetsService(auth, stats.Object, user2, twitterDal.Object, logger3.Object); + ICachedTwitterUserService user2 = new CachedTwitterUserService(user, settings); + _tweetService = new TwitterTweetsService(auth, stats.Object, user2, twitterDal.Object, settings, logger3.Object); } [TestMethod] diff --git a/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs index 51c2e40..d80c8dc 100644 --- a/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs +++ b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs @@ -6,7 +6,7 @@ using BirdsiteLive.Twitter.Tools; using BirdsiteLive.Statistics.Domain; using Moq; using BirdsiteLive.DAL.Contracts; -using BirdsiteLive.DAL.Models; +using BirdsiteLive.Common.Settings; namespace BirdsiteLive.ActivityPub.Tests { @@ -20,13 +20,16 @@ namespace BirdsiteLive.ActivityPub.Tests var logger1 = new Mock>(MockBehavior.Strict); var logger2 = new Mock>(MockBehavior.Strict); var logger3 = new Mock>(); - var settings = new Mock(); var stats = new Mock(); var twitterDal = new Mock(); + var settings = new InstanceSettings + { + Domain = "domain.name" + }; ITwitterAuthenticationInitializer auth = new TwitterAuthenticationInitializer(logger1.Object); ITwitterUserService user = new TwitterUserService(auth, stats.Object, logger2.Object); - ICachedTwitterUserService user2 = new CachedTwitterUserService(user, settings.Object); - _tweetService = new TwitterTweetsService(auth, stats.Object, user2, twitterDal.Object, logger3.Object); + ICachedTwitterUserService user2 = new CachedTwitterUserService(user, settings); + _tweetService = new TwitterTweetsService(auth, stats.Object, user2, twitterDal.Object, settings, logger3.Object); } [TestMethod] @@ -81,7 +84,7 @@ namespace BirdsiteLive.ActivityPub.Tests { var tweet = await _tweetService.GetTweetAsync(1610807139089383427); - Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\nhttps://twitter.com/kadhim/status/1610706613207285773"); + Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\n\nhttps://domain.name/users/kadhim/statuses/1610706613207285773"); } [TestMethod]