public async Task ProcessMessagesContinue(InputModels.Continue input, bool force = false) { input.ThrowIfNull(nameof(input)); var messageQuery = from message in DbContext.Messages where force || !message.Processed orderby message.Id descending select message; var take = SettingsRepository.MessagesPerPage(true); var skip = take * input.CurrentStep; var messages = messageQuery.Skip(skip).Take(take).ToList(); foreach (var message in messages) { var serviceResponse = new ServiceModels.ServiceResponse(); var processedMessage = await ProcessMessageInput(serviceResponse, message.OriginalBody); if (serviceResponse.Success) { message.OriginalBody = processedMessage.OriginalBody; message.DisplayBody = processedMessage.DisplayBody; message.ShortPreview = processedMessage.ShortPreview; message.LongPreview = processedMessage.LongPreview; message.Cards = processedMessage.Cards; message.Processed = true; DbContext.Update(message); } } DbContext.SaveChanges(); }
public int GetPageNumber(int messageId, List <int> messageIds) { var index = (double)messageIds.FindIndex(id => id == messageId); index++; var messagesPerPage = SettingsRepository.MessagesPerPage(); return(Convert.ToInt32(Math.Ceiling(index / messagesPerPage))); }
public int ProcessMessages(bool force = false) { var records = from message in DbContext.Messages where force || !message.Processed select message.Id; var recordCount = records.Count(); var take = SettingsRepository.MessagesPerPage(true); var totalSteps = (int)Math.Ceiling(1D * recordCount / take); return(totalSteps); }
public List <ItemModels.MessagePreview> GetPreviews(int boardId, int page, int unread) { var participation = new List <DataModels.Participant>(); var viewLogs = new List <DataModels.ViewLog>(); var historyTimeLimit = SettingsRepository.HistoryTimeLimit(); if (UserContext.IsAuthenticated) { participation = DbContext.Participants.Where(r => r.UserId == UserContext.ApplicationUser.Id).ToList(); viewLogs = DbContext.ViewLogs.Where(r => r.LogTime >= historyTimeLimit && r.UserId == UserContext.ApplicationUser.Id).ToList(); } var sortedMessageIds = GetIndexIds(boardId, page, unread, historyTimeLimit, participation, viewLogs); var messageQuery = from message in DbContext.Messages where sortedMessageIds.Contains(message.Id) select new { message.Id, message.ShortPreview, message.ViewCount, message.ReplyCount, message.TimePosted, message.LastReplyId, message.LastReplyById, message.LastReplyPosted }; var messages = messageQuery.ToList(); var take = SettingsRepository.MessagesPerPage(); var popularityLimit = SettingsRepository.PopularityLimit(); var messagePreviews = new List <ItemModels.MessagePreview>(); foreach (var messageId in sortedMessageIds) { var message = messages.First(item => item.Id == messageId); var messagePreview = new ItemModels.MessagePreview { Id = message.Id, ShortPreview = string.IsNullOrEmpty(message.ShortPreview.Trim()) ? "No subject" : message.ShortPreview, Views = message.ViewCount, Replies = message.ReplyCount, Pages = Convert.ToInt32(Math.Ceiling(1.0 * message.ReplyCount / take)), LastReplyId = message.Id, Popular = message.ReplyCount > popularityLimit, Pinned = PinRepository.Any(item => item.MessageId == message.Id) }; messagePreviews.Add(messagePreview); var lastMessageTime = message.TimePosted; if (message.LastReplyId != 0) { var lastReplyDetails = (from item in DbContext.Messages join postedBy in DbContext.Users on item.PostedById equals postedBy.Id where item.Id == message.LastReplyId select new { postedBy.DisplayName, item.ShortPreview }).FirstOrDefault(); if (lastReplyDetails != null) { messagePreview.LastReplyId = message.LastReplyId; messagePreview.LastReplyPreview = lastReplyDetails.ShortPreview; messagePreview.LastReplyByName = lastReplyDetails.DisplayName; messagePreview.LastReplyById = message.LastReplyById; messagePreview.LastReplyPosted = message.LastReplyPosted.ToPassedTimeString(); messagePreview.LastReplyPostedDT = message.LastReplyPosted; lastMessageTime = message.LastReplyPosted; } } if (lastMessageTime > historyTimeLimit) { messagePreview.Unread = GetUnreadLevel(message.Id, lastMessageTime, participation, viewLogs); } } return(messagePreviews); }