aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs18
-rw-r--r--src/slskd/Events/Types/Events.cs8
-rw-r--r--src/slskd/Messaging/ConversationService.cs17
3 files changed, 22 insertions, 21 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 0c76379a..40f6bf50 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -943,23 +943,15 @@ namespace slskd
private void Client_PrivateMessageReceived(object sender, PrivateMessageReceivedEventArgs args)
{
- var userIsBlacklisted = Users.IsBlacklisted(args.Username);
-
- EventBus.Raise(new PrivateMessageReceivedEvent
- {
- MessageId = args.Id,
- MessageTimestamp = args.Timestamp,
- Username = args.Username,
- Message = args.Message,
- Replayed = args.Replayed,
- Blacklisted = userIsBlacklisted,
- });
-
- if (userIsBlacklisted)
+ if (Users.IsBlacklisted(args.Username))
{
Log.Debug("Ignored private message from blacklisted user {Username}: {Message}", args.Username, args.Message);
return;
}
+ else
+ {
+ // todo: raise blacklisted message event?
+ }
Messaging.Conversations.HandleMessageAsync(args.Username, PrivateMessage.FromEventArgs(args));
diff --git a/src/slskd/Events/Types/Events.cs b/src/slskd/Events/Types/Events.cs
index 5ae5d011..48d15f54 100644
--- a/src/slskd/Events/Types/Events.cs
+++ b/src/slskd/Events/Types/Events.cs
@@ -18,6 +18,7 @@
namespace slskd.Events;
using System;
+using slskd.Messaging;
using slskd.Transfers;
public enum EventType
@@ -72,12 +73,7 @@ public sealed record PrivateMessageReceivedEvent : Event
{
public override EventType Type => EventType.PrivateMessageReceived;
public override int Version => 0;
- public required int MessageId { get; init; }
- public required DateTime MessageTimestamp { get; init; }
- public required string Username { get; init; }
- public required string Message { get; init; }
- public required bool Replayed { get; init; }
- public required bool Blacklisted { get; init; }
+ public required PrivateMessage Message { get; init; }
}
public sealed record PublicChatMessageReceivedEvent : Event
diff --git a/src/slskd/Messaging/ConversationService.cs b/src/slskd/Messaging/ConversationService.cs
index de772ff0..b39162d6 100644
--- a/src/slskd/Messaging/ConversationService.cs
+++ b/src/slskd/Messaging/ConversationService.cs
@@ -24,6 +24,7 @@ namespace slskd.Messaging
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Serilog;
+ using slskd.Events;
using Soulseek;
/// <summary>
@@ -112,12 +113,15 @@ namespace slskd.Messaging
{
public ConversationService(
ISoulseekClient soulseekClient,
+ EventBus eventBus,
IDbContextFactory<MessagingDbContext> contextFactory)
{
SoulseekClient = soulseekClient;
+ EventBus = eventBus;
ContextFactory = contextFactory;
}
+ private EventBus EventBus { get; }
private IDbContextFactory<MessagingDbContext> ContextFactory { get; }
private ILogger Log { get; } = Serilog.Log.ForContext<ConversationService>();
private ISoulseekClient SoulseekClient { get; }
@@ -301,8 +305,12 @@ namespace slskd.Messaging
if (existing != null)
{
- // the message was replayed. ensure the local ack bit is in sync with the server
- existing.IsAcknowledged = message.IsAcknowledged;
+ // the message was replayed. either we haven't ACKed it, or we did and the ACK didn't make it to the
+ // server. either way we need to ensure that the local db understands the message needs to be ACKed, so
+ // force the bit false. we shouldn't need to update any other part of the message because IDs are unique
+ // on the soulseek server
+ existing.IsAcknowledged = false;
+ existing.WasReplayed = message.WasReplayed;
}
else
{
@@ -312,6 +320,11 @@ namespace slskd.Messaging
context.SaveChanges();
+ EventBus.Raise(new PrivateMessageReceivedEvent
+ {
+ Message = message,
+ });
+
return Task.CompletedTask;
}