use native links for QT

This commit is contained in:
Vincent Cloutier 2023-01-27 12:32:18 -05:00
parent b1aafc28ab
commit 9e3b3992dd
3 changed files with 22 additions and 10 deletions

View file

@ -30,15 +30,17 @@ namespace BirdsiteLive.Twitter
private readonly ICachedTwitterUserService _twitterUserService;
private readonly ITwitterUserDal _twitterUserDal;
private readonly ILogger<TwitterTweetsService> _logger;
private readonly InstanceSettings _instanceSettings;
private HttpClient _httpClient = new HttpClient();
#region Ctor
public TwitterTweetsService(ITwitterAuthenticationInitializer twitterAuthenticationInitializer, ITwitterStatisticsHandler statisticsHandler, ICachedTwitterUserService twitterUserService, ITwitterUserDal twitterUserDal, ILogger<TwitterTweetsService> logger)
public TwitterTweetsService(ITwitterAuthenticationInitializer twitterAuthenticationInitializer, ITwitterStatisticsHandler statisticsHandler, ICachedTwitterUserService twitterUserService, ITwitterUserDal twitterUserDal, InstanceSettings instanceSettings, ILogger<TwitterTweetsService> 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
{

View file

@ -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<ILogger<TwitterUserService>>(MockBehavior.Strict);
var logger3 = new Mock<ILogger<TwitterTweetsService>>();
var stats = new Mock<ITwitterStatisticsHandler>();
var settings = new Mock<Common.Settings.InstanceSettings>();
var twitterDal = new Mock<ITwitterUserDal>();
var settings = new InstanceSettings
{
Domain = "domain.name"
};
twitterDal
.Setup(x => x.GetTwitterUserAsync(
It.Is<string>(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]

View file

@ -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<ILogger<TwitterAuthenticationInitializer>>(MockBehavior.Strict);
var logger2 = new Mock<ILogger<TwitterUserService>>(MockBehavior.Strict);
var logger3 = new Mock<ILogger<TwitterTweetsService>>();
var settings = new Mock<Common.Settings.InstanceSettings>();
var stats = new Mock<ITwitterStatisticsHandler>();
var twitterDal = new Mock<ITwitterUserDal>();
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]