From bef06936aa7a2c6e251110d06984971238718672 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Sun, 20 May 2018 04:14:29 +0900 Subject: [PATCH] =?utf8?q?=E6=8A=95=E7=A8=BF=E6=AC=84=E3=81=AB=E3=83=A1?= =?utf8?q?=E3=83=B3=E3=82=B7=E3=83=A7=E3=83=B3=E4=BB=A5=E5=A4=96=E3=81=AE?= =?utf8?q?=E6=96=87=E5=AD=97=E5=88=97=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C?= =?utf8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AF?= =?utf8?q?=E6=8A=95=E7=A8=BF=E6=99=82=E3=81=AB=E8=AD=A6=E5=91=8A=E3=83=80?= =?utf8?q?=E3=82=A4=E3=82=A2=E3=83=AD=E3=82=B0=E3=82=92=E8=A1=A8=E7=A4=BA?= =?utf8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- OpenTween.Tests/TweenMainTest.cs | 9 ++++++++ OpenTween/Properties/Resources.Designer.cs | 10 +++++++++ OpenTween/Properties/Resources.en.resx | 4 ++++ OpenTween/Properties/Resources.resx | 4 ++++ OpenTween/Resources/ChangeLog.txt | 1 + OpenTween/Tween.cs | 35 ++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+) diff --git a/OpenTween.Tests/TweenMainTest.cs b/OpenTween.Tests/TweenMainTest.cs index 6843c847..576dd64f 100644 --- a/OpenTween.Tests/TweenMainTest.cs +++ b/OpenTween.Tests/TweenMainTest.cs @@ -165,5 +165,14 @@ namespace OpenTween var expected = "#てすと @TwitterAPI " + Environment.NewLine + " http://twitter.com/"; Assert.Equal(expected, TweenMain.CreateRetweetUnofficial(html, true)); } + + [Theory] + [InlineData("", true)] + [InlineData("hoge", false)] + [InlineData("@twitterapi ", true)] + [InlineData("@twitterapi @opentween ", true)] + [InlineData("@twitterapi @opentween hoge", false)] + public void TextContainsOnlyMentions_Test(string input, bool expected) + => Assert.Equal(expected, TweenMain.TextContainsOnlyMentions(input)); } } diff --git a/OpenTween/Properties/Resources.Designer.cs b/OpenTween/Properties/Resources.Designer.cs index 31f42682..d607e44d 100644 --- a/OpenTween/Properties/Resources.Designer.cs +++ b/OpenTween/Properties/Resources.Designer.cs @@ -1832,6 +1832,16 @@ namespace OpenTween.Properties { } /// + /// この内容で投稿してもよろしいですか? + ///{0} に類似しているローカライズされた文字列を検索します。 + /// + internal static string PostConfirmText { + get { + return ResourceManager.GetString("PostConfirmText", resourceCulture); + } + } + + /// /// 投稿できる文字数の上限を越えています。強制的に投稿しますか? に類似しているローカライズされた文字列を検索します。 /// internal static string PostLengthOverMessage1 { diff --git a/OpenTween/Properties/Resources.en.resx b/OpenTween/Properties/Resources.en.resx index 08914457..296627c6 100644 --- a/OpenTween/Properties/Resources.en.resx +++ b/OpenTween/Properties/Resources.en.resx @@ -1158,4 +1158,8 @@ Existing setting files are copied to {1}. To use Bitly, you must perform the Bitly authentication in settings dialog. + + Are you sure to you want to post this text? +{0} + \ No newline at end of file diff --git a/OpenTween/Properties/Resources.resx b/OpenTween/Properties/Resources.resx index 74501624..ec56fc3f 100644 --- a/OpenTween/Properties/Resources.resx +++ b/OpenTween/Properties/Resources.resx @@ -1216,4 +1216,8 @@ Bitlyを使用するには設定画面で認証情報を入力する必要があります + + この内容で投稿してもよろしいですか? +{0} + \ No newline at end of file diff --git a/OpenTween/Resources/ChangeLog.txt b/OpenTween/Resources/ChangeLog.txt index 0d0b95dd..9150840f 100644 --- a/OpenTween/Resources/ChangeLog.txt +++ b/OpenTween/Resources/ChangeLog.txt @@ -3,6 +3,7 @@ ==== Ver 1.4.2-dev(xxxx/xx/xx) * NEW: システムのタイムゾーンの変更を検知して、ツイートの投稿日時などの表示を新しいタイムゾーンに同期します * NEW: 5月中旬に予定されている引用ツイートに関する Twitter API の仕様変更に対応 + * NEW: リプライ送信時にリプライ以外何も入力されていない状態であった場合は警告のダイアログを表示します * FIX: 動画のサムネイル画像に「URLをコピー」を行うとエラーが発生する不具合を修正 * FIX: pic.twitter.com のサムネイル画像をHTTPS接続で取得するように修正 diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index a6dcda40..de961c73 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -2101,6 +2101,15 @@ namespace OpenTween } } + if (TextContainsOnlyMentions(this.StatusText.Text)) + { + var message = string.Format(Properties.Resources.PostConfirmText, this.StatusText.Text); + var ret = MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); + + if (ret != DialogResult.OK) + return; + } + var inReplyToStatusId = this.inReplyTo?.Item1; var inReplyToScreenName = this.inReplyTo?.Item2; _history[_history.Count - 1] = new StatusTextHistory(StatusText.Text, inReplyToStatusId, inReplyToScreenName); @@ -4751,6 +4760,32 @@ namespace OpenTween } /// + /// メンション以外の文字列が含まれていないテキストであるか判定します + /// + internal static bool TextContainsOnlyMentions(string text) + { + var mentions = TweetExtractor.ExtractMentionEntities(text).OrderBy(x => x.Indices[0]); + var startIndex = 0; + + foreach (var mention in mentions) + { + var textPart = text.Substring(startIndex, mention.Indices[0] - startIndex); + + if (!string.IsNullOrWhiteSpace(textPart)) + return false; + + startIndex = mention.Indices[1]; + } + + var textPartLast = text.Substring(startIndex); + + if (!string.IsNullOrWhiteSpace(textPartLast)) + return false; + + return true; + } + + /// /// 投稿時に auto_populate_reply_metadata オプションによって自動で追加されるメンションを除去します /// private string RemoveAutoPopuratedMentions(string statusText, out long[] autoPopulatedUserIds) -- 2.11.0