Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing some cleanup of all the Warnings that litter the build - Part 2 #186

Merged
Merged
11 changes: 5 additions & 6 deletions src/TagzApp.Providers.Mastodon/MastodonProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Microsoft.Extensions.Logging;
using System.Net.Http.Json;
using System.Text.Json;
using System.Net.Http.Json;
using System.Web;
using TagzApp.Common.Models;

using Microsoft.Extensions.Logging;

namespace TagzApp.Providers.Mastodon;

Expand Down Expand Up @@ -52,7 +51,7 @@ public async Task<IEnumerable<Content>> GetContentForHashtag(Hashtag tag, DateTi
return Enumerable.Empty<Content>();
}

NewestId = messages.OrderByDescending(m => m.id).First().id;
NewestId = messages!.OrderByDescending(m => m.id).First().id;

var baseServerAddress = _HttpClient.BaseAddress.Host.ToString();

Expand All @@ -66,7 +65,7 @@ public async Task<IEnumerable<Content>> GetContentForHashtag(Hashtag tag, DateTi
Author = new Creator
{
DisplayName = m.account!.display_name,
UserName = m.account.acct + (m.account.acct.Contains("@") ? "" : $"@{baseServerAddress}" ),
UserName = m.account.acct + (m.account.acct.Contains("@") ? "" : $"@{baseServerAddress}"),
ProviderId = Id,
ProfileImageUri = new Uri(m.account.avatar_static),
ProfileUri = new Uri(m.account.url)
Expand Down
15 changes: 9 additions & 6 deletions src/TagzApp.Providers.Mastodon/Messages.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Text.Json;

namespace TagzApp.Providers.Mastodon;

// TODO: Check for CS8618 -- Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public class Messages
{
public Message[]? ReceivedMessages { get; set; }
Expand Down Expand Up @@ -37,7 +37,7 @@ public class Message
public Card? card { get; set; }
public object? poll { get; set; }

public static MediaAttachment GetMediaAttachment(string mediaJson)
public static MediaAttachment? GetMediaAttachment(string mediaJson)
{

var rawJson = mediaJson.Substring(mediaJson.IndexOf('{'));
Expand All @@ -57,7 +57,9 @@ public class Account
public string display_name { get; set; } = string.Empty;
public bool locked { get; set; }
public bool bot { get; set; }

public object discoverable { get; set; }

public bool group { get; set; }
public DateTime created_at { get; set; }
public string note { get; set; } = string.Empty;
Expand Down Expand Up @@ -148,12 +150,12 @@ public class MediaAttachment
public static implicit operator Common.Models.Card(MediaAttachment mediaAttachment)
{

if (mediaAttachment is null) return null;
if (mediaAttachment is null) return mediaAttachment!;

return new Common.Models.Card
{
ImageUri = new Uri(mediaAttachment.url),
AltText = mediaAttachment.description?.ToString(),
AltText = mediaAttachment.description?.ToString() ?? "",
Height = mediaAttachment.meta?.original?.height ?? 0,
Width = mediaAttachment.meta?.original?.width ?? 0
};
Expand Down Expand Up @@ -183,3 +185,4 @@ public class Small
public string size { get; set; }
public float aspect { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2 changes: 1 addition & 1 deletion src/TagzApp.Providers.Mastodon/StartMastodon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public IServiceCollection RegisterServices(IServiceCollection services, IConfigu
services.AddTransient<ISocialMediaProvider, MastodonProvider>();
return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TagzApp.Common.Models;

namespace TagzApp.UnitTest.InMemoryMessaging.GivenOneSubscriber;
namespace TagzApp.UnitTest.InMemoryMessaging.GivenOneSubscriber;
public class WhenPublishingMessages
{

Expand Down Expand Up @@ -28,7 +26,7 @@ public async Task ShouldPublishMessage()
{

// Arrange
Content published = null;
Content published = null!;
_Sut.SubscribeToContent(_Tag, (content) => published = content);

// Act
Expand Down
Loading