Skip to content

Commit

Permalink
Expand 'Blocked Users' feature to include a capabilities option (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpfritz authored Jun 27, 2024
1 parent 6af77db commit 1cc1cf3
Show file tree
Hide file tree
Showing 19 changed files with 805 additions and 32 deletions.
5 changes: 5 additions & 0 deletions doc/YouTube-Doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TagzApp is an open source application with all source code available for contributors and providers to review. We have created multiple 'providers' for various social media services including Mastodon, X, Twitch, Bluesky, and YouTube.

TagzApp polls these services repeatedly in order to present message content on a unified dashboard for moderators and pop-up messages for live stream hosts and viewers to interact with

You can review all of our C# source code for the YouTube provider at: https://github.com/FritzAndFriends/TagzApp/tree/main/src/TagzApp.Providers.YouTubeChat
2 changes: 1 addition & 1 deletion scripts/AddMigration.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet ef migrations add --context TagzApp.Storage.Postgres.TagzAppContext -p ..\src\TagzApp.Storage.Postgres\ -s ..\src\TagzApp.Web %1
dotnet ef migrations add --context TagzApp.Storage.Postgres.TagzAppContext -p ..\src\TagzApp.Storage.Postgres\ -s ..\src\TagzApp.Blazor %1
29 changes: 24 additions & 5 deletions src/TagzApp.Blazor/Components/Admin/Pages/BlockedUsers.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using System.ComponentModel.DataAnnotations
@using TagzApp.ViewModels.Data
@inject IMessagingService _Service
@inject UserManager<TagzAppUser> _UserManager
@inject IModerationRepository _Repository
Expand All @@ -17,10 +18,19 @@
<option value="">Select a provider</option>
@foreach (var provider in Providers)
{
<option value="@provider.Id">@provider.DisplayName</option>
<option value="@provider.Id">@provider.Name</option>
}
</select>
<input id="username" name="username" maxlength="20" placeholder="User Name" @bind="@UserToBlock" />

@* add a select to choose the BlockedUserCapabilities *@
<select name="blockedUserCapabilities" @bind="@BlockedUserCapabilities">
@foreach (var capability in Enum.GetValues(typeof(BlockedUserCapabilities)))
{
<option value="@capability">@capability</option>
}
</select>

<AntiforgeryToken />
<button type="submit" class="btn btn-primary">Block User</button>
</form>
Expand All @@ -35,6 +45,7 @@
<th>Provider</th>
<th>Username</th>
<th>Blocked By</th>
<th>Capabilities</th>
<th>Blocked On</th>
<th>Blocked Until</th>
</tr>
Expand All @@ -54,6 +65,7 @@
<td>@user.Provider</td>
<td>@@@(user.UserName.TrimStart('@'))</td>
<td>@user.BlockingUser</td>
<td>@user.Capabilities.ToString()</td>
<td data-utc="@user.BlockedDate">@user.BlockedDate.ToLocalTime().ToString("d")</td>
<td>@(user.ExpirationDate > DateTime.Now.AddYears(1) ? "No end date" : user.ExpirationDate.Value.Date.ToLocalTime().ToString("d"))</td>
</tr>
Expand All @@ -68,7 +80,7 @@ else

@code {

private IEnumerable<ISocialMediaProvider> Providers { get; set; }
private AvailableProvider[] Providers { get; set; } = [];
private IEnumerable<BlockedUser> Users { get; set; }

[CascadingParameter]
Expand All @@ -80,15 +92,21 @@ else
[SupplyParameterFromForm(FormName = "BlockNewUser", Name = "username")]
private string UserToBlock { get; set; } = string.Empty;

[SupplyParameterFromForm(FormName = "BlockNewUser", Name = "blockedUserCapabilities")]
private BlockedUserCapabilities? BlockedUserCapabilities { get; set; }

private object EditModel = new();

protected override async Task OnInitializedAsync()
{

Providers = _Service.Providers
.OrderBy(x => x.DisplayName).ToArray();
Users = await _Repository.GetBlockedUsers();

BlockedUserCapabilities ??= Common.Models.BlockedUserCapabilities.Moderated;

Providers = _Service.Providers.Where(p => p.Enabled)
.Select(p => new AvailableProvider(p.Id, p.DisplayName))
.ToArray();

}

Expand All @@ -100,13 +118,14 @@ else
var user = await _UserManager.FindByNameAsync(HttpContext.User.Identity.Name);
if (user != null)
{
await _Repository.BlockUser($"@{UserToBlock.TrimStart('@')}", SelectedProvider, user.DisplayName, new DateTimeOffset(new DateTime(2050, 1, 1), TimeSpan.Zero));
await _Repository.BlockUser($"@{UserToBlock.TrimStart('@')}", SelectedProvider, user.DisplayName, new DateTimeOffset(new DateTime(2050, 1, 1), TimeSpan.Zero), this.BlockedUserCapabilities ?? Common.Models.BlockedUserCapabilities.Moderated );
}

// reload the users list
Users = await _Repository.GetBlockedUsers();
SelectedProvider = string.Empty;
UserToBlock = string.Empty;
BlockedUserCapabilities = Common.Models.BlockedUserCapabilities.Moderated;

}

Expand Down
20 changes: 16 additions & 4 deletions src/TagzApp.Blazor/Components/Pages/MessageDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@
@* Add a block user button *@
<li>
Block @Model.AuthorDisplayName on @Model.Provider.ToLowerInvariant().Humanize(LetterCasing.Title)

@* TODO: Wire up the GO button

*@
with @* Add an select for the enum BlockedUserCapabilities *@
<select name="blockedUserCapabilities" @bind="@BlockedUserCapabilities">
@foreach (var capability in Enum.GetValues(typeof(BlockedUserCapabilities)))
{
<option value="@capability">@capability</option>
}
</select>

<input type="submit" name="blockUser" value="Go" />
</li>
</ul>
Expand All @@ -124,6 +129,8 @@

private string ValidationMessage { get; set; }

private BlockedUserCapabilities BlockedUserCapabilities { get; set; } = BlockedUserCapabilities.Moderated;

protected override async Task OnInitializedAsync()
{

Expand All @@ -139,7 +146,12 @@

var user = await UserManager.FindByNameAsync(HttpContext.User.Identity.Name);

await ModerationRepository.BlockUser(Model.AuthorUserName, Model.Provider, user.DisplayName, new DateTimeOffset(new DateTime(2050, 1, 1), TimeSpan.Zero));
await ModerationRepository.BlockUser(
Model.AuthorUserName,
Model.Provider,
user.DisplayName,
new DateTimeOffset(new DateTime(2050, 1, 1), TimeSpan.Zero),
BlockedUserCapabilities);
ValidationMessage = $"User {Model.AuthorUserName} has been blocked on {Model.Provider.ToLowerInvariant().Humanize(LetterCasing.Title)}";

}
Expand Down
8 changes: 7 additions & 1 deletion src/TagzApp.Blazor/Hubs/ModerationHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ public async Task<IEnumerable<ModerationContentModel>> GetFilteredContentByTag(s
[ModerationState.Pending, ModerationState.Approved, ModerationState.Rejected] :
new[] { Enum.Parse<ModerationState>(state) };

var results = (await _Service.GetFilteredContentByTag(tag, providers, states))
var hiddenUsers = (await _Repository.GetBlockedUsers())
.Where(b => b.Capabilities == BlockedUserCapabilities.Hidden)
.ToArray();

var results = (await _Service.GetFilteredContentByTag(tag, providers, states, 200))
.Where(c => !hiddenUsers.Any(h => h.Provider.Equals(c.Item1.Provider, StringComparison.InvariantCultureIgnoreCase) && h.UserName.Equals(c.Item1.Author.UserName, StringComparison.InvariantCultureIgnoreCase)))
.Take(100)
.Select(c => ModerationContentModel.ToModerationContentModel(c.Item1, c.Item2))
.ToArray();
Console.WriteLine($"Found {results.Length} results for {tag} with {providers.Length} providers and {states.Length} states");
Expand Down
2 changes: 1 addition & 1 deletion src/TagzApp.Common/IModerationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface IModerationRepository
/// <param name="userName">The moderator who is blocking the user</param>
/// <param name="expirationDate">The date the block expires</param>
/// <returns></returns>
Task BlockUser(string userId, string provider, string userName, DateTimeOffset expirationDate);
Task BlockUser(string userId, string provider, string userName, DateTimeOffset expirationDate, BlockedUserCapabilities capabilities);

/// <summary>
/// Unblock a user
Expand Down
10 changes: 10 additions & 0 deletions src/TagzApp.Common/Models/BlockedUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ public class BlockedUser
/// </summary>
public DateTimeOffset? ExpirationDate { get; set; }

public BlockedUserCapabilities Capabilities { get; set; } = BlockedUserCapabilities.Moderated;

}

public enum BlockedUserCapabilities
{

Moderated = 1,
Hidden = 2

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1cc1cf3

Please sign in to comment.