Ejemplo n.º 1
0
        ///Returns a list of DBNotifications for the user ("news") sorted by time
        public async Task<List<DBItem>> GetNewsFeed()
        {
            List<DBItem> list = new List<DBItem>();

            //by default, limits the size of each

            //medals
            var medalList = await medalTable.OrderByDescending(item=>item.Time).Where(item=>item.AccountId==User.Id).Take(2).ToListAsync();
            list.AddRange(medalList);
            //droplets
            var dropletList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => item.AccountId == User.Id && item.Type == "droplet").Take(4).ToListAsync();
            list.AddRange(dropletList);
            //rank
            if(User.RatingNotificationToggle){
                var rankList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item=>(item.AccountId==User.Id && item.Type=="rank")).Take(1).ToListAsync();
                list.AddRange(rankList);
            }
            //club requests
            var clubrqList = await clubRequestTable.OrderByDescending(item => item.Time).Where(item => item.AccountId == User.Id).Take(4).ToListAsync();
            list.AddRange(clubrqList);
            //club invites
            var invitesList = await inviteTable.OrderByDescending(item => item.Time).Where(item => item.RecipientId == User.Id).Take(4).ToListAsync();
            list.AddRange(invitesList);
            //club warnings
            //NOTE: is there a better way to do this than by giving each user a warning individually?
            var warningList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => item.AccountId == User.Id && item.Type == "warning").Take(4).ToListAsync();
            list.AddRange(warningList);
            //club creations/joins
            var joinsList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => item.AccountId == User.Id && item.Type == "join").Take(4).ToListAsync();
            list.AddRange(joinsList);
            //friend requests
            var frqList = await friendRequestTable.OrderByDescending(item => item.Time).Where(item => (item.AuthorId == User.Id
                || item.RecipientId == User.Id)).Take(4).ToListAsync();
            list.AddRange(frqList);
            //accepted friend requests
            var friendsList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => item.AccountId == User.Id && item.Type == "friend").Take(4).ToListAsync();
            list.AddRange(friendsList);
            //bans
            var banList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => (item.AccountId == User.Id && item.Type == "ban")).Take(2).ToListAsync();
            list.AddRange(banList);
            //club reports
            var clubReportList = await dbNotificationTable.OrderByDescending(item => item.Time).Where(item => (item.AccountId == User.Id && item.Type == "clubReport")).Take(2).ToListAsync();
            list.AddRange(clubReportList);
            

            //TODO: THIS IS HALF DONE
            list.OrderByDescending(item=>item.Time);

            return list;
        }
Ejemplo n.º 2
0
        ///returns a list of comments and club requests; is what users see in chat
        ///returns 20-25 items; indexCommentId is used to retrieve sets of comments; if "", gets 20 most recent items
        ///if not "", gets the 20 most recent comments prior to the passed in comment;
        ///must pass in index type - can be "comment" or "clubRequest"
        public async Task<List<DBItem>> GetChat(string clubId, string indexType, string indexId) {
            List<DBItem> list = new List<DBItem>();
            List<Comment> commentList = new List<Comment>();
            List<ClubRequest> requestList = new List<ClubRequest>();

            //if empty string, get newest ~25 items
            if (indexId.Equals(""))
            {
                //get 20 most recent comments
                commentList = await commentTable.OrderByDescending(item => item.Time).Where(item => item.ClubId == clubId)
                    .Take(20).ToListAsync();
                //get 5 most recent club requests that are visible
                requestList = await clubRequestTable.OrderByDescending(item => item.Time).Where(item => item.ClubId == clubId && item.Visible == true)
                    .Take(5).ToListAsync();
            }
            else {
                //get the reference point comment; use the passed in type to determine what class it is
                DBItem refItem;

                if (indexType.Equals("comment"))
                {
                    refItem = await commentTable.LookupAsync(indexId);
                }
                else {
                    refItem = await clubRequestTable.LookupAsync(indexId);
                }

                //get 20 most recent comments; skip determined by time
                commentList = await commentTable.OrderByDescending(item => item.Time).Where(item => item.ClubId == clubId
                    && item.Time<refItem.Time).Take(20).ToListAsync();
                //get 5 most recent club requests that are visible; skip determined by time
                requestList = await clubRequestTable.OrderByDescending(item => item.Time).Where(item => item.ClubId == clubId && item.Visible == true
                    && item.Time < refItem.Time).Take(5).ToListAsync();
            }
            
            //add to list and sort
            list.AddRange(commentList);
            list.AddRange(requestList);
            list.OrderByDescending(item=>item.Time);

            return list;
        }