C
C#15mo ago
SWEETPONY

✅ How to get confirmation from user about reading the notification?

Notifications work easy in my case. I just send notification message to all clients using broker. UI (it is vue.js in my case) subscribes to topic and receives message than send it to clients. Let's see some code:
public async Task<Task> OnNotify(
IDeliveryHandlerContext context,
ClientNotifyRequestArguments request)
{
var clientConnectionSummaries = _connectedClients.Values?
.Where(connection => connection.Principal != null
&& connection.Principal.Name == request.Login)
.EmptyIfNull();

if(clientConnectionSummaries == null)
return Task.CompletedTask;

foreach(var clientSummary in clientConnectionSummaries)
Task.Run(async () => await SendAsync(context,request,clientSummary), Lifetime.Finalizing)
.NoWait(Logger);

return Task.CompletedTask;
}
public async Task<Task> OnNotify(
IDeliveryHandlerContext context,
ClientNotifyRequestArguments request)
{
var clientConnectionSummaries = _connectedClients.Values?
.Where(connection => connection.Principal != null
&& connection.Principal.Name == request.Login)
.EmptyIfNull();

if(clientConnectionSummaries == null)
return Task.CompletedTask;

foreach(var clientSummary in clientConnectionSummaries)
Task.Run(async () => await SendAsync(context,request,clientSummary), Lifetime.Finalizing)
.NoWait(Logger);

return Task.CompletedTask;
}
private async Task SendAsync(
IDeliveryHandlerContext context,
ClientNotifyRequestArguments request,
MqttClientConnectionDto clientConnectionSummary)
{
var signature = new EndpointSignature()
.WithNamespace("client")
.WithName(clientConnectionSummary.ID);

await using var clientEndpoint = new RemoteEndpoint(Context, signature, default, Logger);

var result = await clientEndpoint.Command(
new NotifySendData
{
Message = request.Message,
Theme = request.Theme,
Event = request.Event
},
context.ToRequestParameters() );
}
private async Task SendAsync(
IDeliveryHandlerContext context,
ClientNotifyRequestArguments request,
MqttClientConnectionDto clientConnectionSummary)
{
var signature = new EndpointSignature()
.WithNamespace("client")
.WithName(clientConnectionSummary.ID);

await using var clientEndpoint = new RemoteEndpoint(Context, signature, default, Logger);

var result = await clientEndpoint.Command(
new NotifySendData
{
Message = request.Message,
Theme = request.Theme,
Event = request.Event
},
context.ToRequestParameters() );
}
But I don't understand how I can add confirmation for messages. For example, I want to send a notification and see if a person has viewed it. Can someone give me an idea, how to make this?
9 Replies
JakenVeina
JakenVeina15mo ago
that's a very... broad question you obviously know how to send messages back and forth between your clients and server what part of "confirming that a notification was read" is your sticking point?
SWEETPONY
SWEETPONYOP15mo ago
hmmm maybe I just asked weird question you asked right questions! I can just send message to special topic in broker and wait for response on this topic but what if I need to constantly send messages until I get a signal that the message has been read? now I just run Task and don't await it ah! the main problem is I don't understand when I should read response it looks like long polling problem
JakenVeina
JakenVeina15mo ago
why would you use long polling? it's 2023, what browser do you need to support that doesn't support websockets?
SWEETPONY
SWEETPONYOP15mo ago
i mean "long polling" harold I can send notification to message broker and vue.js will catch notification with websockets But I need to get response from client that notification has been read and I don't understand how to do it correctly All I can do rn is ask message broker about a new response on the right topic ah maybe I get the idea
JakenVeina
JakenVeina15mo ago
yes, I know you mean long-polling, that's why I asked why you would use it what is the "message broker" here? is that something running client-side?
SWEETPONY
SWEETPONYOP15mo ago
rabbitmq
JakenVeina
JakenVeina15mo ago
which means what?
SWEETPONY
SWEETPONYOP15mo ago
https://www.rabbitmq.com/ you can check this is a message broker which we use
JakenVeina
JakenVeina15mo ago
which does what?
Want results from more Discord servers?
Add your server