public async Task <List <UserMessage> > GetUnReadMessage(MessageSearchOptions options) { options.statusId = StaticKeys.UserMessageStatusId_Waiting; var userMessages = await SearchUserMessage(options, null); return(userMessages); //return userMessages?.FindAll(m => m.ReceiverId.IsNullOrEmpty()); }
public async Task <List <UserMessage> > SearchUserMessage(MessageSearchOptions options, PageOptions page) { var serviceId = options?.serviceId; var typeId = options?.typeId; var topicId = options?.topicId; var receiverId = options?.reveiverId; var statusId = options?.statusId; var senderIds = options?.senderIds; var query = DB.Queryable <Message, UserMessage>((m, um) => new object[] { JoinType.Left, m.Id == um.MessageId && um.ReceiverId == receiverId }); if (!senderIds.IsNull() && senderIds.Length > 0) { query.In((m, um) => m.SenderId, senderIds); } if (statusId == StaticKeys.UserMessageStatusId_Waiting) { query.Where((m, um) => string.IsNullOrEmpty(um.ReceiverId)); } if (!serviceId.IsNullOrEmpty()) { query.Where((m, um) => m.ServiceId == serviceId || um.ServiceId == serviceId); } if (!typeId.IsNullOrEmpty()) { query.Where((m, um) => m.TypeId == typeId); } if (!topicId.IsNullOrEmpty()) { query.Where((m, um) => m.TopicId == topicId); } if (!page.IsNull()) { page.TotalCount = query.Count(); } var result = query.Select((m, um) => new UserMessage { Id = um.Id, ReceiverId = um.ReceiverId, MessageId = um.MessageId, ServiceId = um.ServiceId, Message = m, }); return(page.IsNull() || !page.IsValidate ? await result.ToListAsync() : await result.ToPageListAsync(page.PageIndex, page.PageSize)); }
public async Task <IActionResult> UnRreadAnnounceMessage() { var userId = User.GetClaimsValue(CoreKeys.USER_ID); var serviceId = User.GetClaimsValue(CoreKeys.SYSTEM_ID); var searchOptions = new MessageSearchOptions { serviceId = serviceId, typeId = StaticKeys.MessageTypeId_Announce, reveiverId = userId }; var result = await _messageService.GetUnReadMessage(searchOptions); return(new JsonResult(new { data = result.Select(m => Mapper.Map <UserMessage, UserMessageViewModel>(m)) })); }
public async Task <IActionResult> ReceiveAnnounce() { var userId = User.GetUserId(); var serviceId = User.GetServiceId(); var searchOptions = new MessageSearchOptions { reveiverId = userId, serviceId = serviceId, typeId = StaticKeys.MessageTypeId_Announce }; var isSuccess = await _messageService.ReceiveMessages(searchOptions); return(new JsonResult(new { isSuccess, msg = isSuccess ? "操作成功" : "操作失败" })); }
public async void ReceiveNotifyMessageShouldOk() { var mo = new Message { Topic = topic, Body = body, ServiceId = serviceId, SenderId = targetId, SendTime = DateTime.UtcNow }; var message = JsonConvert.SerializeObject(mo); var result = await _messageService.NotifyAsync(message); var count = 0; var searchOptions = new MessageSearchOptions { reveiverId = subscriberId, serviceId = serviceId, typeId = StaticKeys.MessageTypeId_Notify }; var userMessages = await _messageService.SearchUserMessage(searchOptions, null); Assert.True(count > 0); Assert.True(userMessages.Exists(um => um.ReceiverId == subscriberId)); Assert.NotEmpty(userMessages); }
public async Task <bool> ReceiveMessages(MessageSearchOptions options) { var unreadMessages = await GetUnReadMessage(options); foreach (var message in unreadMessages) { UserMessageDb.Insert( new UserMessage { Id = Guid.NewGuid().ToString(), MessageId = message.Message.Id, ReceiverId = options?.reveiverId, ServiceId = options?.serviceId, StatusId = Guid.Empty.ToString() }); } return(true); }
public async Task <IActionResult> GetTargetMessages([FromForm] string topicId, [FromForm] int start, [FromForm] int length) { var userId = User.GetClaimsValue(CoreKeys.USER_ID); var serviceId = User.GetClaimsValue(CoreKeys.SYSTEM_ID); // get all subscribe target id var targetIds = await _subscribeService.Search(new SubscribeSearchOptions { SubscriberId = userId }, null); var searchOptions = new MessageSearchOptions { reveiverId = userId, serviceId = serviceId, topicId = topicId, typeId = StaticKeys.MessageTypeId_Notify, senderIds = targetIds.IsNull() || targetIds.Count <= 0 ? new string[] { } : targetIds.Select(t => t.TargetId).ToArray() }; var result = await _messageService.SearchUserMessage(searchOptions, new PageOptions(start, length)); return(new JsonResult(new { data = result.Select(m => Mapper.Map <UserMessage, UserMessageViewModel>(m)) })); }
public async Task <List <Message> > Search(MessageSearchOptions options, PageOptions page) { var query = DB.Queryable <Message, Topic>((m, t) => new object[] { JoinType.Inner, m.TopicId == t.Id }); if (!options.topicId.IsNullOrEmpty()) { query.Where((m, t) => m.TopicId == options.topicId); } if (!options.serviceId.IsNullOrEmpty()) { query.Where((m, t) => m.ServiceId == options.serviceId); } if (!options.typeId.IsNullOrEmpty()) { query.Where((m, t) => m.TypeId == options.typeId); } page.TotalCount = query.Count(); var result = query.Select((m, t) => new Message { Id = m.Id, Topic = t.Name, Body = m.Body, ReceiveTime = m.ReceiveTime, SenderId = m.SenderId, SendTime = m.SendTime, ServiceId = m.ServiceId, StatusId = m.StatusId, TopicId = m.TopicId, TypeId = m.TypeId, Title = m.Title }); return(!page.IsValidate ? await result.ToListAsync() : await result.ToPageListAsync(page.PageIndex, page.PageSize)); }
public async Task <IActionResult> ReceiveTargetMessages([FromForm] string topicId) { var userId = User.GetClaimsValue(CoreKeys.USER_ID); var serviceId = User.GetClaimsValue(CoreKeys.SYSTEM_ID); var targetIds = await _subscribeService.Search(new SubscribeSearchOptions { SubscriberId = userId }, null); var searchOptions = new MessageSearchOptions { reveiverId = userId, serviceId = serviceId, topicId = topicId, typeId = StaticKeys.MessageTypeId_Notify, senderIds = targetIds.IsNull() || targetIds.Count <= 0 ? new string[] { } : targetIds.Select(t => t.TargetId).ToArray() }; var isSuccess = await _messageService.ReceiveMessages(searchOptions); return(new JsonResult(new { isSuccess, msg = isSuccess ? "操作成功" : "操作失败" })); }