From f8a67f23883fb7a733d761e4830259bcd7c57875 Mon Sep 17 00:00:00 2001 From: Yusuf Praditya <47532266+yusufpraditya@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:58:24 +0700 Subject: [PATCH] Refactor --- MyPractice/Youtube/Server.cs | 2 +- MyPractice/Youtube/Subscriber.cs | 4 ++-- MyPractice/Youtube/Youtuber.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MyPractice/Youtube/Server.cs b/MyPractice/Youtube/Server.cs index 6d96fb1..98319fc 100644 --- a/MyPractice/Youtube/Server.cs +++ b/MyPractice/Youtube/Server.cs @@ -29,7 +29,7 @@ public void UploadFinished(object? sender, DataEventArgs e) private void SendNotification() { - if (notificationHandler != null) notificationHandler.Invoke(this, data); + notificationHandler?.Invoke(this, data); } public void ViewReached(object? sender, DataEventArgs e) diff --git a/MyPractice/Youtube/Subscriber.cs b/MyPractice/Youtube/Subscriber.cs index 6944e6a..50f99c7 100644 --- a/MyPractice/Youtube/Subscriber.cs +++ b/MyPractice/Youtube/Subscriber.cs @@ -27,9 +27,9 @@ public void WatchVideo(int videoIndex, int times) { _server.data.viewCount.Add(videoIndex, times); } - if (_server.data.viewCount.GetValueOrDefault(videoIndex) >= _trendingThreshold && trendingHandler != null) + if (_server.data.viewCount.GetValueOrDefault(videoIndex) >= _trendingThreshold) { - trendingHandler.Invoke(this, _server.data); + trendingHandler?.Invoke(this, _server.data); } } else diff --git a/MyPractice/Youtube/Youtuber.cs b/MyPractice/Youtube/Youtuber.cs index deaf51b..182a454 100644 --- a/MyPractice/Youtube/Youtuber.cs +++ b/MyPractice/Youtube/Youtuber.cs @@ -29,7 +29,7 @@ private void UploadToServer(int videoIndex, string videoTitle) { _server.data.videoIndex = videoIndex; _server.data.videoTitle = videoTitle; - if (uploadHandler != null) uploadHandler.Invoke(this, _server.data); + uploadHandler?.Invoke(this, _server.data); } public void WatchVideo(int videoIndex, int times) @@ -49,9 +49,9 @@ public void WatchVideo(int videoIndex, int times) { _server.data.viewCount.Add(videoIndex, times); } - if (_server.data.viewCount.GetValueOrDefault(videoIndex) >= _server.TrendingThreshold && trendingHandler != null) + if (_server.data.viewCount.GetValueOrDefault(videoIndex) >= _server.TrendingThreshold) { - trendingHandler.Invoke(this, _server.data); + trendingHandler?.Invoke(this, _server.data); } } }