コード例 #1
0
ファイル: ChatRoom.cs プロジェクト: JustynaJuza/Magic
 public ChatRoomViewModel(ChatRoom room)
 {
     Id = room.Id;
     Name = room.Name;
     IsGameRoom = room.IsGameRoom;
     IsPrivate = room.IsPrivate;
     TabColorCode = room.TabColorCode;
     Users = room.GetUserList();
     Log = (room.Log != null ? (ChatLogViewModel) room.Log.GetViewModel() : new ChatLogViewModel());
 }
コード例 #2
0
ファイル: ChatRoom.cs プロジェクト: JustynaJuza/Magic
 public ChatRoomViewModel(ChatRoom room, string userId)
     : this(room)
 {
     Log = (room.Log != null ? (ChatLogViewModel)room.Log.GetViewModel(userId) : new ChatLogViewModel());
 }
コード例 #3
0
ファイル: ChatHub.cs プロジェクト: JustynaJuza/Magic
        // Create new chat room with given settings and for specific users only if it's private.
        public void CreateChatRoom(string roomId = null, bool isGameRoom = false, bool isPrivate = false, IList<string> recipientNames = null)
        {
            using (var context = new MagicDbContext())
            {
                var chatRoom = new ChatRoom(roomId)
                {
                    IsGameRoom = isGameRoom,
                    IsPrivate = isPrivate,
                    Name = (isGameRoom ? "Game" : null),
                    TabColorCode = (isGameRoom ? string.Empty.AssignRandomColorCode() : null)
                };
                context.Insert(chatRoom);

                if (!isPrivate) return;

                // TODO: check how recipients behave after chacking chatroom existance and if thee can be any null exception
                var recipients = recipientNames.Distinct().Select(userName => context.Users.FirstOrDefault(u => u.UserName == userName)).ToList();

                foreach (var user in recipients)
                {
                    AddUserToRoom(chatRoom.Id, user.Id);
                    SubscribeActiveConnections(chatRoom.Id, user.Id);
                }
            }
        }