Example #1
0
        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());
        }
Example #2
0
        private byte[] HandleListFriends(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.");
            }
            List <ulong> friendIds = _friendsData.GetFriendsList(userReq.Id);

            if (friendIds == null)
            {
                friendIds = new List <ulong>();
            }
            List <FriendsAppUser> friends = friendIds.Select(x => ToFriendsAppUser(x)).ToList();
            FriendsAppMsg         msg     = new FriendsAppMsg();

            msg.FriendsList = new FriendsAppListMsg();
            msg.FriendsList.FriendsList.AddRange(friends.Select(x => x.ToNetworkModel()));
            return(msg.ToByteArray());
        }
Example #3
0
        private byte[] HandleListFriendRequests(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.");
            }
            List <ulong>          requests     = _friendsData.GetFriendRequests(userReq.Id);
            List <FriendsAppUser> requestUsers = requests
                                                 .Select(x => User.Get(x))
                                                 .Where(x => x != null)
                                                 .Select(x => new FriendsAppUser(x.ToMessage(), null, null))
                                                 .ToList();
            FriendsAppMsg msg = new FriendsAppMsg();

            msg.FriendRequests        = new FriendsAppRequestsMsg();
            msg.FriendRequests.ToUser = userReq.Id;
            msg.FriendRequests.FriendRequestsList.AddRange(requestUsers.Select(x => x.ToNetworkModel()));
            return(msg.ToByteArray());
        }