private byte[] HandleGetFriend(EventDataMsg eventMsg, MsgContext ctx) { User userReq = _api.Services.User.GetUserByClientId(ctx.senderId); if (userReq == null) { throw new FriendsAppProviderException("You must be signedIn to add some friends."); } User userTo = User.Get(eventMsg.LongValue); if (userTo == null) { throw new FriendsAppProviderException("User with this ID could not be found."); } List <ulong> friends = _friendsData.GetFriendsList(userReq.Id); if (!friends.Contains(userTo.Id)) { throw new FriendsAppProviderException("This user is not your friend."); } FriendsAppUser friendDetail = ToFriendsAppUser(userTo.Id); FriendsAppMsg msg = new FriendsAppMsg(); msg.FriendDetail = friendDetail.ToNetworkModel(); return(msg.ToByteArray()); }
private void RenderPage(int pageNum) { if (_friends == null) { Refresh(); } _root.GetChildren().ForEach(x => x.Dispose()); _root.Clear(); for (int i = 0; i <= ROWS; ++i) { if (pageNum * ROWS + i >= _friends.Count) { break; } FriendsAppUser friend = _friends[pageNum * ROWS + i]; MenuItemText username = new MenuItemText($"username{friend.UserId}"); username.SetText(friend.Username); _root.AddChild(0, i, 3, 1, username); if (friend.CurrentRoomId.HasValue) { MenuItemButton connectBtn = new MenuItemButton($"connect{friend.UserId}"); connectBtn.SetText("Connect"); connectBtn.Clicked += () => { _api.DefaultApps.RoomList.ChangeRoom(friend.CurrentRoomId.Value); }; _root.AddChild(3, i, 1, 1, connectBtn); } MenuItemButton removeFriend = new MenuItemButton($"remove{friend.UserId}"); removeFriend.SetText("Remove"); removeFriend.Clicked += () => { _api.DefaultApps.Friends.RemoveFriend(friend.UserId).Wait(); Refresh(); }; _root.AddChild(4, i, 1, 1, removeFriend); } if (pageNum > 0) { MenuItemButton prevPage = new MenuItemButton("prevPage"); prevPage.SetText("<"); prevPage.Clicked += () => { RenderPage(pageNum - 1); }; _root.AddChild(0, ROWS, 1, 1, prevPage); } if ((pageNum + 1) * ROWS < _friends.Count) { MenuItemButton nextPage = new MenuItemButton("nextPage"); nextPage.SetText(">"); nextPage.Clicked += () => { RenderPage(pageNum + 1); }; _root.AddChild(4, ROWS, 1, 1, nextPage); } }
private void RenderPage(int pageNum) { if (_requests == null) { Refresh(); } _root.GetChildren().ForEach(x => x.Dispose()); _root.Clear(); for (int i = 0; i <= ROWS; ++i) { if (pageNum * ROWS + i >= _requests.Count) { break; } FriendsAppUser user = _requests[pageNum * ROWS + i]; MenuItemText username = new MenuItemText($"username{user.UserId}"); username.SetText(user.Username); _root.AddChild(0, i, 3, 1, username); MenuItemButton acceptBtn = new MenuItemButton($"accept{user.UserId}"); acceptBtn.SetText("Accept"); acceptBtn.Clicked += () => { _api.DefaultApps.Friends.AcceptFriendRequest(user.UserId).Wait(); Refresh(); }; _root.AddChild(3, i, 1, 1, acceptBtn); MenuItemButton rejectBtn = new MenuItemButton($"reject{user.UserId}"); rejectBtn.SetText("Reject"); rejectBtn.Clicked += () => { _api.DefaultApps.Friends.DeleteFriendRequest(user.UserId).Wait(); Refresh(); }; _root.AddChild(4, i, 1, 1, rejectBtn); } if (pageNum > 0) { MenuItemButton prevPage = new MenuItemButton("prevPage"); prevPage.SetText("<"); prevPage.Clicked += () => { RenderPage(pageNum - 1); }; _root.AddChild(0, ROWS, 1, 1, prevPage); } if ((pageNum + 1) * ROWS < _requests.Count) { MenuItemButton nextPage = new MenuItemButton("nextPage"); nextPage.SetText(">"); nextPage.Clicked += () => { RenderPage(pageNum + 1); }; _root.AddChild(4, ROWS, 1, 1, nextPage); } }
private IMenuItem CreateBlock(FriendsAppUser friend) { MenuItemGrid item = new MenuItemGrid(friend.Username, 5, 1); MenuItemText username = new MenuItemText("username"); item.AddChild(0, 0, 4, 1, username); username.SetText(friend.Username); username.SetFontSize(8, 15); username.SetTextStyle(UnityEngine.FontStyle.Bold); MenuItemButton selectButton = new MenuItemButton("selectButton"); item.AddChild(4, 0, 1, 1, selectButton); selectButton.SetText(">"); selectButton.Clicked += () => FriendSelected?.Invoke(friend.UserId); return(item); }