QT tweaks

This commit is contained in:
Vincent Cloutier 2023-06-30 12:58:31 -04:00
parent 01acc03dca
commit 26e5036870
4 changed files with 55 additions and 10 deletions

View file

@ -327,8 +327,16 @@ namespace BirdsiteLive.Twitter
string quoteTweetLink = tweet.GetProperty("content").GetProperty("itemContent") string quoteTweetLink = tweet.GetProperty("content").GetProperty("itemContent")
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy") .GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
.GetProperty("quoted_status_permalink").GetProperty("expanded").GetString(); .GetProperty("quoted_status_permalink").GetProperty("expanded").GetString();
quoteTweetLink = quoteTweetLink.Replace("https://twitter.com/", $"https://{_instanceSettings.Domain}/users/"); Uri test = new Uri(quoteTweetLink);
quoteTweetLink = quoteTweetLink.Replace("/status/", "/statuses/"); string quoteTweetAcct = test.Segments[1].Replace("/", "");
string quoteTweetId = test.Segments[3];
quoteTweetLink = quoteTweetLink.Replace("https://twitter.com/", $"https://{_instanceSettings.Domain}/@");
quoteTweetLink = quoteTweetLink.Replace("/status/", "/");
//MessageContent.Replace($"https://twitter.com/i/web/status/{}", "");
MessageContent = MessageContent.Replace($"https://twitter.com/{quoteTweetAcct}/status/{quoteTweetId}", "");
MessageContent = MessageContent + "\n\n" + quoteTweetLink; MessageContent = MessageContent + "\n\n" + quoteTweetLink;
} }

View file

@ -202,15 +202,16 @@ namespace BirdsiteLive.Controllers
id = parsedStatusId, id = parsedStatusId,
content = status.apObject.content, content = status.apObject.content,
created_at = status.published, created_at = status.published,
uri = $"https://{_instanceSettings.Domain}/users/{tweet.Author.Acct}/statuses/{tweet.Id}", uri = $"https://{_instanceSettings.Domain}/users/{tweet.Author.Acct.ToLower()}/statuses/{tweet.Id}",
url = $"https://{_instanceSettings.Domain}/@{tweet.Author.Acct}/{tweet.Id}", url = $"https://{_instanceSettings.Domain}/@{tweet.Author.Acct.ToLower()}/{tweet.Id}",
account = new MastodonUserApi() account = new MastodonUserApi()
{ {
Id = user.Id, id = user.Id,
username = user.Acct, username = user.Acct,
acct = user.Acct, acct = user.Acct,
display_name = user.Name, display_name = user.Name,
Note = user.Description, note = user.Description,
url = $"https://{_instanceSettings.Domain}/@{tweet.Author.Acct.ToLower()}",
avatar = user.ProfileImageUrl, avatar = user.ProfileImageUrl,
avatar_static = user.ProfileImageUrl, avatar_static = user.ProfileImageUrl,
header = user.ProfileBannerURL, header = user.ProfileBannerURL,

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace BirdsiteLive.Models; namespace BirdsiteLive.Models;
@ -20,18 +21,26 @@ public class MastodonPostApi
public string content { get; set; } public string content { get; set; }
public MastodonUserApi account { get; set; } public MastodonUserApi account { get; set; }
public MastodonAppApi application { get; } = new MastodonAppApi(); public MastodonAppApi application { get; } = new MastodonAppApi();
public List<MastodonAppApi> media_attachments { get; set; } = new List<MastodonAppApi>();
public List<MastodonAppApi> mentions { get; set; } = new List<MastodonAppApi>();
public List<MastodonAppApi> tags { get; set; } = new List<MastodonAppApi>();
public List<MastodonAppApi> emojis { get; set; } = new List<MastodonAppApi>();
public string card { get; set; }
public string poll { get; set; }
public string reblog { get; set; }
} }
public class MastodonUserApi public class MastodonUserApi
{ {
public long Id { get; set; } public long id { get; set; }
public string username { get; set; } public string username { get; set; }
public string acct { get; set; } public string acct { get; set; }
public string display_name { get; set; } public string display_name { get; set; }
public bool locked { get; set; } = false; public bool locked { get; set; } = false;
public bool bot { get; set; } = true; public bool bot { get; set; } = true;
public bool group { get; set; } = false; public bool group { get; set; } = false;
public string Note { get; set; } public string note { get; set; }
public string Url { get; set; } public string url { get; set; }
public string avatar { get; set; } public string avatar { get; set; }
public string avatar_static { get; set; } public string avatar_static { get; set; }
public string header { get; set; } public string header { get; set; }
@ -39,6 +48,9 @@ public class MastodonUserApi
public int followers_count { get; set; } = 0; public int followers_count { get; set; } = 0;
public int following_count { get; set; } = 0; public int following_count { get; set; } = 0;
public int statuses_count { get; set; } = 0; public int statuses_count { get; set; } = 0;
public List<MastodonAppApi> fields { get; set; } = new List<MastodonAppApi>();
public List<MastodonAppApi> emojis { get; set; } = new List<MastodonAppApi>();
} }
public class MastodonAppApi public class MastodonAppApi

View file

@ -17,6 +17,7 @@ namespace BirdsiteLive.ActivityPub.Tests
public class TweetTests public class TweetTests
{ {
private ITwitterTweetsService _tweetService; private ITwitterTweetsService _tweetService;
[TestInitialize] [TestInitialize]
public async Task TestInit() public async Task TestInit()
{ {
@ -39,6 +40,7 @@ namespace BirdsiteLive.ActivityPub.Tests
} }
[TestMethod] [TestMethod]
public async Task SimpleTextTweet() public async Task SimpleTextTweet()
{ {
@ -107,9 +109,31 @@ namespace BirdsiteLive.ActivityPub.Tests
{ {
var tweet = await _tweetService.GetTweetAsync(1610807139089383427); var tweet = await _tweetService.GetTweetAsync(1610807139089383427);
Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\n\nhttps://domain.name/users/kadhim/statuses/1610706613207285773"); Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\n\nhttps://domain.name/@kadhim/1610706613207285773");
Assert.AreEqual(tweet.Author.Acct, "RyanSAdams"); Assert.AreEqual(tweet.Author.Acct, "RyanSAdams");
} }
[TestMethod]
public async Task QTandTextContainsLink()
{
var tweet = await _tweetService.GetTweetAsync(1668932525522305026);
Assert.AreEqual(tweet.MessageContent, @"https://domain.name/@WeekInEthNews/1668684659855880193");
Assert.AreEqual(tweet.Author.Acct, "WeekInEthNews");
}
[Ignore]
[TestMethod]
public async Task QTandTextContainsWebLink()
{
var tweet = await _tweetService.GetTweetAsync(1668969663340871682);
Assert.AreEqual(tweet.MessageContent, @"Friends, our Real World Risk Workshop (now transformed into summer school) #RWRI (18th ed.) takes place July 10-21 (remote).
We have a few scholarships left but more importantly we are looking for a guest speaker on AI-LLM-Robotics for a 45 Q&amp;A with us.
http://www.realworldrisk.com https://twitter.com/i/web/status/1668969663340871682");
Assert.AreEqual(tweet.Author.Acct, "nntaleb");
}
[TestMethod] [TestMethod]
public async Task SimpleThread() public async Task SimpleThread()