mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 14:11:29 +00:00
Implement in-game and website notifications (#932)
* Implement notifications logic, basic calls, and admin command * Remove unnecessary code * Add ability to stack notifications and return manually created XML * Remove test that is no longer needed and is causing failures * Apply suggestions from code review * Merge notifications with existing announcements page * Order notifications by descending ID instead of ascending ID * Move notification send task to moderation options under user Also restyles the buttons to line up next to each other like in the slot pages. * Style/position fixes with granted slots/notification partials * Fix incorrect form POST route * Prevent notification text area from breaking out of container * Actually use builder result for notification text * Minor restructuring of the notifications page * Add notifications for team picks, publish issues, and moderation * Mark notifications as dismissed instead of deleting them * Add XMLdoc to SendNotification method * Fix incorrect URL in announcements webhook * Remove unnecessary inline style from granted slots partial * Apply suggestions from code review * Apply first batch of suggestions from code review * Apply second batch of suggestions from code review * Change notification icon depending on if user has unread notifications * Show unread notification icon if there is an announcement posted * Remove "potential" wording from definitive fixes in error docs * Remove "Error code:" from publish notifications * Send notification if user tries to unlock a mod-locked level * Change notification timestamp format to include date * Add clarification to level mod-lock notification message * Change team pick notifications to moderation notifications Apparently the MMPick type doesn't show a visual notification. * Apply suggestions from code review * Add obsolete to notification types that display nothing in-game * Remove unused imports and remove icon switch case in favor of bell icon * Last minute fixes * Send notification upon earth wipe and clarify moderation case notifications * Add check for empty/too long notification text
This commit is contained in:
parent
98b370b106
commit
aea66b4a74
33 changed files with 712 additions and 199 deletions
|
@ -1,14 +1,16 @@
|
|||
#nullable enable
|
||||
using System.Text;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Notifications;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Mail;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -66,12 +68,46 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
|
|||
$"token.ExpiresAt: {token.ExpiresAt.ToString()}\n" +
|
||||
"---DEBUG INFO---");
|
||||
#endif
|
||||
|
||||
|
||||
return this.Ok(announceText.ToString());
|
||||
}
|
||||
|
||||
[HttpGet("notification")]
|
||||
public IActionResult Notification() => this.Ok();
|
||||
[Produces("text/xml")]
|
||||
public async Task<IActionResult> Notification()
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
|
||||
List<NotificationEntity> notifications = await this.database.Notifications
|
||||
.Where(n => n.UserId == token.UserId)
|
||||
.Where(n => !n.IsDismissed)
|
||||
.OrderByDescending(n => n.Id)
|
||||
.ToListAsync();
|
||||
|
||||
// We don't need to do any more work if there are no unconverted notifications to begin with.
|
||||
if (notifications.Count == 0) return this.Ok();
|
||||
|
||||
StringBuilder builder = new();
|
||||
|
||||
// ReSharper disable once ForCanBeConvertedToForeach
|
||||
// Suppressing this because we need to modify the list while iterating over it.
|
||||
for (int i = 0; i < notifications.Count; i++)
|
||||
{
|
||||
NotificationEntity n = notifications[i];
|
||||
|
||||
builder.AppendLine(LighthouseSerializer.Serialize(this.HttpContext.RequestServices,
|
||||
GameNotification.CreateFromEntity(n)));
|
||||
|
||||
n.IsDismissed = true;
|
||||
}
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Ok(new LbpCustomXml
|
||||
{
|
||||
Content = builder.ToString(),
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters chat messages sent by a user.
|
||||
|
@ -104,7 +140,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
|
|||
}
|
||||
|
||||
string username = await this.database.UsernameFromGameToken(token);
|
||||
|
||||
|
||||
string filteredText = CensorHelper.FilterMessage(message);
|
||||
|
||||
if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#nullable enable
|
||||
using System.Diagnostics;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
|
@ -47,12 +46,16 @@ public class PublishController : ControllerBase
|
|||
if (slot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, slot is null", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
"Your level failed to publish. (LH-PUB-0001)");
|
||||
return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(slot.RootLevel))
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, slot does not include rootLevel", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0002)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -61,6 +64,8 @@ public class PublishController : ControllerBase
|
|||
if (slot.Resources == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0003)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -73,11 +78,15 @@ public class PublishController : ControllerBase
|
|||
if (oldSlot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level republish, could not find old slot", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to republish. (LH-REP-0001)");
|
||||
return this.NotFound();
|
||||
}
|
||||
if (oldSlot.CreatorId != user.UserId)
|
||||
{
|
||||
Logger.Warn("Rejecting level republish, old slot's creator is not publishing user", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to republish because you are not the original publisher. (LH-REP-0002)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
|
@ -111,36 +120,48 @@ public class PublishController : ControllerBase
|
|||
if (slot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, slot is null", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
"Your level failed to publish. (LH-PUB-0001)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (slot.Resources?.Length == 0)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0003)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
// Yes Rider, this isn't null
|
||||
Debug.Assert(slot.Resources != null, "slot.ResourceList != null");
|
||||
|
||||
slot.Description = CensorHelper.FilterMessage(slot.Description);
|
||||
|
||||
if (slot.Description.Length > 512)
|
||||
{
|
||||
Logger.Warn($"Rejecting level upload, description too long ({slot.Description.Length} characters)", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
slot.Name = CensorHelper.FilterMessage(slot.Name);
|
||||
|
||||
if (slot.Name.Length > 64)
|
||||
{
|
||||
Logger.Warn($"Rejecting level upload, title too long ({slot.Name.Length} characters)", LogArea.Publish);
|
||||
Logger.Warn($"Rejecting level upload, title too long ({slot.Name.Length} characters)",
|
||||
LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish because the name is too long, {slot.Name.Length} characters. (LH-PUB-0004)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
slot.Description = CensorHelper.FilterMessage(slot.Description);
|
||||
|
||||
if (slot.Description.Length > 512)
|
||||
{
|
||||
Logger.Warn($"Rejecting level upload, description too long ({slot.Description.Length} characters)",
|
||||
LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish because the description is too long, {slot.Description.Length} characters. (LH-PUB-0005)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish because the server is missing resources. (LH-PUB-0006)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -149,6 +170,8 @@ public class PublishController : ControllerBase
|
|||
if (rootLevel == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, unable to find rootLevel", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0002)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -157,6 +180,8 @@ public class PublishController : ControllerBase
|
|||
if (rootLevel.FileType != LbpFileType.Level)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, rootLevel is not a level", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0007)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
|
@ -165,8 +190,10 @@ public class PublishController : ControllerBase
|
|||
if (rootLevel.FileType != LbpFileType.Adventure)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, rootLevel is not a LBP 3 Adventure", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish. (LH-PUB-0008)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameVersion slotVersion = FileHelper.ParseLevelVersion(rootLevel);
|
||||
|
@ -193,6 +220,8 @@ public class PublishController : ControllerBase
|
|||
if (oldSlot.CreatorId != user.UserId)
|
||||
{
|
||||
Logger.Warn("Rejecting level republish, old level not owned by current user", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to republish because you are not the original publisher. (LH-REP-0002)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
@ -240,10 +269,12 @@ public class PublishController : ControllerBase
|
|||
|
||||
oldSlot.MinimumPlayers = Math.Clamp(slot.MinimumPlayers, 1, 4);
|
||||
oldSlot.MaximumPlayers = Math.Clamp(slot.MaximumPlayers, 1, 4);
|
||||
|
||||
|
||||
// Check if the level has been locked by a moderator to avoid unlocking it
|
||||
if (oldSlot.LockedByModerator)
|
||||
if (oldSlot.LockedByModerator && !slot.InitiallyLocked)
|
||||
{
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} will not be unlocked because it has been locked by a moderator. (LH-REP-0003)");
|
||||
oldSlot.InitiallyLocked = true;
|
||||
}
|
||||
|
||||
|
@ -256,6 +287,8 @@ public class PublishController : ControllerBase
|
|||
if (usedSlots > user.EntitledSlots)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, too many published slots", LogArea.Publish);
|
||||
await this.database.SendNotification(user.UserId,
|
||||
$"{slot.Name} failed to publish because you have reached the maximum number of levels on your earth. (LH-PUB-0009)");
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue