Skip to content

Commit

Permalink
PostClass.PostUriプロパティを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Jun 7, 2024
1 parent 7236ee4 commit b402d2c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 37 deletions.
2 changes: 2 additions & 0 deletions OpenTween.Tests/Models/TwitterPostFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void CreateFromStatus_Test()
var post = factory.CreateFromStatus(status, selfUserId: new("20000"), followerIds: EmptyIdSet, firstLoad: false);

Assert.Equal(new TwitterStatusId(status.IdStr), post.StatusId);
Assert.Equal(new($"https://twitter.com/tetete/status/{status.IdStr}"), post.PostUri);
Assert.Equal(new DateTimeUtc(2022, 1, 1, 0, 0, 0), post.CreatedAt);
Assert.Equal("hoge", post.Text);
Assert.Equal("hoge", post.TextFromApi);
Expand Down Expand Up @@ -288,6 +289,7 @@ public void CreateFromDirectMessageEvent_Test()
var post = factory.CreateFromDirectMessageEvent(eventItem, users, apps, selfUserId: new(selfUser.IdStr), firstLoad: false);

Assert.Equal(new TwitterDirectMessageId(eventItem.Id), post.StatusId);
Assert.Null(post.PostUri);
Assert.Equal(new DateTimeUtc(2022, 1, 1, 0, 0, 0), post.CreatedAt);
Assert.Equal("hoge", post.Text);
Assert.Equal("hoge", post.TextFromApi);
Expand Down
19 changes: 1 addition & 18 deletions OpenTween.Tests/MyCommonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,10 @@ public void ReplaceAppNameTest(string str, string excepted)
public void GetReadableVersionTest(string fileVersion, string expected)
=> Assert.Equal(expected, MyCommon.GetReadableVersion(fileVersion));

public static readonly TheoryData<PostClass, string> GetStatusUrlTest1TestCase = new()
{
{
new PostClass { StatusId = new TwitterStatusId("249493863826350080"), ScreenName = "Favstar_LM", RetweetedId = null, RetweetedBy = null },
"https://twitter.com/Favstar_LM/status/249493863826350080"
},
{
new PostClass { StatusId = new TwitterStatusId("216033842434289664"), ScreenName = "haru067", RetweetedId = new TwitterStatusId("200245741443235840"), RetweetedBy = "re4k" },
"https://twitter.com/haru067/status/200245741443235840"
},
};

[Theory]
[MemberData(nameof(GetStatusUrlTest1TestCase))]
public void GetStatusUrlTest1(PostClass post, string expected)
=> Assert.Equal(expected, MyCommon.GetStatusUrl(post));

[Theory]
[InlineData("Favstar_LM", 249493863826350080L, "https://twitter.com/Favstar_LM/status/249493863826350080")]
[InlineData("haru067", 200245741443235840L, "https://twitter.com/haru067/status/200245741443235840")]
public void GetStatusUrlTest2(string screenName, long statusId, string expected)
public void GetStatusUrlTest(string screenName, long statusId, string expected)
=> Assert.Equal(expected, MyCommon.GetStatusUrl(screenName, new TwitterStatusId(statusId)));

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions OpenTween/Models/PostClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ double Latitude

public PostId StatusId { get; init; } = null!;

public Uri? PostUri { get; init; }

public string Text
{
get
Expand Down
1 change: 1 addition & 0 deletions OpenTween/Models/TwitterPostFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public PostClass CreateFromStatus(
IsPromoted = status.IsPromoted,

// originalStatus から生成
PostUri = new(MyCommon.GetStatusUrl(screenName, new(originalStatus.IdStr))),
CreatedAt = createdAt,
Text = text,
TextFromApi = textFromApi,
Expand Down
6 changes: 0 additions & 6 deletions OpenTween/MyCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,12 +828,6 @@ public static string GetReadableVersion(Version version)

public const string TwitterUrl = "https://twitter.com/";

public static string GetStatusUrl(PostClass post)
{
var statusId = post.RetweetedId ?? post.StatusId;
return GetStatusUrl(post.ScreenName, statusId.ToTwitterStatusId());
}

public static string GetStatusUrl(string screenName, TwitterStatusId statusId)
=> TwitterUrl + screenName + "/status/" + statusId.Id;

Expand Down
17 changes: 12 additions & 5 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3704,8 +3704,8 @@ private async void StatusOpenMenuItem_Click(object sender, EventArgs e)
{
var tab = this.CurrentTab;
var post = this.CurrentPost;
if (post != null && tab.TabType != MyCommon.TabUsageType.DirectMessage)
await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(post));
if (post?.PostUri is { } postUri)
await MyCommon.OpenInBrowserAsync(this, postUri);
}

private async void VerUpMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -4621,7 +4621,10 @@ private void CopyIdUri()

var copyUrls = new List<string>();
foreach (var post in tab.SelectedPosts)
copyUrls.Add(MyCommon.GetStatusUrl(post));
{
if (post.PostUri is { } postUri)
copyUrls.Add(postUri.ToString());
}

if (copyUrls.Count == 0)
return;
Expand Down Expand Up @@ -6986,7 +6989,8 @@ private async Task DoRepliedStatusOpen()
{
if (MyCommon.IsKeyDown(Keys.Shift))
{
await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.ToTwitterStatusId()));
if (currentPost.PostUri is { } postUri)
await MyCommon.OpenInBrowserAsync(this, postUri);
return;
}
if (this.statuses.Posts.TryGetValue(currentPost.InReplyToStatusId, out var repPost))
Expand Down Expand Up @@ -8243,11 +8247,14 @@ private void DoQuoteOfficial()
return;
}

if (post.PostUri is not { } postUri)
return;

var selection = (this.StatusText.SelectionStart, this.StatusText.SelectionLength);

this.inReplyTo = null;

this.StatusText.Text += " " + MyCommon.GetStatusUrl(post);
this.StatusText.Text += " " + postUri;

(this.StatusText.SelectionStart, this.StatusText.SelectionLength) = selection;
this.StatusText.Focus();
Expand Down
10 changes: 2 additions & 8 deletions OpenTween/TweetDetailsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,14 +1119,8 @@ private async void NameLinkLabel_LinkClicked(object sender, LinkLabelLinkClicked

private async void DateTimeLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (this.CurrentPost == null)
return;

if (this.CurrentPost.StatusId is not TwitterStatusId)
return;

var statusUrl = MyCommon.GetStatusUrl(this.CurrentPost);
await MyCommon.OpenInBrowserAsync(this, statusUrl);
if (this.CurrentPost?.PostUri is { } postUri)
await MyCommon.OpenInBrowserAsync(this, postUri);
}
}

Expand Down

0 comments on commit b402d2c

Please sign in to comment.