notify using signal, and only email as fallback
Fixes chat room selector in web interface,
This commit is contained in:
14
src/Yavsc.Abstract/IT/BugReport.cs
Normal file
14
src/Yavsc.Abstract/IT/BugReport.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
public class BugReport {
|
||||
[Required]
|
||||
public string ApiKey { get ; set; }
|
||||
[Required]
|
||||
public string Component { get ; set; }
|
||||
[Required][StringLength(1024)]
|
||||
public string ExceptionObjectJson { get ; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ namespace Yavsc
|
||||
public const string PrivateMessageDenied = "deniedpv";
|
||||
|
||||
public const string Error = "error";
|
||||
|
||||
public const string BookQuery = "bookQuery";
|
||||
}
|
||||
}
|
||||
|
@ -57,42 +57,47 @@ namespace Yavsc.Services
|
||||
throw new Exception("No dest id");
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Sending to {string.Join(" ",raa)} using signalR : "+JsonConvert.SerializeObject(ev));
|
||||
List<MessageWithPayloadResponse.Result> results = new List<MessageWithPayloadResponse.Result>();
|
||||
foreach(var clientId in raa) {
|
||||
MessageWithPayloadResponse.Result result = new MessageWithPayloadResponse.Result();
|
||||
result.registration_id = clientId;
|
||||
|
||||
var user = _dbContext.Users.FirstOrDefault(u=> u.Id == clientId);
|
||||
if (user==null)
|
||||
{
|
||||
response.failure++;
|
||||
result.error = "no such user.";
|
||||
continue;
|
||||
}
|
||||
if (!user.EmailConfirmed){
|
||||
response.failure++;
|
||||
result.error = "user has not confirmed his email address.";
|
||||
continue;
|
||||
}
|
||||
if (user.Email==null){
|
||||
response.failure++;
|
||||
result.error = "user has no legacy email address.";
|
||||
continue;
|
||||
}
|
||||
|
||||
var body = ev.CreateBody();
|
||||
|
||||
|
||||
|
||||
var hubClient = hubContext.Clients.User(clientId);
|
||||
if (hubClient == null)
|
||||
{
|
||||
var user = _dbContext.Users.FirstOrDefault(u=> u.Id == clientId);
|
||||
if (user==null)
|
||||
{
|
||||
response.failure++;
|
||||
result.error = "no such user.";
|
||||
continue;
|
||||
}
|
||||
if (!user.EmailConfirmed){
|
||||
response.failure++;
|
||||
result.error = "user has not confirmed his email address.";
|
||||
continue;
|
||||
}
|
||||
var body = ev.CreateBody();
|
||||
|
||||
var mailSent = await _emailSender.SendEmailAsync(
|
||||
_logger.LogDebug($"Sending to {user.UserName} <{user.Email}> : {body}");
|
||||
var mailSent = await _emailSender.SendEmailAsync(
|
||||
user.UserName,
|
||||
user.Email,
|
||||
$"{ev.Sender} (un client) vous demande un rendez-vous",
|
||||
$"{ev.CreateBody()}\r\n"
|
||||
$"{ev.Sender} (un client) vous demande un rendez-vous",
|
||||
body+Environment.NewLine
|
||||
);
|
||||
|
||||
var sent = await _emailSender.SendEmailAsync(ev.Sender, user.Email,
|
||||
ev.Topic, body
|
||||
);
|
||||
if (!sent.Sent) {
|
||||
result.message_id = sent.MessageId;
|
||||
result.error = sent.ErrorMessage;
|
||||
if (!mailSent.Sent) {
|
||||
result.message_id = mailSent.MessageId;
|
||||
result.error = mailSent.ErrorMessage;
|
||||
response.failure++;
|
||||
}
|
||||
else
|
||||
@ -102,8 +107,16 @@ namespace Yavsc.Services
|
||||
}
|
||||
}
|
||||
else {
|
||||
_logger.LogDebug($"Sending signal to {string.Join(" ",raa)} : "+JsonConvert.SerializeObject(ev));
|
||||
// we assume that each hub connected client will handle this signal
|
||||
result.message_id=hubClient.notify(ev);
|
||||
|
||||
hubClient.notify(NotificationTypes.BookQuery,
|
||||
$"# {ev.Sender} (un client) vous demande un rendez-vous\n"+body);
|
||||
|
||||
result.message_id=MimeKit.Utils.MimeUtils.GenerateMessageId(
|
||||
siteSettings.Authority
|
||||
);
|
||||
|
||||
response.success++;
|
||||
}
|
||||
results.Add(result);
|
||||
|
@ -31,7 +31,13 @@
|
||||
var ChatView = function ($view, full)
|
||||
{
|
||||
|
||||
|
||||
if (!full) throw "not implemented";
|
||||
|
||||
// build a channel list
|
||||
var chans = Array();
|
||||
var frontRoomName;
|
||||
|
||||
var chat = $.connection.chatHub
|
||||
// Create a function that the hub can call back to display messages.
|
||||
chat.client.addMessage = function (name, room, message) {
|
||||
@ -74,17 +80,18 @@
|
||||
)
|
||||
}
|
||||
|
||||
var activeRoom;
|
||||
var activeRoomName;
|
||||
var setActiveRoom = function(room) {
|
||||
if (activeRoom) {
|
||||
var frontRoom;
|
||||
if (frontRoomName!=='') {
|
||||
frontRoom=$("#vroom_"+frontRoomName);
|
||||
// TODO animate
|
||||
activeRoom.addClass("hidden");
|
||||
$("sel_"+activeRoomName).addClass("btn-primary");
|
||||
}
|
||||
activeRoom=$("#vroom_"+room);
|
||||
activeRoomName=room;
|
||||
activeRoom.removeClass("hidden");
|
||||
frontRoom.addClass("hidden");
|
||||
$("#sel_"+frontRoomName).addClass("btn-primary");
|
||||
}
|
||||
frontRoomName = room;
|
||||
frontRoom=$("#vroom_"+room);
|
||||
$("#sel_"+room).removeClass("btn-primary");
|
||||
frontRoom.removeClass("hidden");
|
||||
}
|
||||
|
||||
var roomlist = $('<div class="roomlist"></div>');
|
||||
@ -94,7 +101,7 @@
|
||||
|
||||
var buildRoom = function (room)
|
||||
{
|
||||
var roomTag = $("<a>"+room+"</a>").addClass("btn").addClass("btn-primary");
|
||||
var roomTag = $("<a>"+room+"</a>").addClass("btn");
|
||||
roomTag.prop("id","sel_"+room)
|
||||
.click(function(){
|
||||
setActiveRoom(room);
|
||||
@ -124,9 +131,6 @@
|
||||
setActiveRoom(room);
|
||||
}
|
||||
|
||||
// build a channel list
|
||||
var chans = Array();
|
||||
|
||||
$view.data("chans").split(",").forEach(function(chan) {
|
||||
buildRoom(chan)
|
||||
});
|
||||
|
Reference in New Issue
Block a user