示例#1
0
        public async Task <List <ViewModels.Messages.DisplayMessage> > GetUserMessages(string userId, int page)
        {
            var take = CurrentUser.ApplicationUser.MessagesPerPage;
            var skip = (page - 1) * take;

            var messageQuery = from message in DbContext.Messages
                               where message.PostedById == userId
                               where !message.Deleted
                               orderby message.Id descending
                               select new {
                message.Id,
                message.TopicId
            };

            var messageIds = new List <int>();
            var attempts   = 0;
            var skipped    = 0;

            foreach (var message in messageQuery)
            {
                if (!await BoardRepository.CanAccess(message.TopicId))
                {
                    if (attempts++ > 100)
                    {
                        break;
                    }

                    continue;
                }

                if (skipped++ < skip)
                {
                    continue;
                }

                messageIds.Add(message.Id);

                if (messageIds.Count == take)
                {
                    break;
                }
            }

            var messages = await GetMessages(messageIds);

            foreach (var message in messages)
            {
                message.ShowControls = false;
            }

            return(messages);
        }
示例#2
0
        public async Task <List <int> > GetIndexIds(int boardId, int page, int unreadFilter)
        {
            var take             = UserContext.ApplicationUser.TopicsPerPage;
            var skip             = (page - 1) * take;
            var historyTimeLimit = DateTime.Now.AddDays(-14);

            var topicQuery = from topic in DbContext.Topics
                             where !topic.Deleted
                             select new {
                topic.Id,
                topic.LastMessageTimePosted,
                topic.Pinned
            };

            if (boardId > 0)
            {
                topicQuery = from topic in DbContext.Topics
                             join topicBoard in DbContext.TopicBoards on topic.Id equals topicBoard.TopicId
                             where topicBoard.BoardId == boardId
                             where !topic.Deleted
                             select new {
                    topic.Id,
                    topic.LastMessageTimePosted,
                    topic.Pinned
                };
            }

            if (unreadFilter > 0)
            {
                topicQuery = topicQuery.Where(m => m.LastMessageTimePosted > historyTimeLimit);
            }

            var sortedTopicQuery = from topic in topicQuery
                                   orderby topic.LastMessageTimePosted descending
                                   orderby topic.Pinned descending
                                   select new {
                topic.Id,
                topic.LastMessageTimePosted
            };

            var topicIds = new List <int>();
            var attempts = 0;
            var skipped  = 0;

            foreach (var topic in sortedTopicQuery)
            {
                if (!await BoardRepository.CanAccess(topic.Id))
                {
                    if (attempts++ > 100)
                    {
                        break;
                    }

                    continue;
                }

                var unreadLevel = unreadFilter == 0 ? 0 : GetUnreadLevel(topic.Id, topic.LastMessageTimePosted);

                if (unreadLevel < unreadFilter)
                {
                    if (attempts++ > 100)
                    {
                        break;
                    }

                    continue;
                }

                if (skipped++ < skip)
                {
                    continue;
                }

                topicIds.Add(topic.Id);

                if (topicIds.Count == take)
                {
                    break;
                }
            }

            return(topicIds);
        }
示例#3
0
        public async Task <List <int> > GetIndexIds(int boardId, int page, int unreadFilter)
        {
            var take             = UserContext.ApplicationUser.TopicsPerPage;
            var skip             = (page - 1) * take;
            var historyTimeLimit = DateTime.Now.AddDays(-14);

            var messageQuery = from message in DbContext.Messages
                               where message.ParentId == 0
                               select new {
                message.Id,
                message.LastReplyPosted,
                message.Pinned
            };

            if (boardId > 0)
            {
                messageQuery = from message in DbContext.Messages
                               join messageBoard in DbContext.MessageBoards on message.Id equals messageBoard.MessageId
                               where message.ParentId == 0
                               where messageBoard.BoardId == boardId
                               select new {
                    message.Id,
                    message.LastReplyPosted,
                    message.Pinned
                };
            }

            if (unreadFilter > 0)
            {
                messageQuery = messageQuery.Where(m => m.LastReplyPosted > historyTimeLimit);
            }

            var sortedMessageQuery = from message in messageQuery
                                     orderby message.LastReplyPosted descending
                                     orderby message.Pinned descending
                                     select new {
                message.Id,
                message.LastReplyPosted
            };

            var messageIds = new List <int>();
            var attempts   = 0;
            var skipped    = 0;

            foreach (var message in sortedMessageQuery)
            {
                if (!await BoardRepository.CanAccess(message.Id))
                {
                    if (attempts++ > 100)
                    {
                        break;
                    }

                    continue;
                }

                var unreadLevel = unreadFilter == 0 ? 0 : GetUnreadLevel(message.Id, message.LastReplyPosted);

                if (unreadLevel < unreadFilter)
                {
                    if (attempts++ > 100)
                    {
                        break;
                    }

                    continue;
                }

                if (skipped++ < skip)
                {
                    continue;
                }

                messageIds.Add(message.Id);

                if (messageIds.Count == take)
                {
                    break;
                }
            }

            return(messageIds);
        }