[backend/services] Basic event bus implementation (ISH-60)
This commit is contained in:
parent
fc0f40f8ce
commit
ff27d7ff16
5 changed files with 21 additions and 5 deletions
|
@ -1,9 +1,6 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||
using JI = System.Text.Json.Serialization.JsonIgnoreAttribute;
|
||||
using static Iceshrimp.Backend.Core.Database.Tables.Notification;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
|
||||
|
|
|
@ -54,6 +54,7 @@ public static class ServiceExtensions {
|
|||
.AddSingleton<HttpRequestService>()
|
||||
.AddSingleton<QueueService>()
|
||||
.AddSingleton<ObjectStorageService>()
|
||||
.AddSingleton<EventService>()
|
||||
.AddSingleton<RequestBufferingMiddleware>()
|
||||
.AddSingleton<AuthorizationMiddleware>()
|
||||
.AddSingleton<RequestVerificationMiddleware>()
|
||||
|
|
11
Iceshrimp.Backend/Core/Services/EventService.cs
Normal file
11
Iceshrimp.Backend/Core/Services/EventService.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
|
||||
namespace Iceshrimp.Backend.Core.Services;
|
||||
|
||||
public class EventService {
|
||||
public event EventHandler<Note> NotePublished;
|
||||
public event EventHandler<string> NoteDeleted;
|
||||
|
||||
public void RaiseNotePublished(object? sender, Note note) => NotePublished.Invoke(sender, note);
|
||||
public void RaiseNoteDeleted(object? sender, Note note) => NoteDeleted.Invoke(sender, note.Id);
|
||||
}
|
|
@ -36,7 +36,8 @@ public class NoteService(
|
|||
MentionsResolver mentionsResolver,
|
||||
MfmConverter mfmConverter,
|
||||
DriveService driveSvc,
|
||||
NotificationService notificationSvc
|
||||
NotificationService notificationSvc,
|
||||
EventService eventSvc
|
||||
) {
|
||||
private readonly List<string> _resolverHistory = [];
|
||||
private int _recursionLimit = 100;
|
||||
|
@ -84,6 +85,7 @@ public class NoteService(
|
|||
if (reply != null) reply.RepliesCount++;
|
||||
await db.AddAsync(note);
|
||||
await db.SaveChangesAsync();
|
||||
eventSvc.RaiseNotePublished(this, note);
|
||||
await notificationSvc.GenerateMentionNotifications(note, mentionedLocalUserIds);
|
||||
|
||||
var obj = await noteRenderer.RenderAsync(note, mentions);
|
||||
|
@ -127,7 +129,7 @@ public class NoteService(
|
|||
|
||||
user.NotesCount--;
|
||||
db.Remove(dbNote);
|
||||
|
||||
eventSvc.RaiseNoteDeleted(this, dbNote);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
@ -212,6 +214,7 @@ public class NoteService(
|
|||
if (dbNote.Reply != null) dbNote.Reply.RepliesCount++;
|
||||
await db.Notes.AddAsync(dbNote);
|
||||
await db.SaveChangesAsync();
|
||||
eventSvc.RaiseNotePublished(this, dbNote);
|
||||
await notificationSvc.GenerateMentionNotifications(dbNote, mentionedLocalUserIds);
|
||||
await notificationSvc.GenerateReplyNotifications(dbNote, mentionedLocalUserIds);
|
||||
logger.LogDebug("Note {id} created successfully", dbNote.Id);
|
||||
|
|
|
@ -57,4 +57,8 @@
|
|||
<None Remove="migrate.sql"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Core\Events\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Add table
Reference in a new issue