public async Task <Mail> MCSendReplyAsync(Mail mail) { var authId = GetClaimId(ClaimType.UserId); var siteId = GetCurrentSiteId(); if (mail.InReplyToId != null && HasPermission(Permission.MailParticipants)) { var inReplyToMail = await _mailRepository.GetByIdAsync(mail.InReplyToId.Value); mail.ThreadId = inReplyToMail?.ThreadId ?? mail.InReplyToId.Value; mail.FromUserId = 0; mail.ToUserId = inReplyToMail.FromUserId; mail.CanParticipantDelete = true; mail.IsNew = true; mail.IsDeleted = false; mail.SiteId = siteId; _cache.Remove(UnreadMailCacheKey(siteId, (int)mail.ToUserId)); if (!inReplyToMail.IsRepliedTo) { await _mailRepository.MarkAdminReplied(inReplyToMail.Id); _cache.Remove(UnhandledMailCount(siteId)); } return(await _mailRepository.AddSaveAsync(authId, mail)); } else { _logger.LogError($"User {authId} doesn't have permission to reply to mail {mail.InReplyToId}."); throw new GraException("Permission denied"); } }
public async Task MarkHandled(int mailId) { var authId = GetClaimId(ClaimType.UserId); if (HasPermission(Permission.MailParticipants)) { var mail = await _mailRepository.GetByIdAsync(mailId); if (mail.ToUserId == null) { await _mailRepository.MarkAdminReplied(mailId); var siteId = GetCurrentSiteId(); await _cache.RemoveAsync(UnhandledMailCount(siteId)); } else { throw new GraException("Cannot mark participant mail as handled"); } } else { _logger.LogError($"User {authId} doesn't have permission to mark mail as handled."); throw new GraException("Permission denied"); } }