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

Initial connection to Bluesky working #350

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/TagzApp.Blazor.Client/Components/Admin/Bluesky.Config.Ui.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@using System.ComponentModel.DataAnnotations
@using System.Text.Json
<UiProviderConfig ProviderName="Bluesky" Health="@Health" ProviderIconCssClass="icon-bluesky">

<EditForm Model="Model" OnValidSubmit="SaveConfig">
<AntiforgeryToken />
<ValidationSummary />
<dl>
<dt><label for="Enabled">Enabled:</label></dt>
<dd>
<InputCheckbox name="Enabled" @bind-Value="Model.Enabled" />
</dd>
</dl>

<button type="submit" class="btn btn-primary">Save</button>

</EditForm>

</UiProviderConfig>

@code {

[Parameter, EditorRequired]
public ISocialMediaProvider Provider { get; set; } = null!;

public (SocialMediaStatus Status, string Message) Health { get; set; } = (SocialMediaStatus.Unknown, string.Empty);


public ViewModel Model { get; set; } = new();

protected override async Task OnParametersSetAsync()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

var headers = providerConfiguration.GetConfigurationByKey("DefaultHeaders");
var headerDictionary = string.IsNullOrEmpty(headers) ? new() : JsonSerializer.Deserialize<Dictionary<string, string>>(headers);

Model = new ViewModel
{
Enabled = string.IsNullOrEmpty(providerConfiguration.GetConfigurationByKey("Enabled")) ? false : bool.Parse(providerConfiguration.GetConfigurationByKey("Enabled"))
};

Health = await Provider.GetHealth();

await base.OnParametersSetAsync();

}

private async Task SaveConfig()
{

var providerConfiguration = await Provider.GetConfiguration(ConfigureTagzAppFactory.Current);

providerConfiguration.SetConfigurationByKey("Enabled", Model.Enabled.ToString());

await Provider.SaveConfiguration(ConfigureTagzAppFactory.Current, providerConfiguration);

}

public class ViewModel
{

public bool Enabled { get; set; }


}


}
82 changes: 46 additions & 36 deletions src/TagzApp.Blazor.Client/Components/ModerationMessage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,54 @@
@inject NavigationManager NavigationManager

<article @ref="thisArticle" data-providerid="@Content.ProviderId"
class="modMessage @AdditionalClasses @CssClass"
@onmouseover="() => DisplayModeration(true)"
@onmouseleave="() => DisplayModeration(false)"> @* @onclick="() => OnContentSelected?.InvokeAsync(Content)"> *@
class="modMessage @AdditionalClasses @CssClass"
@onmouseover="() => DisplayModeration(true)"
@onmouseleave="() => DisplayModeration(false)">
@* @onclick="() => OnContentSelected?.InvokeAsync(Content)"> *@

@if (ShowModerationActions)
{
<div id="moderationAction">
<i class="bi bi-check2 approve" title="Approve this content" @onclick="async () => await Moderate(ModerationState.Approved)"></i>
<i class="bi bi-x-circle-fill reject" title="Reject this content" @onclick="async () => await Moderate(ModerationState.Rejected)"></i>
<i class="bi bi-journal-text more"
@onclick="@(() => NavigationManager.NavigateTo($"/MessageDetails/{Content.Provider}/{Content.ProviderId}"))"
title="More Actions"></i>
<i class="bi bi-journal-text more"
@onclick="@(() => NavigationManager.NavigateTo($"/MessageDetails/{Content.Provider}/{Content.ProviderId}"))"
title="More Actions"></i>
</div>
}

<img class="ProfilePicture"
src="@Content.AuthorProfileImageUri"
alt="@Content.AuthorDisplayName"
onerror="this.src='/img/user.jpg';" />

<div class="byline">
<div class="author">@Content.AuthorDisplayName <i class="autoMod"></i></div>
<div class="authorUserName" title="@Content.AuthorUserName">
@if (!Content.AuthorUserName.TrimStart('@').Equals(Content.AuthorDisplayName)) {
@Content.AuthorUserName
}
</div>
<img class="ProfilePicture"
src="@Content.AuthorProfileImageUri"
alt="@Content.AuthorDisplayName"
onerror="this.src='/img/user.jpg';" />

<div class="byline">
<div class="author">@Content.AuthorDisplayName <i class="autoMod"></i></div>
<div class="authorUserName" title="@Content.AuthorUserName">
@if (!Content.AuthorUserName.TrimStart('@').Equals(Content.AuthorDisplayName))
{
@Content.AuthorUserName
}
</div>
</div>

<i class="provider bi @MapProviderToIcon(Content.Provider)"></i>

<div class="time">
<div>@Content.Timestamp.ToLocalTime().ToString("d") @Content.Timestamp.ToLocalTime().ToString("t")</div>
<div class="autoModReason">@if (!string.IsNullOrEmpty(AutomodReason)){
<div class="autoModReason">
@if (!string.IsNullOrEmpty(AutomodReason))
{
<text>AI Reason ( @AutomodReason )</text>
}</div>
}
</div>
</div>

<div class="content">@((MarkupString)(Content.Content.FormatContentWithEmotes()))</div>

