.github
.idx
DysonNetwork.Sphere
Account
Activity
Auth
Chat
Connection
Developer
Email
Localization
Migrations
Pages
Permission
Post
Properties
Publisher
Realm
Resources
Sticker
Storage
Handlers
ActionLogFlushHandler.cs
MessageReadReceiptFlushHandler.cs
CacheService.cs
CloudFile.cs
FileController.cs
FileService.cs
FlushBufferService.cs
Wallet
wwwroot
.DS_Store
.gitignore
AppDatabase.cs
Dockerfile
DysonNetwork.Sphere.csproj
DysonNetwork.Sphere.csproj.DotSettings.user
DysonNetwork.Sphere.http
Program.cs
appsettings.json
package.json
postcss.config.js
tailwind.config.js
.dockerignore
.gitignore
DysonNetwork.sln
DysonNetwork.sln.DotSettings.user
compose.yaml
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using DysonNetwork.Sphere.Chat;
|
|
using EFCore.BulkExtensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NodaTime;
|
|
using Quartz;
|
|
|
|
namespace DysonNetwork.Sphere.Storage.Handlers;
|
|
|
|
public class MessageReadReceiptFlushHandler(IServiceProvider serviceProvider) : IFlushHandler<MessageReadReceipt>
|
|
{
|
|
public async Task FlushAsync(IReadOnlyList<MessageReadReceipt> items)
|
|
{
|
|
var now = SystemClock.Instance.GetCurrentInstant();
|
|
var distinctId = items
|
|
.DistinctBy(x => x.SenderId)
|
|
.Select(x => x.SenderId)
|
|
.ToList();
|
|
|
|
using var scope = serviceProvider.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
|
await db.ChatMembers.Where(r => distinctId.Contains(r.Id))
|
|
.ExecuteUpdateAsync(s => s.SetProperty(m => m.LastReadAt, now)
|
|
);
|
|
}
|
|
}
|
|
|
|
public class ReadReceiptFlushJob(FlushBufferService fbs, MessageReadReceiptFlushHandler hdl) : IJob
|
|
{
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
await fbs.FlushAsync(hdl);
|
|
}
|
|
}
|