tweaks Announce activities
This commit is contained in:
parent
2bf4266312
commit
9951645360
6 changed files with 56 additions and 10 deletions
|
@ -44,8 +44,8 @@ namespace BirdsiteLive.Domain
|
|||
if (tweet.IsRetweet)
|
||||
{
|
||||
actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, tweet.OriginalAuthor.Acct);
|
||||
noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, tweet.OriginalAuthor.Acct, tweet.Id.ToString());
|
||||
announceId = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.RetweetId.ToString());
|
||||
noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, tweet.OriginalAuthor.Acct, tweet.RetweetId.ToString());
|
||||
announceId = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());
|
||||
}
|
||||
|
||||
var to = $"{actorUrl}/followers";
|
||||
|
|
|
@ -178,6 +178,7 @@ namespace BirdsiteLive.Twitter
|
|||
JsonElement inReplyToUserElement;
|
||||
string inReplyToUser = null;
|
||||
long? inReplyToPostId = null;
|
||||
long retweetId = default;
|
||||
|
||||
string userName = tweet.GetProperty("content").GetProperty("itemContent")
|
||||
.GetProperty("tweet_results").GetProperty("result").GetProperty("core").GetProperty("user_results")
|
||||
|
@ -217,6 +218,10 @@ namespace BirdsiteLive.Twitter
|
|||
.GetProperty("core").GetProperty("user_results").GetProperty("result")
|
||||
.GetProperty("legacy").GetProperty("screen_name").GetString();
|
||||
OriginalAuthor = await _twitterUserService.GetUserAsync(OriginalAuthorUsername);
|
||||
retweetId = Int64.Parse(tweet.GetProperty("content").GetProperty("itemContent")
|
||||
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
|
||||
.GetProperty("retweeted_status_result").GetProperty("result")
|
||||
.GetProperty("rest_id").GetString());
|
||||
}
|
||||
|
||||
string creationTime = tweet.GetProperty("content").GetProperty("itemContent")
|
||||
|
@ -291,7 +296,7 @@ namespace BirdsiteLive.Twitter
|
|||
}
|
||||
var extractedTweet = new ExtractedTweet
|
||||
{
|
||||
Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()),
|
||||
Id = Int64.Parse(tweet.GetProperty("entryId").GetString().Replace("tweet-", "")),
|
||||
InReplyToStatusId = inReplyToPostId,
|
||||
InReplyToAccount = inReplyToUser,
|
||||
MessageContent = MessageContent.Trim(),
|
||||
|
@ -301,6 +306,7 @@ namespace BirdsiteLive.Twitter
|
|||
IsRetweet = isRetweet,
|
||||
Media = Media.Count() == 0 ? null : Media.ToArray(),
|
||||
RetweetUrl = "https://t.co/123",
|
||||
RetweetId = retweetId,
|
||||
OriginalAuthor = OriginalAuthor,
|
||||
};
|
||||
|
||||
|
|
|
@ -45,9 +45,41 @@ Photo by Tim Tronckoe | @timtronckoe
|
|||
var statusExtractor = new StatusExtractor(_settings, logger1.Object);
|
||||
var stats = new Mock<IExtractionStatisticsHandler>();
|
||||
var service = new StatusService(_settings, statusExtractor, stats.Object);
|
||||
var result = service.GetActivity(username, extractedTweet);
|
||||
var activity = service.GetActivity(username, extractedTweet);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(activity.type, "Create");
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RetweetTest()
|
||||
{
|
||||
#region Stubs
|
||||
var username = "MyUserName";
|
||||
var extractedTweet = new ExtractedTweet
|
||||
{
|
||||
Id = 124,
|
||||
IsRetweet = true,
|
||||
OriginalAuthor = new TwitterUser { Acct = "hello" },
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
MessageContent = @"Getting ready for the weekend...have a great one everyone!",
|
||||
RetweetId = 543,
|
||||
};
|
||||
#endregion
|
||||
|
||||
var logger1 = new Mock<ILogger<StatusExtractor>>();
|
||||
var statusExtractor = new StatusExtractor(_settings, logger1.Object);
|
||||
var stats = new Mock<IExtractionStatisticsHandler>();
|
||||
var service = new StatusService(_settings, statusExtractor, stats.Object);
|
||||
var activity = service.GetActivity(username, extractedTweet);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(activity.type, "Announce");
|
||||
Assert.AreEqual(activity.apObject.attributedTo, "https://domain.name/users/hello");
|
||||
Assert.AreEqual(activity.apObject.announceId, "https://domain.name/users/myusername/statuses/124");
|
||||
Assert.AreEqual(activity.apObject.id, "https://domain.name/users/hello/statuses/543");
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ExecuteAsync_SingleTweet_PublishReply_Test()
|
||||
public async Task ExecuteAsync_SingleRetweet_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var tweetId = 10;
|
||||
|
@ -243,7 +243,9 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
new ExtractedTweet
|
||||
{
|
||||
Id = tweetId,
|
||||
IsReply = true,
|
||||
IsReply = false,
|
||||
IsRetweet = true,
|
||||
OriginalAuthor = new TwitterUser { Acct = "hello" },
|
||||
IsThread = false
|
||||
}
|
||||
};
|
||||
|
@ -293,10 +295,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
}
|
||||
};
|
||||
|
||||
var settings = new InstanceSettings
|
||||
{
|
||||
PublishReplies = true
|
||||
};
|
||||
var settings = new InstanceSettings { };
|
||||
#endregion
|
||||
|
||||
#region Mocks
|
||||
|
|
|
@ -57,6 +57,12 @@ namespace BirdsiteLive.ActivityPub.Tests
|
|||
var tweets = await _tweetService.GetTimelineAsync("grantimahara", default);
|
||||
Assert.IsTrue(tweets[0].IsReply);
|
||||
Assert.IsTrue(tweets.Length > 30);
|
||||
|
||||
Assert.AreEqual(tweets[2].MessageContent, "Liftoff!");
|
||||
Assert.AreEqual(tweets[2].RetweetId, 1266812530833240064);
|
||||
Assert.AreEqual(tweets[2].Id, 1266813644626489345);
|
||||
Assert.AreEqual(tweets[2].OriginalAuthor.Acct, "SpaceX");
|
||||
Assert.IsTrue(tweets[2].IsRetweet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@ namespace BirdsiteLive.ActivityPub.Tests
|
|||
{
|
||||
var tweet = await _tweetService.GetTweetAsync(1600905296892891149);
|
||||
Assert.AreEqual(tweet.MessageContent, "We’re strengthening American manufacturing by creating 750,000 manufacturing jobs since I became president.");
|
||||
Assert.AreEqual(tweet.Id, 1600905296892891149);
|
||||
Assert.IsFalse(tweet.IsRetweet);
|
||||
Assert.IsFalse(tweet.IsReply);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
Reference in a new issue