Example #1
0
        public List <ParticipantResponseViewModel> getChatParticipantList()
        {
            List <ParticipantResponseViewModel> result = new List <ParticipantResponseViewModel>();
            var rulesets = _context.RuleSets.Include(x => x.AspNetUser).Where(x => x.AspNetUser.IsGm == true && x.IsDeleted != true).ToList();

            //////////Need to be commented..
            //users = users.Where(x => x.Id == "248c6bae-fab3-4e1f-b91b-f674de70a65d").ToList();
            //////////
            foreach (var ruleset in rulesets)
            {
                ParticipantResponseViewModel obj = new ParticipantResponseViewModel()
                {
                    Metadata = new ParticipantMetadataViewModel()
                    {
                        TotalUnreadMessages = 0
                    },
                    Participant = new ChatParticipantViewModel()
                    {
                        //DisplayName = ruleset.AspNetUser.UserName,
                        //Id = ruleset.AspNetUser.Id,
                        //Avatar = ruleset.AspNetUser.ProfileImage,
                        //CampaignID = ruleset.RuleSetId,
                        //UserId= ruleset.AspNetUser.Id


                        //DisplayName = ruleset.RuleSetName,
                        //Avatar = ruleset.ImageUrl,
                        DisplayName = ruleset.AspNetUser.UserName + " (GM)",
                        Avatar      = ruleset.AspNetUser.ProfileImage,
                        Id          = ruleset.RuleSetId.ToString(),
                        CampaignID  = ruleset.RuleSetId,
                        UserId      = ruleset.AspNetUser.Id,
                        Status      = 3,
                        //UserAvatar= ruleset.AspNetUser.ProfileImage,
                        //UserDisplayName= ruleset.AspNetUser.UserName,
                    }
                };
                result.Add(obj);
            }
            var chars = _context.PlayerInvites.Where(x => x.PlayerCharacterID != null && x.IsDeleted != true).Include(x => x.PlayerCharacter).OrderBy(x => x.PlayerCharacter.CharacterName).ToList();

            //////////Need to be commented..
            //chars = chars.Where(x => x.PlayerCharacterID == 569 || x.PlayerCharacterID == 570).ToList();
            //////////
            ///
            foreach (var character in chars)
            {
                ParticipantResponseViewModel charObj = new ParticipantResponseViewModel()
                {
                    Metadata = new ParticipantMetadataViewModel()
                    {
                        TotalUnreadMessages = 0
                    },
                    Participant = new ChatParticipantViewModel()
                    {
                        DisplayName = character.PlayerCharacter.CharacterName,
                        Id          = character.PlayerCharacterID.ToString(),
                        Avatar      = character.PlayerCharacter.ImageUrl,

                        CampaignID          = 0,
                        CharacterCampaignID = (int)character.PlayerCampaignID,
                        CharacterID         = (int)character.PlayerCharacterID,
                        UserId = character.PlayerCharacter.UserId,
                        Status = 3
                    }
                };
                //if (!result.Where(x => x.Participant.UserId == charObj.Participant.UserId).Any())
                //{
                result.Add(charObj);
                //}
                ////////else {
                ////////    var obj = result.Where(x => x.Participant.UserId == charObj.Participant.UserId).FirstOrDefault();
                ////////    if (obj!=null)
                ////////    {
                ////////        result.Remove(obj);
                ////////        obj.Participant.CampaignID = 0;
                ////////        obj.Participant.CharacterCampaignID = (int)character.PlayerCampaignID;
                ////////        obj.Participant.CharacterID = (int)character.PlayerCharacterID;
                ////////        result.Add(obj);
                ////////    }
                ////////}
            }

            return(result);
        }
Example #2
0
        public async Task <IActionResult> Participants([FromBody] dynamic payload)
        {
            string srchTxt = payload.searchText;


            string userId       = this.HttpContext.User.GetClaim(OpenIdConnectConstants.Claims.Subject);
            string userEmail    = this._ctx.Users.Find(userId).Email;
            var    msgListQuery = (from g in this._ctx.ChatGroups.Include(d => d.DateSeen).ThenInclude(d => d.User)
                                   join p in this._ctx.Participants.Include(d => d.User) on g equals p.Group into arrPart
                                   join ms in this._ctx.ChatMessages on g equals ms.ChatGroup into chatMessages
                                   where g.ParticipantType == EnumChatGroupParticipantType.user &&
                                   arrPart.Any(d => d.User.Id == userId)



                                   select new {
                Particpants = arrPart,
                ChatGroup = g,
                UnreadMessageCount = chatMessages
                                     .Where(d => d.DateSent > g.DateSeen
                                            .Where(s => s.User.Id == userId)
                                            .Select(ds => ds.DateSeen)
                                            .Max())
                                     .Count()
            }
                                   );

            Console.WriteLine(msgListQuery.ToString());
            var msgList = await msgListQuery.ToArrayAsync();

            var userList = await(
                from u in this._ctx.Users
                where !msgList.Any(d => d.Particpants.Any(p => p.User == u)) &&
                u.Id != userId
                select new { Id = u.Id, Email = u.Email, }
                ).ToArrayAsync();


            List <ParticipantResponseViewModel> resp = new List <ParticipantResponseViewModel>();

            foreach (var item in msgList)
            {
                var part = new ParticipantResponseViewModel();
                part.Participants = new List <ChatParticipantViewModel>();


                foreach (var p in item.Particpants.OrderBy(d => d.User.Id == userId))
                {
                    var connectedPart = GroupChatHub.getConnectedParticpant(p.User.Id).FirstOrDefault();

                    part.Participants.Add(new ChatParticipantViewModel()
                    {
                        DisplayName     = p.User.Email,
                        UserId          = p.User.Id,
                        ParticipantType = ChatParticipantTypeEnum.User,
                        Status          = connectedPart == null ? EnumChatParticipantStatus.Offline : EnumChatParticipantStatus.Online,
                        Email           = p.User.Email
                    });
                }



                part.Metadata = new ParticipantMetadataViewModel()
                {
                    TotalUnreadMessages = item.UnreadMessageCount,
                    Title   = item.ChatGroup.Title,
                    GroupId = item.ChatGroup != null?item.ChatGroup.Id.ToString() : ""
                };
                resp.Add(part);
            }


            foreach (var user in userList)
            {
                var part = new ParticipantResponseViewModel();
                part.Participants = new List <ChatParticipantViewModel>();



                var connectedPart = GroupChatHub.getConnectedParticpant(user.Id).FirstOrDefault();

                part.Participants.Add(new ChatParticipantViewModel()
                {
                    DisplayName     = user.Email,
                    UserId          = user.Id,
                    ParticipantType = ChatParticipantTypeEnum.User,
                    Status          = connectedPart == null ? EnumChatParticipantStatus.Offline : EnumChatParticipantStatus.Online,
                    Email           = user.Email
                });

                part.Participants.Add(new ChatParticipantViewModel()
                {
                    DisplayName     = userEmail,
                    UserId          = userId,
                    ParticipantType = ChatParticipantTypeEnum.User,
                    Status          = EnumChatParticipantStatus.Online,
                    Email           = userEmail
                });



                part.Metadata = new ParticipantMetadataViewModel()
                {
                    TotalUnreadMessages = 0,
                    GroupId             = "",
                    Title = part.Participants.First().DisplayName
                };

                resp.Add(part);
            }

            return(Json(resp.OrderBy(d => d.Participants.Any(p => p.Status == EnumChatParticipantStatus.Online)).ThenBy(d => d.Metadata.Title)));
        }