Exemple #1
0
 public List <Profile> GetOnlineMembers(int groupId)
 {
     return(groupController.GetOnlineMembers(groupId));
 }
Exemple #2
0
        public List <Profile> JoinChatWithGroup(int groupId, int chatId)
        {
            List <Profile> profiles = groupController.GetOnlineMembers(groupId); //gets all online members of the group
            Chat           chat     = FindChat(chatId);                          //finds active chat

            try
            {
                if (chat != null)                                                                                              //chat is active right now
                {
                    lock (chat)                                                                                                //locks the chat object so only one process can access it
                    {
                        List <Tuple <Profile, object, string> > membersToJoin = new List <Tuple <Profile, object, string> >(); //list where members who have to join will be stored
                        foreach (Profile member in profiles)
                        {
                            Tuple <Profile, object, string> user = FindChat(chatId).Users.Find(
                                delegate(Tuple <Profile, object, string> tuple)
                            {
                                return(tuple.Item1.ProfileID == member.ProfileID);
                            }
                                );

                            if (user == null)                                                             //if user isnt in chat already
                            {
                                membersToJoin.Add(new Tuple <Profile, object, string>(member, null, "")); //adds the member to list (who will join chat)
                            }
                        }

                        if ((chat.MaxNrOfUsers - chat.Users.Count) >= membersToJoin.Count) //ok nr of people in chat
                        {
                            chat.Users.AddRange(membersToJoin);                            //adds this list to already existing list
                            return(profiles);                                              //persons added to chat
                        }
                        else
                        {
                            return(new List <Profile>());//too few places
                        }
                    }
                }
                else
                {
                    lock (chats)
                    {
                        chat = dbChat.GetChat(chatId);//Gets chat from database
                        if (chat.MaxNrOfUsers >= profiles.Count)
                        {
                            List <Tuple <Profile, object, string> > membersToJoin = new List <Tuple <Profile, object, string> >();
                            foreach (Profile user in profiles)
                            {
                                membersToJoin.Add(new Tuple <Profile, object, string>(user, null, "")); //member added to list of members to join
                            }
                            chat.Users = membersToJoin;                                                 //adds user to chat
                            chats.Add(chat);                                                            //adds chat to chat list
                            return(profiles);                                                           //Returns joined users
                        }
                        else
                        {
                            return(new List <Profile>());//too few spots in chatbox (no one has joined)
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(new List <Profile>());//something went wrong (no one should be called back)
            }
        }