private void SetChatRooms(GitterChatRoom[] rooms) { IEnumerable <GroupedMenuItem> intermediate; if (rooms == null || rooms.Length == 0) { intermediate = new GroupedMenuItem[0]; } else { if (SearchGitter) { intermediate = new[] { new GroupedMenuItem(AppResources.MenuGroupSearchResults, rooms.Where(r => !r.IsSuggestion)), new GroupedMenuItem(AppResources.MenuGroupSuggestions, rooms.Where(r => r.IsSuggestion)), }; } else { intermediate = new[] { new GroupedMenuItem(AppResources.MenuGroupStarredUnreads, rooms.Where(r => r.IsStarred && r.HasUnread).OrderBy(r => r.Room.FavouriteIndex)), new GroupedMenuItem(AppResources.MenuGroupUnreads, rooms.Where(r => !r.IsStarred && r.HasUnread).OrderBy(r => r.Name.ToUpperInvariant())), new GroupedMenuItem(AppResources.MenuGroupStarred, rooms.Where(r => r.IsStarred && !r.HasUnread).OrderBy(r => r.Room.FavouriteIndex)), new GroupedMenuItem(AppResources.MenuGroupRooms, rooms.Where(r => !r.IsStarred && !r.HasUnread && !r.IsPerson).OrderBy(r => r.Name.ToUpperInvariant())), new GroupedMenuItem(AppResources.MenuGroupDirects, rooms.Where(r => !r.IsStarred && !r.HasUnread && r.IsPerson).OrderBy(r => r.Name.ToUpperInvariant())) }; } } // remove empty items var results = intermediate.Where(g => g.Any()).ToArray(); // handle no items if (results.Length == 0) { results = new[] { new GroupedMenuItem(AppResources.MenuGroupNoResults) }; } // update the UI ChatRooms.Clear(); var groups = new ObservableCollection <GroupedMenuItem>(results); foreach (var group in groups) { ChatRooms.Add(group); } }
private async void GetProfile() { var contactService = new ContactService(); var result = await contactService.GetProfile(MyAccount.IdUser); if (result != null && result.Contacts != null) { foreach (var item in result.Contacts) { var room = new ConversationRoom(ConversationType.Private, MyAccount, item); room.OnSendMessage += Room_OnSendMessage; ChatRooms.Add(room); } } }
public async Task CreateRoom() { if (string.IsNullOrEmpty(NewRoomName)) { return; } var newChatRoom = new ChatRoomDto { Name = NewRoomName }; newChatRoom.Id = ChatFacade.CreateChatRoom(newChatRoom); ChatRooms.Add(newChatRoom); NewRoomName = ""; await Service.ChangeViewModelForConnectionsAsync( (ChatViewModel viewModel) => { viewModel.ChatRooms.Add(newChatRoom); }, ChatFacade.GetAllConnectedUsers() .Select(s => s.ConnectionId) .ToList()); }