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

Fixed notifications for moderation #148

Merged
merged 7 commits into from
Aug 31, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./src/TagzApp.WebTest
timeout-minutes: 10
container:
image: mcr.microsoft.com/playwright/dotnet:v1.37.0-jammy
image: mcr.microsoft.com/playwright/dotnet:v1.37.1-jammy
options: --ipc=host
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion src/TagzApp.Common/INotifyNewMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TagzApp.Web.Services;

public interface INotifyNewMessages
{
void Notify(string hashtag, Content content);
void NotifyNewContent(string hashtag, Content content);

void NotifyApprovedContent(string hashtag, Content content, ModerationAction action);

Expand Down
4 changes: 2 additions & 2 deletions src/TagzApp.Storage.Postgres/PostgresMessagingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task AddHashtagToWatch(string tag)
_Service.SubscribeToContent(new Hashtag() { Text = tag },
c =>
{
_NotifyNewMessages.Notify(Hashtag.ClearFormatting(c.HashtagSought), c);
_NotifyNewMessages.NotifyNewContent(Hashtag.ClearFormatting(c.HashtagSought), c);
});


Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
_Service.SubscribeToContent(new Hashtag() { Text = tag },
c =>
{
_NotifyNewMessages.Notify(Hashtag.ClearFormatting(c.HashtagSought), c);
_NotifyNewMessages.NotifyNewContent(Hashtag.ClearFormatting(c.HashtagSought), c);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task Moderate(string userId, string provider, string providerId, Mo

var outContent = (Content)content;
notify(Hashtag.ClearFormatting(content.HashtagSought), outContent, (ModerationAction)moderationAction);
if (state != ModerationState.Rejected) _Notifier.Notify(Hashtag.ClearFormatting(content.HashtagSought), outContent);
if (state != ModerationState.Rejected) _Notifier.NotifyNewContent(Hashtag.ClearFormatting(content.HashtagSought), outContent);

}
}
4 changes: 2 additions & 2 deletions src/TagzApp.Web/Pages/Moderation.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div class="row">
<div class="col-md-12">
<h1 class="text-center">Moderate Content for TagzApp (@Model.Tags.Select(t => $"#{t}").First())</h1>
<h1 class="text-center">Moderate Content for TagzApp (@(Model.Tags.Select(t => $"#{t}").FirstOrDefault() ?? ""))</h1>
</div>
</div>

Expand All @@ -25,7 +25,7 @@
<script src="~/js/masonry.js" asp-append-version="true"></script>
<script>

window.TagzApp.ListenForModerationContent("@Model.Tags.First()");
window.TagzApp.ListenForModerationContent("@Model.Tags.FirstOrDefault()");

window.onload = window.Masonry.resizeAllGridItems();
window.addEventListener("resize", Masonry.resizeAllGridItems);
Expand Down
2 changes: 1 addition & 1 deletion src/TagzApp.Web/Services/InMemoryMessagingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Task AddHashtagToWatch(string tag)
c =>
{
_Content[c.HashtagSought.TrimStart('#')].Add(c);
_NotifyNewMessages.Notify(Hashtag.ClearFormatting(c.HashtagSought), c);
_NotifyNewMessages.NotifyNewContent(Hashtag.ClearFormatting(c.HashtagSought), c);
//_Logger.LogInformation($"Message found for tag '{c.HashtagSought}': {c.Text}");
});

Expand Down
25 changes: 21 additions & 4 deletions src/TagzApp.Web/Services/SignalRNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@ public SignalRNotifier(IHubContext<MessageHub> hubContext, IHubContext<Moderatio
_ModerationEnabled = configuration.GetValue<bool>("ModerationEnabled", false);
}

public void Notify(string hashtag, Content content)
public void NotifyNewContent(string hashtag, Content content)
{

_HubContext.Clients
.Group(hashtag)
.SendAsync("NewWaterfallMessage", (ContentModel)content);
if (_ModerationEnabled)
{

_ModContext.Clients
.Group(hashtag)
.NewWaterfallMessage((ContentModel)content);

}
else
{

_HubContext.Clients
.Group(hashtag)
.SendAsync("NewWaterfallMessage", (ContentModel)content);

}

}

Expand All @@ -35,6 +48,10 @@ public void NotifyApprovedContent(string hashtag, Content content, ModerationAct
.Group(hashtag)
.NewApprovedMessage(ModerationContentModel.ToModerationContentModel(content, action));

_HubContext.Clients
.Group(hashtag)
.SendAsync("NewWaterfallMessage", (ContentModel)content);

}

public void NotifyRejectedContent(string hashtag, Content content, ModerationAction action)
Expand Down
13 changes: 11 additions & 2 deletions src/TagzApp.WebTest/Fixtures/PlaywrightFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public PlaywrightFixture(IMessageSink output) : base(output)

private readonly Guid _Uniqueid = Guid.NewGuid();

protected override IHost CreateHost(IHostBuilder builder)
public override LogLevel MinimumLogLevel => LogLevel.Warning;

protected override IHost CreateHost(IHostBuilder builder)
{
//ServicesExtensions.SocialMediaProviders = new List<IConfigureProvider> { new StartStubSocialMediaProvider() };
builder.AddTestConfiguration();
builder.AddTestConfiguration(jsonConfiguration: CONFIGURATION);
builder.UseOnlyStubSocialMediaProvider();
builder.UseOnlyInMemoryService();
builder.UseUniqueDb(_Uniqueid);
Expand All @@ -34,6 +36,13 @@ protected override IHost CreateHost(IHostBuilder builder)
return host;
}

private const string CONFIGURATION = """
{
"ModerationEnabled": "false"
}
""";


[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize",
Justification = "Base class calls SuppressFinalize")]
public async override ValueTask DisposeAsync()
Expand Down
15 changes: 12 additions & 3 deletions src/TagzApp.WebTest/Tests/ModalWebTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ public ModalFixture(IMessageSink output) : base(output)

private readonly Guid _Uniqueid = Guid.NewGuid();

protected override IHost CreateHost(IHostBuilder builder)
public override LogLevel MinimumLogLevel => LogLevel.Warning;

protected override IHost CreateHost(IHostBuilder builder)
{
// ServicesExtensions.SocialMediaProviders = new List<IConfigureProvider> { new StartStubSocialMediaProvider() };
builder.AddTestConfiguration();
// ServicesExtensions.SocialMediaProviders = new List<IConfigureProvider> { new StartStubSocialMediaProvider() };
builder.AddTestConfiguration(jsonConfiguration: CONFIGURATION);
builder.UseOnlyStubSocialMediaProvider();
builder.UseOnlyInMemoryService();
builder.UseUniqueDb(_Uniqueid);
return base.CreateHost(builder);
}

private const string CONFIGURATION = """
{
"ModerationEnabled": "false"
}
""";


// Temp hack to see if it is a timing issue in github actions
public async override Task InitializeAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public BaseModerationFixture(IMessageSink output) : base(output)

private readonly Guid _Uniqueid = Guid.NewGuid();

public override LogLevel MinimumLogLevel => LogLevel.Warning;

protected override IHost CreateHost(IHostBuilder builder)
{

Expand Down
7 changes: 7 additions & 0 deletions src/TagzApp.WebTest/appsettings.test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.EntityFrameworkCore": "Error"
}
},
"TestHostStartDelay": 0,
"ModerationEnabled": "false"

}