示例#1
0
 public ServiceCallback <List <FriendsAppUser> > ListFriends()
 {
     return(new ServiceCallback <List <FriendsAppUser> >(() =>
     {
         EventDataMsg msg = new EventDataMsg();
         msg.AppId = APP_ID;
         msg.EventType = (uint)FriendsAppEvents.LIST_FRIENDS;
         byte[] data;
         try
         {
             data = _api.Event.SendEvent(msg, EventRecipient.PROVIDER).Wait();
         }
         catch (EventServiceException e)
         {
             throw new FriendsAppException(e.Message);
         }
         FriendsAppMsg friendsAppMsg = FriendsAppMsg.Parser.ParseFrom(data);
         if (friendsAppMsg == null || friendsAppMsg.FriendsList == null)
         {
             throw new FriendsAppException("Unknown response.");
         }
         return friendsAppMsg.FriendsList.FriendsList
         .Where(x => x != null)
         .Select(x => new FriendsAppUser(x))
         .ToList();
     }));
 }
示例#2
0
 public ServiceCallback <FriendsAppUser> GetFriendDetails(ulong userId)
 {
     return(new ServiceCallback <FriendsAppUser>(() =>
     {
         EventDataMsg msg = new EventDataMsg();
         msg.AppId = APP_ID;
         msg.EventType = (uint)FriendsAppEvents.GET_FRIEND;
         msg.LongValue = userId;
         byte[] data;
         try
         {
             data = _api.Event.SendEvent(msg, EventRecipient.PROVIDER).Wait();
         }
         catch (EventServiceException e)
         {
             throw new FriendsAppException(e.Message);
         }
         FriendsAppMsg friendsAppMsg = FriendsAppMsg.Parser.ParseFrom(data);
         if (friendsAppMsg == null || friendsAppMsg.FriendDetail == null)
         {
             throw new FriendsAppException("Unknown response.");
         }
         return new FriendsAppUser(friendsAppMsg.FriendDetail);
     }));
 }
示例#3
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());
        }
示例#4
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());
        }
示例#5
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());
        }