Inheritance: BaseViewModel
Beispiel #1
1
        public RoomViewModel(MainViewModel mainViewModel, Room room, IList<User> users)
            : base(true)
        {
            Description = room;
              MainViewModel = mainViewModel;
              Messages = new ObservableCollection<MessageViewModel>();
              allInRoom = new UserViewModel(new User("Все в комнате", Color.Black), this);
              messageIds = new HashSet<long>();
              Users = new ObservableCollection<UserViewModel>(users == null
            ? Enumerable.Empty<UserViewModel>()
            : room.Users.Select(user => new UserViewModel(users.Single(u => u.Equals(user)), this)));

              SendMessageCommand = new Command(SendMessage, Obj => ClientModel.Client != null);
              PastReturnCommand = new Command(PastReturn);
              AddFileCommand = new Command(AddFile, Obj => ClientModel.Client != null);
              InviteInRoomCommand = new Command(InviteInRoom, Obj => ClientModel.Client != null);
              KickFromRoomCommand = new Command(KickFromRoom, Obj => ClientModel.Client != null);
              ClearSelectedMessageCommand = new Command(ClearSelectedMessage, Obj => ClientModel.Client != null);

              MainViewModel.AllUsers.CollectionChanged += AllUsersCollectionChanged;
              NotifierContext.ReceiveMessage += ClientReceiveMessage;
              NotifierContext.RoomRefreshed += ClientRoomRefreshed;
        }
Beispiel #2
0
        public RoomViewModel(MainViewModel main)
            : base(main, true)
        {
            Init(main, null);

              Name = ServerModel.MainRoomName;
              Type = RoomType.Chat;
              Enabled = true;
        }
Beispiel #3
0
        public RoomViewModel(MainViewModel main, string roomName, IList<string> usersNicks)
            : base(main, true)
        {
            Init(main, usersNicks);

              using (var client = ClientModel.Get())
              {
            Room room;
            if (!client.Rooms.TryGetValue(roomName, out room))
              throw new ArgumentException("roomName");

            Name = room.Name;
            Type = room.Type;
            Enabled = room.Enabled;

            FillMessages(client);
            RefreshReceivers(client);
              }
        }
Beispiel #4
0
        private void Init(MainViewModel main, IList<string> usersNicks)
        {
            mainViewModel = main;
              Messages = new ObservableCollection<MessageViewModel>();
              SelectedReceiver = allInRoom = new UserViewModel(AllInRoomKey, null, this);
              recivers = new List<UserViewModel>();
              messageIds = new HashSet<long>();

              var userViewModels = usersNicks == null
            ? Enumerable.Empty<UserViewModel>()
            : usersNicks.Select(user => new UserViewModel(user, this));
              Users = new ObservableCollection<UserViewModel>(userViewModels);

              SendMessageCommand = new Command(SendMessage, _ => ClientModel.Api != null && ClientModel.Client.IsConnected);
              PastReturnCommand = new Command(PastReturn);
              AddFileCommand = new Command(AddFile, _ => ClientModel.Api != null);
              InviteInRoomCommand = new Command(InviteInRoom, _ => ClientModel.Api != null);
              KickFromRoomCommand = new Command(KickFromRoom, _ => ClientModel.Api != null);
              ClearSelectedMessageCommand = new Command(ClearSelectedMessage);
              EnableVoiceCommand = new Command(EnableVoice, _ => Type == RoomType.Voice && !Enabled);
              DisableVoiceCommand = new Command(DisableVoice, _ => Type == RoomType.Voice && Enabled);

              NotifierContext.ReceiveMessage += CreateSubscriber<ReceiveMessageEventArgs>(ClientReceiveMessage);
              NotifierContext.RoomOpened += CreateSubscriber<RoomEventArgs>(ClientRoomOpened);
              NotifierContext.RoomRefreshed += CreateSubscriber<RoomEventArgs>(ClientRoomRefreshed);
        }