OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Thumbnail / Services / SimpleThumbnailService.cs
index a1b608b..8de0cd5 100644 (file)
@@ -19,6 +19,8 @@
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable
+
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -27,6 +29,7 @@ using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading.Tasks;
+using OpenTween.Models;
 
 namespace OpenTween.Thumbnail.Services
 {
@@ -37,34 +40,21 @@ namespace OpenTween.Thumbnail.Services
     {
         protected Regex regex;
         protected string thumb_replacement;
-        protected string fullsize_replacement;
-
-        protected readonly HttpClient http;
+        protected string? fullsize_replacement;
 
         public SimpleThumbnailService(string pattern, string replacement)
-            : this(null, pattern, replacement, null)
-        {
-        }
-
-        public SimpleThumbnailService(HttpClient http, string pattern, string replacement)
-            : this(http, pattern, replacement, null)
+            : this(pattern, replacement, null)
         {
         }
 
-        public SimpleThumbnailService(string pattern, string replacement, string file_replacement)
-            : this(null, pattern, replacement, file_replacement)
+        public SimpleThumbnailService(string pattern, string replacement, string? file_replacement)
         {
-        }
-
-        public SimpleThumbnailService(HttpClient http, string pattern, string replacement, string file_replacement)
-        {
-            this.http = http ?? MyCommon.CreateHttpClient();
             this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
             this.thumb_replacement = replacement;
             this.fullsize_replacement = file_replacement;
         }
 
-        public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
+        public override Task<ThumbnailInfo?> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
         {
             return Task.Run(() =>
             {
@@ -73,20 +63,18 @@ namespace OpenTween.Thumbnail.Services
 
                 return new ThumbnailInfo
                 {
-                    ImageUrl = url,
-                    ThumbnailUrl = thumbnailUrl,
+                    MediaPageUrl = url,
+                    ThumbnailImageUrl = thumbnailUrl,
                     TooltipText = null,
                     FullSizeImageUrl = ReplaceUrl(url, this.fullsize_replacement)
                 };
             }, token);
         }
 
-        protected string ReplaceUrl(string url)
-        {
-            return ReplaceUrl(url, this.thumb_replacement);
-        }
+        protected string? ReplaceUrl(string url)
+            => this.ReplaceUrl(url, this.thumb_replacement);
 
-        protected string ReplaceUrl(string url, string replacement)
+        protected string? ReplaceUrl(string url, string? replacement)
         {
             if (replacement == null) return null;
             var match = this.regex.Match(url);