public async Task <Feedback> ConfirmComradeRequest([FromBody] ComradeRequestFeedback req) { if (!ModelState.IsValid) { return(null); } var request = await _comrades.DrawComradeRequest(req.Id); if (request == null || request.Agreed || request.ReceiverId != req.ReceiverId) { Debug.Fail("Security break: comrade request confirmation failed."); return(null); } request.Seen = true; request.Agreed = true; var comrades = _comrades.MakeComradesFromRequest(request); _comrades.SaveChanges(); var answer = new ComradeRequest() { Id = request.Id, Agreed = true, }; await _signalDispatcher .PushImpulse(req.OtherName, R.ImpulseType.ComradeRequest, answer); return(Success); }
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); }