//NOTE: make sure that I'm delete member junction when deleting club ///Returns a list of the users clubs arranged by most recent activity public async Task<List<Club>> GetActiveClubs() { var memberList = await memberJuncTable.Where(item => item.AccountId == User.Id).ToListAsync(); List<Club> clubList = new List<Club>(); for (int i = 0; i < memberList.Count; i++) { string clubId = memberList[i].ClubId; Club club = (await clubTable.Where(item => item.Id == clubId).ToListAsync())[0]; clubList.Add(club); } //remove clubs not in current cloud clubList = clubList.Where(item => item.CloudId == User.CurrentCloudId).ToList(); clubList.OrderByDescending(item => item.LatestActivity); return clubList; }
///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; }
///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; }