mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 15:08:47 -07:00
feat: Refactor notification handling to use SystemNotificationService; remove outdated NotificationService references and update related logic
This commit is contained in:
@@ -28,7 +28,6 @@ namespace DorkNet.Server.Controllers.API.Photos;
|
||||
public class PhotosController(
|
||||
DorkNetDbContext db,
|
||||
PlayerPresenceService presence,
|
||||
NotificationService notifications,
|
||||
LevelService level,
|
||||
DomainConfig domain) : ControllerBase
|
||||
{
|
||||
@@ -83,12 +82,11 @@ public class PhotosController(
|
||||
// Posting a photo gives a small XP bump — encourages camera use.
|
||||
await level.AwardXpAsync(me, LevelService.InventionSavedXp, $"photo_posted:{photo.Id}");
|
||||
|
||||
// Push to tagged players so their "Photos of me" feed refreshes.
|
||||
foreach (var taggedId in ParseTagged(photo.TaggedPlayerIdsCsv))
|
||||
await notifications.NotifyAsync(taggedId,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "TaggedInPhoto", PhotoId = photo.Id, From = me });
|
||||
|
||||
// No real-time push for photo tags: there is no matching client
|
||||
// message type, and the old SubscriptionUpdateProfile
|
||||
// {Reason:"TaggedInPhoto"} blob decoded to a blank account
|
||||
// ("Orphan player account (0)") without refreshing anything. The
|
||||
// "Photos of me" feed refreshes on the tagged player's next fetch.
|
||||
return Ok(ToDto(photo));
|
||||
}
|
||||
|
||||
@@ -217,9 +215,9 @@ public class PhotosController(
|
||||
{
|
||||
await level.AwardXpAsync(photo.UploaderPlayerId,
|
||||
LevelService.CheerReceivedXp, $"photo_cheer:{id}");
|
||||
await notifications.NotifyAsync(photo.UploaderPlayerId,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "PhotoCheer", PhotoId = id, From = me });
|
||||
// No real-time push: no client message type for photo cheers, and
|
||||
// the old SubscriptionUpdateProfile blob only spawned a blank
|
||||
// "Orphan player account (0)". Count refreshes on next fetch.
|
||||
}
|
||||
return Ok(new { cheered = true, count = photo.CheerCount });
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace DorkNet.Server.Controllers.API.PlayerCheer;
|
||||
[Authorize]
|
||||
public class PlayerCheerController(
|
||||
DorkNetDbContext db,
|
||||
NotificationService notifications,
|
||||
SystemNotificationService systemNotifications,
|
||||
LevelService level) : ControllerBase
|
||||
{
|
||||
private long Me => this.RequireCurrentPlayerId();
|
||||
@@ -54,9 +54,12 @@ public class PlayerCheerController(
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
await level.AwardXpAsync(target, LevelService.CheerReceivedXp, $"cheer_from:{Me}");
|
||||
await notifications.NotifyAsync(target,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "CheerReceived", From = Me, Type = type });
|
||||
// Real notification: a PlayerCheer message the client renders as
|
||||
// "X cheered you" (resolved from FromPlayerId), persisted to the
|
||||
// recipient's notification feed. Replaces the old blank-account
|
||||
// SubscriptionUpdateProfile misuse.
|
||||
await systemNotifications.SendAsync(target,
|
||||
SystemNotificationService.MessageType.PlayerCheer, fromPlayerId: Me);
|
||||
return Ok(new { success = true, error = "" });
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace DorkNet.Server.Controllers.API.PlayerState;
|
||||
[ApiController]
|
||||
public class PlayerStateController(
|
||||
DorkNetDbContext db,
|
||||
NotificationService notifications,
|
||||
SystemNotificationService systemNotifications,
|
||||
LevelService level) : ControllerBase
|
||||
{
|
||||
// RecNet.Progressions.GetProgressionById / GetMyProgression — real
|
||||
@@ -150,9 +150,10 @@ public class PlayerStateController(
|
||||
// Reward the cheered player with a small XP bump.
|
||||
await level.AwardXpAsync(playerId, LevelService.CheerReceivedXp, $"cheer_from:{me}");
|
||||
|
||||
await notifications.NotifyAsync(playerId,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "CheerReceived", From = me, Type = type });
|
||||
// Real PlayerCheer notification (persisted + pushed as a Message),
|
||||
// replacing the old blank-account SubscriptionUpdateProfile misuse.
|
||||
await systemNotifications.SendAsync(playerId,
|
||||
SystemNotificationService.MessageType.PlayerCheer, fromPlayerId: me);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace DorkNet.Server.Controllers.API.PlayerSubscriptions;
|
||||
[Route("api/[controller]/v1")]
|
||||
[Authorize]
|
||||
public class PlayerSubscriptionsController(
|
||||
DorkNetDbContext db,
|
||||
NotificationService notifications) : ControllerBase
|
||||
DorkNetDbContext db) : ControllerBase
|
||||
{
|
||||
private long Me => this.RequireCurrentPlayerId();
|
||||
|
||||
@@ -61,11 +60,10 @@ public class PlayerSubscriptionsController(
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Tell the target their subscriber count changed so the watch
|
||||
// refreshes their profile page if open.
|
||||
await notifications.NotifyAsync(targetId,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "NewSubscriber", From = Me });
|
||||
// No real-time push: no client message type for new subscribers, and
|
||||
// the old SubscriptionUpdateProfile {Reason:"NewSubscriber"} blob
|
||||
// decoded to a blank account ("Orphan player account (0)") without
|
||||
// refreshing anything. The subscriber count refreshes on next fetch.
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user