mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-15 01:31:28 +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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue