-
-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/notification settings #486
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cb9aa43
change /members back button to javascript back
NielsPilgaard 05a455f
Delete 02-group-notifications.md
NielsPilgaard 8e1099e
add padding to group tabs to fix text being cropped
NielsPilgaard 39ae90e
fix possible NRE
NielsPilgaard 2507cb7
add chat notification pref
NielsPilgaard 2eba966
migrations
NielsPilgaard c3335ee
Update ChatNotificationServiceTests.cs
NielsPilgaard bfe8e46
Update Program.cs
NielsPilgaard 3a6c46d
Create WebApplicationBuilderExtensions.cs
NielsPilgaard db4b56b
Update GroupMembership.cs
NielsPilgaard 2fbca84
Update SendMessageConsumer.cs
NielsPilgaard 59d7c2d
Update ChatNotificationService.cs
NielsPilgaard 8874f97
Create NotificationSettingsService.cs
NielsPilgaard c1f5334
Create Notifications.razor
NielsPilgaard 8c747f5
Update TopBar.razor
NielsPilgaard d4f5bae
Update ChatNotificationServiceTests.cs
NielsPilgaard 5fc39eb
address review comments
NielsPilgaard 487fee9
Update NotificationSettingsService.cs
NielsPilgaard f839c8f
Update ChatNotificationService.cs
NielsPilgaard 2ea8568
Update ChatNotificationPreference.cs
NielsPilgaard 21b834e
Update src/web/Jordnaer/Pages/Settings/Notifications.razor
NielsPilgaard 28935b2
Update ChatNotificationServiceTests.cs
NielsPilgaard 21f08b7
Merge branch 'feature/notification-settings' of https://github.com/Ni…
NielsPilgaard d1604db
Update Notifications.razor
NielsPilgaard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/shared/Jordnaer.Shared/Database/Enums/ChatNotificationPreference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using NetEscapades.EnumGenerators; | ||
|
|
||
| namespace Jordnaer.Shared; | ||
|
|
||
| [EnumExtensions] | ||
| public enum ChatNotificationPreference | ||
| { | ||
| [Display(Name = "Ingen")] | ||
| None = 0, | ||
|
|
||
| [Display(Name = "Kun første besked i ny samtale")] | ||
| FirstMessageOnly = 1, | ||
|
|
||
| [Display(Name = "Alle beskeder")] | ||
| AllMessages = 2 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/web/Jordnaer/Features/Notifications/NotificationSettingsService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using Jordnaer.Database; | ||
| using Jordnaer.Shared; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using OneOf; | ||
| using OneOf.Types; | ||
|
|
||
| namespace Jordnaer.Features.Notifications; | ||
|
|
||
| public interface INotificationSettingsService | ||
| { | ||
| Task<ChatNotificationPreference> GetChatPreferenceAsync(string userId, CancellationToken cancellationToken = default); | ||
| Task<OneOf<Success, NotFound>> SetChatPreferenceAsync(string userId, ChatNotificationPreference preference, CancellationToken cancellationToken = default); | ||
| Task<OneOf<Success, NotFound>> SetGroupPostPreferenceAsync(string userId, Guid groupId, bool enabled, CancellationToken cancellationToken = default); | ||
| Task<OneOf<Success, NotFound>> SetAllGroupPostPreferencesAsync(string userId, bool enabled, CancellationToken cancellationToken = default); | ||
| Task<List<GroupMembership>> GetGroupPreferencesAsync(string userId, CancellationToken cancellationToken = default); | ||
| } | ||
|
|
||
| public class NotificationSettingsService(IDbContextFactory<JordnaerDbContext> contextFactory) : INotificationSettingsService | ||
| { | ||
| public async Task<ChatNotificationPreference> GetChatPreferenceAsync(string userId, CancellationToken cancellationToken = default) | ||
| { | ||
| await using var context = await contextFactory.CreateDbContextAsync(cancellationToken); | ||
|
|
||
| var userProfile = await context.UserProfiles | ||
| .AsNoTracking() | ||
| .FirstOrDefaultAsync(x => x.Id == userId, cancellationToken); | ||
|
|
||
| return userProfile?.ChatNotificationPreference ?? ChatNotificationPreference.FirstMessageOnly; | ||
| } | ||
|
|
||
| public async Task<OneOf<Success, NotFound>> SetChatPreferenceAsync(string userId, ChatNotificationPreference preference, CancellationToken cancellationToken = default) | ||
| { | ||
| await using var context = await contextFactory.CreateDbContextAsync(cancellationToken); | ||
|
|
||
| var userProfile = await context.UserProfiles | ||
| .FirstOrDefaultAsync(x => x.Id == userId, cancellationToken); | ||
|
|
||
| if (userProfile is null) | ||
| { | ||
| return new NotFound(); | ||
| } | ||
|
|
||
| userProfile.ChatNotificationPreference = preference; | ||
| await context.SaveChangesAsync(cancellationToken); | ||
| return new Success(); | ||
| } | ||
|
|
||
| public async Task<OneOf<Success, NotFound>> SetGroupPostPreferenceAsync(string userId, Guid groupId, bool enabled, CancellationToken cancellationToken = default) | ||
| { | ||
| await using var context = await contextFactory.CreateDbContextAsync(cancellationToken); | ||
|
|
||
| var membership = await context.GroupMemberships | ||
| .FirstOrDefaultAsync(x => x.UserProfileId == userId && x.GroupId == groupId, cancellationToken); | ||
|
|
||
| if (membership is null) | ||
| { | ||
| return new NotFound(); | ||
| } | ||
|
|
||
| membership.EmailOnNewPost = enabled; | ||
| await context.SaveChangesAsync(cancellationToken); | ||
| return new Success(); | ||
| } | ||
|
|
||
| public async Task<OneOf<Success, NotFound>> SetAllGroupPostPreferencesAsync(string userId, bool enabled, CancellationToken cancellationToken = default) | ||
| { | ||
| await using var context = await contextFactory.CreateDbContextAsync(cancellationToken); | ||
|
|
||
| var rowsAffected = await context.GroupMemberships | ||
| .Where(x => x.UserProfileId == userId && x.MembershipStatus == MembershipStatus.Active) | ||
| .ExecuteUpdateAsync(setters => setters.SetProperty(m => m.EmailOnNewPost, enabled), cancellationToken); | ||
|
|
||
| return rowsAffected > 0 ? new Success() : new NotFound(); | ||
| } | ||
|
|
||
| public async Task<List<GroupMembership>> GetGroupPreferencesAsync(string userId, CancellationToken cancellationToken = default) | ||
| { | ||
| await using var context = await contextFactory.CreateDbContextAsync(cancellationToken); | ||
|
|
||
| // Get all active memberships with group information | ||
| return await context.GroupMemberships | ||
| .AsNoTracking() | ||
| .Where(x => x.UserProfileId == userId && x.MembershipStatus == MembershipStatus.Active) | ||
| .Include(x => x.Group) | ||
| .ToListAsync(cancellationToken); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/web/Jordnaer/Features/Notifications/WebApplicationBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace Jordnaer.Features.Notifications; | ||
|
|
||
| public static class WebApplicationBuilderExtensions | ||
| { | ||
| public static WebApplicationBuilder AddNotificationServices(this WebApplicationBuilder builder) | ||
| { | ||
| builder.Services.AddScoped<INotificationSettingsService, NotificationSettingsService>(); | ||
| return builder; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.