public async Task <Feedback> MakeComradeRequest([FromBody] ComradeRequest req) { if (ModelState.IsValid == false || req.SenderId == null) { return(null); } var otherName = req.OtherName; var request = await _comrades.FetchComradeRequest(req.SenderId.Value, otherName, createOnly : true); var userName = await _comrades.GetUserName(req.SenderId.Value); var answer = new ComradeRequest() { Id = request.Id, OtherName = userName, TimeSpan = TimeSpan(request.Since) }; await _signalDispatcher.PushImpulse(otherName, R.ImpulseType.ComradeRequest, answer); return(Success); }
public async Task <Feedback> SendMessage([FromBody] Message message) { if (!ModelState.IsValid) { return(null); } // get required data before actual processings var usersIds = await _messages.GetUsersIdAndName(message.OtherName, message.UserId); var otherId = usersIds.First(u => u.Name == message.OtherName).Id; var userName = usersIds.First(u => u.Id == message.UserId).Name; // save sent message to storage var saveData = new MessageData { UserId = message.UserId, OtherId = otherId, Text = message.Text }; var messageId = _messages.SaveMessage(saveData); // send message to receiver with right data var passedMessage = new Message() { Id = messageId, OtherName = userName, Text = message.Text }; await _signalDispatcher .PushImpulse(message.OtherName, R.ImpulseType.Message, passedMessage); // if we get this far then there's solid chance everthing is ok. return(new Feedback() { Result = FeedResult.Success }); }