private void RefreshReceivers(ClientGuard client) { _recivers.Clear(); LightUserViewModel newReciver = null; var selectedReceiverId = _selectedReceiver == _allInRoomReceiver ? UserId.Empty : _selectedReceiver.UserId; foreach (var user in client.Chat.GetUsers()) { if (user.Id == client.Chat.User.Id) { continue; } var receiver = new LightUserViewModel(user.Id, this); _recivers.Add(receiver); if (user.Id == selectedReceiverId) { newReciver = receiver; } } SelectedReceiver = newReciver == null ? _allInRoomReceiver : newReciver; OnPropertyChanged(nameof(Receivers)); }
private void Init(MainViewModel main, IEnumerable <UserId> userIds) { _mainViewModel = main; Messages = new ObservableCollection <MessageViewModel>(); SelectedReceiver = _allInRoomReceiver = new LightUserViewModel(AllInRoomKey, this); _recivers = new List <LightUserViewModel>(); _messageIds = new HashSet <long>(); var userViewModels = userIds == null ? Enumerable.Empty <UserViewModel>() : userIds.Select(id => new UserViewModel(id, 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); Events.ReceiveMessage += CreateSubscriber <ReceiveMessageEventArgs>(ClientReceiveMessage); Events.RoomOpened += CreateSubscriber <RoomOpenedEventArgs>(ClientRoomOpened); Events.RoomRefreshed += CreateSubscriber <RoomRefreshedEventArgs>(ClientRoomRefreshed); }
public MessageViewModel(long messageId, DateTime messageTime, UserId senderId, UserId receiverId, string message, bool isPrivate, RoomViewModel room) : this(messageId, room, false) { Text = message; Title = Localizer.Instance.Localize(isPrivate ? PMFormKey : FromKey, GetTimeStr(messageTime)); Sender = new LightUserViewModel(senderId, room); Receiver = new LightUserViewModel(receiverId, room); Type = isPrivate ? MessageType.Private : MessageType.Common; EditMessageCommand = new Command(EditMessage, _ => ClientModel.Client != null); }
public MessageViewModel(DateTime messageTime, UserId senderId, FileId fileId, RoomViewModel roomVm) : this(Room.SpecificMessageId, roomVm, true) { this._fileId = fileId; Sender = new LightUserViewModel(senderId, _parentRoom); Progress = 0; Title = Localizer.Instance.Localize(FromKey, GetTimeStr(messageTime)); 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); Events.DownloadProgress += CreateSubscriber <FileDownloadEventArgs>(ClientDownloadProgress); Events.PostedFileDeleted += CreateSubscriber <FileDownloadEventArgs>(ClientPostedFileDeleted); }