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 MessageViewModel(DateTime messageTime, string senderNick, FileId fileId, RoomViewModel roomVm)
            : this(Room.SpecificMessageId, roomVm, true)
        {
            this.fileId = fileId;

              Sender = new UserViewModel(senderNick, parentRoom);
              Progress = 0;

              var localMessageTime = messageTime.ToLocalTime();
              Title = Localizer.Instance.Localize(FromKey, localMessageTime.ToString(TimeFormat));

              var sizeDim = string.Empty;
              var size = 0L;

              using (var client = ClientModel.Get())
              {
            var file = GetFile(client, fileId);

            if (file.Size < 1024)
            {
              sizeDim = Localizer.Instance.Localize(ByteStrKey);
              size = file.Size;
            }

            if (file.Size >= 1024 && file.Size < 1024 * 1024)
            {
              sizeDim = Localizer.Instance.Localize(KByteStrKey);
              size = file.Size / 1024;
            }

            if (file.Size >= 1024 * 1024)
            {
              sizeDim = Localizer.Instance.Localize(MByteStrKey);
              size = file.Size / (1024 * 1024);
            }

            Text = file.Name + string.Format(SizeFormat, size, sizeDim);
              }

              Type = MessageType.File;
              DownloadFileCommand = new Command(DownloadFile, _ => ClientModel.Api != null);

              NotifierContext.DownloadProgress += CreateSubscriber<FileDownloadEventArgs>(ClientDownloadProgress);
              NotifierContext.PostedFileDeleted += CreateSubscriber<FileDownloadEventArgs>(ClientPostedFileDeleted);
        }
Beispiel #3
0
    public MessageViewModel(UserViewModel sender, string fileName, FileDescription fileDescription, RoomViewModel room)
      : this(Room.SpecificMessageId, room, true)
    {
      NotifierContext.DownloadProgress += ClientDownloadProgress;
      NotifierContext.PostedFileDeleted += ClientPostedFileDeleted;

      Sender = sender;
      File = fileDescription;
      Progress = 0;
      Title = string.Format(From, DateTime.Now.ToString(TimeFormat));

      string sizeDim = string.Empty;
      float size = 0;

      if (fileDescription.Size < 1024)
      {
        sizeDim = ByteStr;
        size = fileDescription.Size;
      }

      if (fileDescription.Size >= 1024 && fileDescription.Size < 1024 * 1024)
      {
        sizeDim = KByteStr;
        size = fileDescription.Size / 1024.0f;
      }

      if (fileDescription.Size >= 1024 * 1024)
      {
        sizeDim = MByteStr;
        size = fileDescription.Size / (1024.0f * 1024.0f);
      }
      
      Text = fileName + string.Format(SizeFormat, size, sizeDim);
      Type = MessageType.File;
      DownloadFileCommand = new Command(DownloadFile, Obj => ClientModel.Client != null);
    }
Beispiel #4
0
    public MessageViewModel(long messageId, UserViewModel sender, UserViewModel receiver, string message, bool isPrivate, RoomViewModel room)
      : this(messageId, room, false)
    {
      Text = message;
      Sender = sender;
      Receiver = receiver;
      Type = isPrivate ? MessageType.Private : MessageType.Common;

      EditMessageCommand = new Command(EditMessage, Obj => ClientModel.Client != null);

      Title = string.Format(isPrivate ? PMForm : From, DateTime.Now.ToString(TimeFormat));
    }
 public UserListItem(UserViewModel user)
 {
   User = user;
   Invite = false;
 }
Beispiel #6
0
 public void AddPrivateMessage(UserViewModel sender, UserViewModel receiver, string message)
 {
     AddMessage(new MessageViewModel(Room.SpecificMessageId, sender, receiver, message, true, this));
 }
Beispiel #7
0
 public void AddMessage(long messageId, UserViewModel sender, string message)
 {
     AddMessage(new MessageViewModel(messageId, sender, null, message, false, this));
 }
Beispiel #8
0
 public void AddFileMessage(UserViewModel sender, FileDescription file)
 {
     AddMessage(new MessageViewModel(sender, file.Name, file, this));
 }
Beispiel #9
0
        public MessageViewModel(long messageId, DateTime messageTime, string senderNick, string receiverNick, string message, bool isPrivate, RoomViewModel room)
            : this(messageId, room, false)
        {
            Text = message;
              Sender = new UserViewModel(senderNick, room);
              Receiver = new UserViewModel(receiverNick, room);
              Type = isPrivate ? MessageType.Private : MessageType.Common;

              EditMessageCommand = new Command(EditMessage, _ => ClientModel.Client != null);

              var localMessageTime = messageTime.ToLocalTime();
              Title = Localizer.Instance.Localize(isPrivate ? PMFormKey : FromKey, localMessageTime.ToString(TimeFormat));
        }
Beispiel #10
0
        private void RefreshReceivers(ClientGuard client)
        {
            recivers.Clear();

              var selectedReceiverNick = selectedReceiver == allInRoom
            ? null
            : selectedReceiver.Nick;
              var newReciver = (UserViewModel) null;

              foreach (var user in client.Users.Values)
              {
            if (user.Nick == client.User.Nick)
              continue;

            var receiver = new UserViewModel(user.Nick, this);
            recivers.Add(receiver);

            if (user.Nick == selectedReceiverNick)
              newReciver = receiver;
              }
              OnPropertyChanged("Receivers");

              selectedReceiver = newReciver == null
            ? allInRoom
            : newReciver;
              OnPropertyChanged("SelectedReceiver");
        }
Beispiel #11
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);
        }
Beispiel #12
0
 public void AddMessage(long messageId, UserViewModel sender, string message)
 {
     AddMessage(new MessageViewModel(messageId, sender, null, message, false, this));
 }
Beispiel #13
0
    public bool Equals(UserViewModel viewModel)
    {
      if (viewModel == null)
        return false;

      if (ReferenceEquals(viewModel, this))
        return true;

      if (viewModel.Info == null)
        return Info == null;

      return viewModel.Info.Equals(Info);
    }