private void FriendAdded(FriendStatus friendStatus) { UserWithStatus friend = new UserWithStatus(); friend._id = friendStatus._id; friend.username = friendStatus.username; friend.status = FriendStatusOffline; AddOrUpdateFriend(friend, friendStatus.lobbies); var todoList = new List<UIElement>(); foreach (var item in stackPanelFriendRequestsFrom.Children) { var request = item as FriendRequestFromUserControl; if (request == null) continue; if (request.Username == friendStatus.username) todoList.Add((UIElement)item); } foreach (var item in todoList) stackPanelFriendRequestsFrom.Children.Remove(item); }
private void AddOrUpdateFriend(UserWithStatus friend, List<string> lobbies) { var user = _userData.GetPgUser(friend); user.Status = friend.status; user.Username = friend.username; _userData.AddFriend(user); if (lobbies == null) { var count = _userData.Launchers.Count; var index = _deleteMeLater.Next(count + 1); if (index == count) lobbies = new List<string>(); else lobbies = new List<string>(new[] { _userData.Launchers[index].Id }); } var list = user.Lobbies; foreach (var game_id in lobbies) { LauncherInfo info; if (!UserDataManager.UserData.TryGetGame(game_id, out info)) throw new NotImplementedException("Game not found: " + game_id); if (!list.Contains(info)) list.Add(info); } }