Skip to content

Commit

Permalink
Merge pull request #353 from opentween/drop-numeric-id-properties
Browse files Browse the repository at this point in the history
TwitterStatusクラス等からlong型のIdプロパティを削除
  • Loading branch information
upsilon authored Jun 5, 2024
2 parents 5f66767 + 3671331 commit f64f98d
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 87 deletions.
2 changes: 1 addition & 1 deletion OpenTween.Tests/Api/TwitterApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ public async Task AccountVerifyCredentials_Test()
},
JsonUtils.SerializeJsonByDataContract(new TwitterUser
{
Id = 100L,
IdStr = "100",
ScreenName = "opentween",
})
);
Expand Down
24 changes: 14 additions & 10 deletions OpenTween.Tests/Models/TwitterPostFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private TwitterStatus CreateStatus()

return new()
{
Id = statusId,
IdStr = statusId.ToString(),
CreatedAt = "Sat Jan 01 00:00:00 +0000 2022",
FullText = "hoge",
Expand All @@ -61,7 +60,6 @@ private TwitterUser CreateUser()

return new()
{
Id = userId,
IdStr = userId.ToString(),
ScreenName = "tetete",
Name = "ててて",
Expand Down Expand Up @@ -212,7 +210,7 @@ public void CreateFromStatus_SelfPostUnreadTest()

var factory = new TwitterPostFactory(this.CreateTabinfo(), settingCommon);
var status = this.CreateStatus();
status.User.Id = 20000L;
status.User.IdStr = "20000";
var post = factory.CreateFromStatus(status, selfUserId: new("20000"), followerIds: EmptyIdSet, firstLoad: false);

Assert.False(post.IsRead); // 未読
Expand Down Expand Up @@ -456,11 +454,9 @@ public void CreateFromStatus_QuotedUrlTest()
};
status.QuotedStatus = new()
{
Id = 1234567890L,
IdStr = "1234567890",
User = new()
{
Id = 1111,
IdStr = "1111",
ScreenName = "foo",
},
Expand All @@ -485,11 +481,9 @@ public void CreateFromStatus_QuotedUrlWithPermelinkTest()
status.FullText = "hoge";
status.QuotedStatus = new()
{
Id = 1234567890L,
IdStr = "1234567890",
User = new TwitterUser
{
Id = 1111,
IdStr = "1111",
ScreenName = "foo",
},
Expand Down Expand Up @@ -714,7 +708,7 @@ public void GetQuoteTweetStatusIds_UrlStringTest()
[Fact]
public void ParseDateTimeFromSnowflakeId_LowerTest()
{
var statusId = 1659990873340346368L;
var statusId = new TwitterStatusId("1659990873340346368");
var createdAtStr = "Sat May 20 18:34:00 +0000 2023";
var expected = new DateTimeUtc(2023, 5, 20, 18, 34, 0, 0);
Assert.Equal(expected, TwitterPostFactory.ParseDateTimeFromSnowflakeId(statusId, createdAtStr));
Expand All @@ -723,7 +717,7 @@ public void ParseDateTimeFromSnowflakeId_LowerTest()
[Fact]
public void ParseDateTimeFromSnowflakeId_UpperTest()
{
var statusId = 1672312060766748673L;
var statusId = new TwitterStatusId("1672312060766748673");
var createdAtStr = "Fri Jun 23 18:33:59 +0000 2023";
var expected = new DateTimeUtc(2023, 6, 23, 18, 33, 59, 999);
Assert.Equal(expected, TwitterPostFactory.ParseDateTimeFromSnowflakeId(statusId, createdAtStr));
Expand All @@ -733,12 +727,22 @@ public void ParseDateTimeFromSnowflakeId_UpperTest()
public void ParseDateTimeFromSnowflakeId_FallbackTest()
{
// Snowflake 導入以前の status_id に対しては created_at の文字列からパースした日時を採用する
var statusId = 20L;
var statusId = new TwitterStatusId("20");
var createdAtStr = "Tue Mar 21 20:50:14 +0000 2006";
var expected = new DateTimeUtc(2006, 3, 21, 20, 50, 14, 0);
Assert.Equal(expected, TwitterPostFactory.ParseDateTimeFromSnowflakeId(statusId, createdAtStr));
}

[Fact]
public void ParseDateTimeFromSnowflakeId_FallbackNotNumericTest()
{
// id_str が long 型に変換できない形式だった場合は created_at からパースした日時を採用する
var statusId = new TwitterStatusId("abcdef");
var createdAtStr = "Mon Jan 01 00:00:00 +0000 2024";
var expected = new DateTimeUtc(2024, 1, 1, 0, 0, 0, 0);
Assert.Equal(expected, TwitterPostFactory.ParseDateTimeFromSnowflakeId(statusId, createdAtStr));
}

[Fact]
public void AdjustSortKeyForPromotedPost_BetweenNormatPostsTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void UpdateFromUser_Test()

var twitterUser = new TwitterUser
{
Id = 514241801L,
IdStr = "514241801",
ScreenName = "OpenTween",
StatusesCount = 31,
Expand Down
2 changes: 1 addition & 1 deletion OpenTween.Tests/TweenMainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public void CreateRetweetUnofficial_WithFormatterTest()
new TwitterEntityMention
{
Indices = new[] { 5, 16 },
Id = 6253282L,
IdStr = "6253282",
Name = "Twitter API",
ScreenName = "twitterapi",
},
Expand Down
10 changes: 5 additions & 5 deletions OpenTween.Tests/TweetFormatterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void FormatMentionEntity_Test()
new TwitterEntityMention
{
Indices = new[] { 0, 11 },
Id = 6253282L,
IdStr = "6253282",
Name = "Twitter API",
ScreenName = "twitterapi",
},
Expand Down Expand Up @@ -248,7 +248,7 @@ public void AutoLinkHtml_EscapeTest()
new TwitterEntityMention
{
Indices = new[] { 2, 13 },
Id = 6253282L,
IdStr = "6253282",
Name = "Twitter API",
ScreenName = "twitterapi",
},
Expand All @@ -268,7 +268,7 @@ public void AutoLinkHtml_EscapeTest2()
new TwitterEntityMention
{
Indices = new[] { 10, 21 },
Id = 6253282L,
IdStr = "6253282",
Name = "Twitter API",
ScreenName = "twitterapi",
},
Expand All @@ -288,7 +288,7 @@ public void AutoLinkHtml_EscapeTest3()
new TwitterEntityMention
{
Indices = new[] { 4, 15 },
Id = 6253282L,
IdStr = "6253282",
Name = "Twitter API",
ScreenName = "twitterapi",
},
Expand Down Expand Up @@ -327,7 +327,7 @@ public void AutoLinkHtml_SurrogatePairTest()
new TwitterEntityMention
{
Indices = new[] { 3, 11 },
Id = 89942943L,
IdStr = "89942943",
ScreenName = "irucame",
},
};
Expand Down
3 changes: 0 additions & 3 deletions OpenTween/Api/DataModel/TwitterEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ public class TwitterEntityUrl : TwitterEntity
[DataContract]
public class TwitterEntityMention : TwitterEntity
{
[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "id_str")]
public string IdStr { get; set; }

Expand Down
37 changes: 0 additions & 37 deletions OpenTween/Api/DataModel/TwitterStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,15 @@ public class TwitterStatus
[DataMember(Name = "full_text")]
public string FullText { get; set; }

[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "id_str")]
public string IdStr { get; set; }

[DataMember(Name = "in_reply_to_screen_name")]
public string? InReplyToScreenName { get; set; }

[DataMember(Name = "in_reply_to_status_id")]
public long? InReplyToStatusId { get; set; }

[DataMember(Name = "in_reply_to_status_id_str")]
public string? InReplyToStatusIdStr { get; set; }

[DataMember(Name = "in_reply_to_user_id")]
public long? InReplyToUserId { get; set; }

[DataMember(Name = "in_reply_to_user_id_str")]
public string? InReplyToUserIdStr { get; set; }

Expand All @@ -98,9 +89,6 @@ public class TwitterStatus
[DataMember(Name = "quote_count")]
public int? QuoteCount { get; set; }

[DataMember(Name = "quoted_status_id", IsRequired = false)]
public long? QuotedStatusId { get; set; }

[DataMember(Name = "quoted_status_id_str", IsRequired = false)]
public string? QuotedStatusIdStr { get; set; }

Expand Down Expand Up @@ -233,24 +221,15 @@ public class Extended
[DataMember(Name = "filter_level")]
public string FilterLevel { get; set; }

[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "id_str")]
public string IdStr { get; set; }

[DataMember(Name = "in_reply_to_screen_name")]
public string? InReplyToScreenName { get; set; }

[DataMember(Name = "in_reply_to_status_id")]
public long? InReplyToStatusId { get; set; }

[DataMember(Name = "in_reply_to_status_id_str")]
public string? InReplyToStatusIdStr { get; set; }

[DataMember(Name = "in_reply_to_user_id")]
public long? InReplyToUserId { get; set; }

[DataMember(Name = "in_reply_to_user_id_str")]
public string? InReplyToUserIdStr { get; set; }

Expand All @@ -269,9 +248,6 @@ public class Extended
[DataMember(Name = "quote_count")]
public int? QuoteCount { get; set; }

[DataMember(Name = "quoted_status_id", IsRequired = false)]
public long? QuotedStatusId { get; set; }

[DataMember(Name = "quoted_status_id_str", IsRequired = false)]
public string? QuotedStatusIdStr { get; set; }

Expand Down Expand Up @@ -324,19 +300,15 @@ public TwitterStatus Normalize()
FavoriteCount = this.FavoriteCount,
Favorited = this.Favorited,
FilterLevel = this.FilterLevel,
Id = this.Id,
IdStr = this.IdStr,
InReplyToScreenName = this.InReplyToScreenName,
InReplyToStatusId = this.InReplyToStatusId,
InReplyToStatusIdStr = this.InReplyToStatusIdStr,
InReplyToUserId = this.InReplyToUserId,
InReplyToUserIdStr = this.InReplyToUserIdStr,
IsQuoteStatus = this.IsQuoteStatus,
Lang = this.Lang,
Place = this.Place,
PossiblySensitive = this.PossiblySensitive,
QuoteCount = this.QuoteCount,
QuotedStatusId = this.QuotedStatusId,
QuotedStatusIdStr = this.QuotedStatusIdStr,
QuotedStatus = this.QuotedStatus?.Normalize(),
QuotedStatusPermalink = this.QuotedStatusPermalink,
Expand Down Expand Up @@ -395,18 +367,12 @@ public class TwitterDirectMessage
[DataMember(Name = "created_at")]
public string CreatedAt { get; set; }

[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "id_str")]
public string IdStr { get; set; }

[DataMember(Name = "text")]
public string Text { get; set; }

[DataMember(Name = "sender_id")]
public long SenderId { get; set; }

[DataMember(Name = "sender_id_str")]
public string SenderIdStr { get; set; }

Expand All @@ -416,9 +382,6 @@ public class TwitterDirectMessage
[DataMember(Name = "sender", IsRequired = false)]
public TwitterUser? Sender { get; set; }

[DataMember(Name = "recipient_id")]
public long RecipientId { get; set; }

[DataMember(Name = "recipient_id_str")]
public string RecipientIdStr { get; set; }

Expand Down
4 changes: 0 additions & 4 deletions OpenTween/Api/DataModel/TwitterUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public class TwitterUserEntity
[DataMember(Name = "friends_count")]
public int FriendsCount { get; set; }

[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "id_str")]
public string IdStr { get; set; }

Expand Down Expand Up @@ -120,7 +117,6 @@ public static TwitterUser CreateUnknownUser()
{
return new()
{
Id = 0L,
IdStr = "0",
ScreenName = "?????",
Name = "Unknown User",
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Api/GraphQL/TimelineTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static string GetText(XElement elm, string name)
FullText = GetText(tweetLegacyElm, "full_text"),
InReplyToScreenName = GetTextOrNull(tweetLegacyElm, "in_reply_to_screen_name"),
InReplyToStatusIdStr = GetTextOrNull(tweetLegacyElm, "in_reply_to_status_id_str"),
InReplyToUserId = GetTextOrNull(tweetLegacyElm, "in_reply_to_user_id_str") is string userId ? long.Parse(userId) : null,
InReplyToUserIdStr = GetTextOrNull(tweetLegacyElm, "in_reply_to_user_id_str"),
Favorited = GetTextOrNull(tweetLegacyElm, "favorited") is string favorited ? favorited == "true" : null,
Entities = new()
{
Expand Down
1 change: 0 additions & 1 deletion OpenTween/Api/GraphQL/TwitterGraphqlUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static string GetText(XElement elm, string name)

return new()
{
Id = long.Parse(GetText(userElm, "rest_id")),
IdStr = GetText(userElm, "rest_id"),
Name = GetText(userLegacyElm, "name"),
ProfileImageUrlHttps = GetText(userLegacyElm, "profile_image_url_https"),
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/ListManage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private async void UserList_SelectedIndexChanged(object sender, EventArgs e)
}
}

private async Task LoadUserIconAsync(Uri imageUri, long userId)
private async Task LoadUserIconAsync(Uri imageUri, PersonId userId)
{
var oldImage = this.UserIcon.Image;
this.UserIcon.Image = null;
Expand Down
6 changes: 1 addition & 5 deletions OpenTween/Models/TwitterDirectMessageId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenTween.Models
{
Expand All @@ -36,6 +32,6 @@ public class TwitterDirectMessageId : PostId
public override string Id { get; }

public TwitterDirectMessageId(string id)
=> this.Id = id;
=> this.Id = id ?? throw new ArgumentNullException(nameof(id));
}
}
Loading

0 comments on commit f64f98d

Please sign in to comment.