• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: Commit

開発に使用するリポジトリ


Commit MetaInfo

Revisión56c9541eb4e443073be3df0963f7aaaaedb65044 (tree)
Tiempo2018-10-14 00:48:00
AutorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

絵文字に関する文字数カウントの新仕様に対応

https://twittercommunity.com/t/114607

Cambiar Resumen

Diferencia incremental

--- a/OpenTween.Tests/TwitterTest.cs
+++ b/OpenTween.Tests/TwitterTest.cs
@@ -629,6 +629,26 @@ namespace OpenTween
629629 }
630630
631631 [Fact]
632+ public void GetTextLengthRemain_EmojiTest()
633+ {
634+ using (var twitter = new Twitter())
635+ {
636+ // 絵文字の文字数カウントの仕様変更に対するテストケース
637+ // https://twittercommunity.com/t/114607
638+
639+ Assert.Equal(279, twitter.GetTextLengthRemain("©")); // 基本多言語面の絵文字
640+ Assert.Equal(277, twitter.GetTextLengthRemain("©\uFE0E")); // 異字体セレクタ付き (text style)
641+ Assert.Equal(279, twitter.GetTextLengthRemain("©\uFE0F")); // 異字体セレクタ付き (emoji style)
642+ Assert.Equal(278, twitter.GetTextLengthRemain("🍣")); // 拡張面の絵文字
643+ Assert.Equal(279, twitter.GetTextLengthRemain("#⃣")); // 合字で表現される絵文字
644+ Assert.Equal(278, twitter.GetTextLengthRemain("👦\U0001F3FF")); // Emoji modifier 付きの絵文字
645+ Assert.Equal(278, twitter.GetTextLengthRemain("\U0001F3FF")); // Emoji modifier 単体
646+ Assert.Equal(278, twitter.GetTextLengthRemain("👨\u200D🎨")); // ZWJ で結合された絵文字
647+ Assert.Equal(278, twitter.GetTextLengthRemain("🏃\u200D♀\uFE0F")); // ZWJ と異字体セレクタを含む絵文字
648+ }
649+ }
650+
651+ [Fact]
632652 public void GetTextLengthRemain_BrokenSurrogateTest()
633653 {
634654 using (var twitter = new Twitter())
--- a/OpenTween/Api/DataModel/TwitterTextConfiguration.cs
+++ b/OpenTween/Api/DataModel/TwitterTextConfiguration.cs
@@ -38,6 +38,9 @@ namespace OpenTween.Api.DataModel
3838 [DataMember(Name = "defaultWeight")]
3939 public int DefaultWeight { get; set; }
4040
41+ [DataMember(Name = "emojiParsingEnabled")]
42+ public bool EmojiParsingEnabled { get; set; }
43+
4144 [DataMember(Name = "transformedURLLength")]
4245 public int TransformedURLLength { get; set; }
4346
@@ -65,13 +68,14 @@ namespace OpenTween.Api.DataModel
6568
6669 public static TwitterTextConfiguration DefaultConfiguration()
6770 {
68- // 参照: https://github.com/twitter/twitter-text/blob/v2.0.5/config/v2.json
71+ // 参照: https://github.com/twitter/twitter-text/blob/v3.0.0/config/v3.json
6972 return new TwitterTextConfiguration
7073 {
71- Version = 2,
74+ Version = 3,
7275 MaxWeightedTweetLength = 280,
7376 Scale = 100,
7477 DefaultWeight = 200,
78+ EmojiParsingEnabled = true,
7579 TransformedURLLength = 23,
7680 Ranges = new[]
7781 {
--- a/OpenTween/Resources/ChangeLog.txt
+++ b/OpenTween/Resources/ChangeLog.txt
@@ -1,6 +1,8 @@
11 更新履歴
22
33 ==== Ver 2.1.3-dev(2018/xx/xx)
4+ * NEW: 絵文字に関する文字数カウントの新仕様に対応しました
5+ - この変更により「👩‍👧‍👦」「👨‍🎨」など複数の文字で構成される絵文字を入力した場合の文字数制限が緩和されます
46 * FIX: ユーザー情報ダイアログでbioに絵文字を含む場合にハッシュタグやメンションのリンク範囲がずれる不具合を修正
57
68 ==== Ver 2.1.2(2018/09/30)
--- a/OpenTween/Twitter.cs
+++ b/OpenTween/Twitter.cs
@@ -1812,7 +1812,21 @@ namespace OpenTween
18121812 var config = this.TextConfiguration;
18131813 var totalWeight = 0;
18141814
1815+ int GetWeightFromCodepoint(int codepoint)
1816+ {
1817+ foreach (var weightRange in config.Ranges)
1818+ {
1819+ if (codepoint >= weightRange.Start && codepoint <= weightRange.End)
1820+ return weightRange.Weight;
1821+ }
1822+
1823+ return config.DefaultWeight;
1824+ }
1825+
18151826 var urls = TweetExtractor.ExtractUrlEntities(postText).ToArray();
1827+ var emojis = config.EmojiParsingEnabled
1828+ ? TweetExtractor.ExtractEmojiEntities(postText).ToArray()
1829+ : Array.Empty<TwitterEntityEmoji>();
18161830
18171831 var codepoints = postText.ToCodepoints().ToArray();
18181832 var index = 0;
@@ -1826,19 +1840,17 @@ namespace OpenTween
18261840 continue;
18271841 }
18281842
1829- var codepoint = codepoints[index];
1830- var weight = config.DefaultWeight;
1831-
1832- foreach (var weightRange in config.Ranges)
1843+ var emojiEntity = emojis.FirstOrDefault(x => x.Indices[0] == index);
1844+ if (emojiEntity != null)
18331845 {
1834- if (codepoint >= weightRange.Start && codepoint <= weightRange.End)
1835- {
1836- weight = weightRange.Weight;
1837- break;
1838- }
1846+ totalWeight += GetWeightFromCodepoint(codepoints[index]);
1847+ index = emojiEntity.Indices[1];
1848+ continue;
18391849 }
18401850
1841- totalWeight += weight;
1851+ var codepoint = codepoints[index];
1852+ totalWeight += GetWeightFromCodepoint(codepoint);
1853+
18421854 index++;
18431855 }
18441856
Show on old repository browser