@* MISSING THE PREVIEW IMAGE *@
@if (Content.Content.PreviewCard is not null) {
@if (Content.Content.PreviewCard is not null)
{

if (Content.Content.PreviewCard.ImageUri.ToString().EndsWith(".mp4"))
{
Expand All @@ -70,7 +76,9 @@
[Parameter]
public ModerationContentModel Content { get; set; }

private string AutomodReason { get
private string AutomodReason
{
get
{

var outText = Content?.Reason ?? string.Empty;
Expand Down Expand Up @@ -122,7 +130,7 @@
(ModerationState.Approved, _) => CSS_APPROVED,
(ModerationState.Rejected, "AZURE-CONTENTSAFETY") => CSS_AZURECONTENTSAFETY,
(ModerationState.Rejected, _) => CSS_REJECTED,
(_,_) => ""
(_, _) => ""
};

async Task Moderate(ModerationState action)
Expand All @@ -144,13 +152,14 @@

StateHasChanged();

await ModerationPage.Moderate(new ModerationAction {
Provider = Content.Provider,
ProviderId = Content.ProviderId,
PreviousState = prevState,
State = action,
Timestamp = DateTimeOffset.Now
});
await ModerationPage.Moderate(new ModerationAction
{
Provider = Content.Provider,
ProviderId = Content.ProviderId,
PreviousState = prevState,
State = action,
Timestamp = DateTimeOffset.Now
});

}

Expand All @@ -160,7 +169,7 @@

if (show)
await JSRuntime.InvokeVoidAsync("window.WaterfallUi.PauseNewContent", 5000);
else
else
await JSRuntime.InvokeVoidAsync("window.WaterfallUi.ResumeContent");
}

Expand All @@ -181,11 +190,12 @@

public static string MapProviderToIcon(string provider) =>
provider?.ToLowerInvariant().Trim() switch
{
"twitter" => "bi-twitter-x",
"website" => "bi-globe2",
"youtube-chat" => "bi-youtube",
{
"bluesky" => "icon-bluesky",
"twitter" => "bi-twitter-x",
"website" => "bi-globe2",
"youtube-chat" => "bi-youtube",
_ => $"bi-{provider?.ToLowerInvariant().Trim() ?? "question-circle"}"
};
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
public static string MapProviderToIcon(string provider) =>
provider?.ToLowerInvariant().Trim() switch
{
"bluesky" => "icon-bluesky",
"twitter" => "bi-twitter-x",
"website" => "bi-globe2",
"youtube-chat" => "bi-youtube",
Expand Down
12 changes: 9 additions & 3 deletions src/TagzApp.Blazor/Components/Admin/Pages/GenericProvider.razor
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
@using TagzApp.Providers.TwitchChat
@using TagzApp.Providers.Bluesky
@using TagzApp.Providers.TwitchChat
@using TagzApp.Providers.Mastodon
@using TagzApp.Blazor.Client.Components.Admin

@typeparam TProvider

@switch (Provider.GetType().Name)
{
case nameof(TwitchChatProvider):
case nameof(BlueskyProvider):
{
<TwitchChat_Config_Ui Provider="@Provider" />
<Bluesky_Config_Ui Provider="@Provider" />
break;
}
case nameof(MastodonProvider):
{
<Mastodon_Config_Ui Provider="@Provider" />
break;
}
case nameof(TwitchChatProvider):
{
<TwitchChat_Config_Ui Provider="@Provider" />
break;
}
default:
{
<p>Unknown provider type: @Provider?.GetType().Name</p>
Expand Down
6 changes: 4 additions & 2 deletions src/TagzApp.Blazor/Service_Providers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TagzApp.Providers.Mastodon;
using TagzApp.Providers.Bluesky;
using TagzApp.Providers.Mastodon;
using TagzApp.Providers.TwitchChat;

namespace TagzApp.Blazor;
Expand All @@ -8,8 +9,9 @@ public static class Service_Providers

private static readonly List<IConfigureProvider> _Providers = new()
{
new StartBluesky(),
new StartMastodon(),
new StartTwitchChat(),
new StartMastodon()
};

public static async Task<IServiceCollection> AddTagzAppProviders(this IServiceCollection services)
Expand Down
1 change: 1 addition & 0 deletions src/TagzApp.Blazor/TagzApp.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\TagzApp.Common\TagzApp.Common.csproj" />
<ProjectReference Include="..\TagzApp.Blazor.Client\TagzApp.Blazor.Client.csproj" />
<ProjectReference Include="..\TagzApp.Providers.Bluesky\TagzApp.Providers.Bluesky.csproj" />
<ProjectReference Include="..\TagzApp.Providers.Mastodon\TagzApp.Providers.Mastodon.csproj" />
<ProjectReference Include="..\TagzApp.Providers.TwitchChat\TagzApp.Providers.TwitchChat.csproj" />
<ProjectReference Include="..\TagzApp.Security\TagzApp.Security.csproj" />
Expand Down
10 changes: 10 additions & 0 deletions src/TagzApp.Blazor/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,13 @@ a {
width: 10em;
margin-right: 2em;
}

.icon-bluesky {
width: 23px;
height: 20px;
margin-top: 4px;
display: inline-block;
background-image: url(/img/Bluesky_Logo.svg);
background-size: contain;
filter: brightness(0) invert(1);
}
4 changes: 4 additions & 0 deletions src/TagzApp.Blazor/wwwroot/img/Bluesky_Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/TagzApp.Providers.Bluesky/BlueskyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace TagzApp.Providers.Bluesky;

public class BlueskyConfiguration : IProviderConfiguration
{
public string Name => "Bluesky";

public string Description => "The Bluesky social network served by the AT Protocol";

public bool Enabled { get; set; }

public string[] Keys => new string[] { };

public string GetConfigurationByKey(string key)
{
if (key == "Enabled")
{
return Enabled.ToString();
}

return string.Empty;

}

public void SetConfigurationByKey(string key, string value)
{
if (key == "Enabled")
{
Enabled = bool.Parse(value);
}
}
}
Loading
Loading