Beispiel #1
0
        public void GetProfileInfo(long userId, Action <BackendResult <UserData, ResultCode> > callback)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            string index1 = "userId";
            string str1   = userId.ToString();

            parameters[index1] = str1;
            string index2 = "func_v";
            string str2   = "3";

            parameters[index2] = str2;
            VKRequestsDispatcher.DispatchRequestToVK <UserData>("execute.getProfileInfo", parameters, callback, (Func <string, UserData>)(jsonStr =>
            {
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "relatives", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "wallData", true);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Groups", false);
                jsonStr = VKRequestsDispatcher.FixArrayToObject(jsonStr, "personal");
                jsonStr = VKRequestsDispatcher.FixArrayToObject(jsonStr, "occupation");
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "photos", true);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "subscriptions", true);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "gifts", true);
                int resultCount;
                jsonStr = VKRequestsDispatcher.GetArrayCountAndRemove(jsonStr, "wall", out resultCount);
                VKRequestsDispatcher.GenericRoot <UserData> genericRoot = JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <UserData> >(jsonStr);
                if (genericRoot.response.user.counters.docs == 0)
                {
                    genericRoot.response.user.counters.docs = genericRoot.response.docsCount;
                }
                return(genericRoot.response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #2
0
        public void GetPhotoWithFullInfo(long ownerId, long pid, string accessKey, int knownCommentsCount, int offset, int commentsCountToRead, Action <BackendResult <PhotoWithFullInfo, ResultCode> > callback)
        {
            string str1 = ownerId.ToString() + "_" + pid;

            if (!string.IsNullOrWhiteSpace(accessKey))
            {
                str1 = str1 + "_" + accessKey;
            }
            string str2 = string.Format("var ownerId = {0};\r\n\r\nvar pid  = {1};\r\n\r\n\r\nvar commentsCount = {2};\r\n\r\nvar offset = {3};\r\n\r\nvar countToRead = {4};\r\n\r\nvar likesAll = API.likes.getList({{ \"type\": \"photo\", \"owner_id\":ownerId, \"item_id\":pid, \"count\":10}}).items;\r\n\r\nvar photo = API.photos.getById({{\"photos\" : \"{6}\", \"extended\":1 }});\r\n\r\nif (commentsCount == -1)\r\n{{\r\n   commentsCount = photo[0].comments.count;   \r\n}}\r\n\r\nvar calculatedOffset = commentsCount - offset - countToRead;\r\n\r\nif (calculatedOffset < 0)\r\n{{\r\n   calculatedOffset = 0;\r\n}}\r\nvar comments = API.photos.getComments({{ \"photo_id\" : pid, \"owner_id\": ownerId, \"offset\":calculatedOffset,  \"count\":countToRead, \"sort\":\"asc\", \"need_likes\":1, \"access_key\":\"{5}\", \"allow_group_comments\":1 }});\r\n\r\n\r\nvar users2 = API.users.get({{ \"user_ids\":[email protected]_to_user, \"fields\":\"first_name_dat,last_name_dat\"}});\r\n\r\n\r\n\r\nvar photoTags = API.photos.getTags({{\"owner_id\":ownerId, \"photo_id\":pid, \"access_key\":\"{5}\"}});\r\n\r\nvar userOrGroupIds = [];\r\n\r\nvar repostsCount = 0;\r\nif(likesAll+\"\"!=\"\")\r\n{{\r\n  repostsCount =  API.likes.getList({{ \"type\": \"photo\", \"owner_id\":ownerId, \"item_id\":pid, \"filter\":\"copies\"}}).count;\r\n  userOrGroupIds = likesAll;\r\n}}\r\n\r\nif (commentsCount>0)\r\n{{\r\n    userOrGroupIds = userOrGroupIds + [email protected]_id;\r\n}}\r\n\r\nvar userIds = [];\r\nvar groupIds = [];\r\n\r\nvar i = 0;\r\n\r\nif (ownerId < 0)\r\n{{\r\n     var negOwner = -ownerId;\r\n     groupIds = groupIds + negOwner;\r\n\r\n     if (photo[0].user_id != 0 && photo[0].user_id != 100)\r\n     {{\r\n         userIds = userIds + photo[0].user_id;\r\n     }}\r\n}}\r\nelse\r\n{{\r\n    userIds = userIds + ownerId;\r\n}}\r\n\r\nvar length = userOrGroupIds.length;\r\n\r\nwhile (i < length)\r\n{{\r\n    var id = parseInt(userOrGroupIds[i]);\r\n    \r\n    if (id > 0)\r\n    {{\r\n       if (userIds.length > 0)\r\n       {{\r\n          userIds = userIds + \",\";\r\n       }}\r\n       userIds = userIds + id;\r\n    }}\r\n    else if (id < 0)\r\n    {{\r\n        id = -id;\r\n        if (groupIds.length > 0)\r\n        {{\r\n            groupIds = groupIds + \",\";\r\n        }}\r\n        groupIds = groupIds + id;\r\n    }}\r\n     \r\n    i = i + 1;\r\n}}\r\n\r\nvar users  = API.users.get({{\"user_ids\":userIds, \"fields\":\"sex,photo_max,online,online_mobile\" }});\r\nvar users3 =API.users.get({{\"user_ids\":userIds, \"fields\":\"first_name_dat,last_name_dat\" }}); \r\nvar groups = API.groups.getById({{\"group_ids\":groupIds}});\r\n\r\n\r\n\r\nreturn {{\"Photo\":photo[0], \"comments\": comments, \"LikesAllIds\":likesAll, \"Users\":users, \r\n\"Groups\":groups, \"Users2\":users2, \"Users3\": users3, \"PhotoTags\": photoTags, \"RepostsCount\":repostsCount}};", ownerId, pid, knownCommentsCount, offset, commentsCountToRead, accessKey, str1);
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["code"] = str2;
            VKRequestsDispatcher.DispatchRequestToVK <PhotoWithFullInfo>("execute", parameters, callback, (Func <string, PhotoWithFullInfo>)(jsonStr =>
            {
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "comments", true);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users2", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users3", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Groups", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "PhotoTags", false);
                PhotoWithFullInfo response = JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <PhotoWithFullInfo> >(jsonStr).response;
                response.Users2.AddRange((IEnumerable <User>)response.Users3);
                GroupsService.Current.AddCachedGroups((IEnumerable <Group>)response.Groups);
                foreach (Comment comment in response.Comments)
                {
                    string message = comment.message;
                    comment.text   = message;
                }
                if (response.LikesAllIds == null)
                {
                    response.LikesAllIds = new List <long>();
                }
                return(response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #3
0
 public void GetVideoData(long ownerId, Action <BackendResult <VideosData, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideosData>(string.Format("var oid = {0};\r\nvar added = API.video.get({{\"owner_id\":oid, \"extended\":1}});\r\nvar uploaded = API.video.get({{\"owner_id\":oid, \"album_id\":-1}}).count;\r\nvar albums = API.video.getAlbums({{\"owner_id\":oid}}).count;\r\n\r\nreturn  {{\"AddedVideos\":added, \"UploadedVideosCount\":uploaded, \"VideoAlbumsCount\":albums}};", ownerId), callback, (Func <string, VideosData>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "AddedVideos", true);
         return(JsonConvert.DeserializeObject <GenericRoot <VideosData> >(jsonStr).response);
     }), false, true, new CancellationToken?());
 }
Beispiel #4
0
 public void SearchVideo(string query, int offset, int count, Action <BackendResult <VideoSearchResponse, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideoSearchResponse>(string.Format("var q = \"{0}\";\r\n                                var offset = {1};\r\n                                var count = {2};\r\n                                var videos = API.video.search({{\"q\": q, \"search_own\": 1, \"offset\": offset, \"count\": count}});\r\n                                var myVideos = [];\r\n                                var globalVideos = [];\r\n                                var i = 0;\r\n                                var items = videos.items;\r\n                                while (i < items.length) {{\r\n                                    var video = items[i];\r\n                                    if (video.owner_id == {3}) {{\r\n                                        myVideos.push(video);\r\n                                    }} else {{\r\n                                        globalVideos.push(video);\r\n                                    }}\r\n                                    i = i + 1;\r\n                                }}\r\n\r\n                                return  {{\"MyVideos\": myVideos, \"GlobalVideos\": globalVideos, \"TotalCount\": videos.count}};", query, offset, count, AppGlobalStateManager.Current.LoggedInUserId), callback, (Func <string, VideoSearchResponse>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "MyVideos", true);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "GlobalVideos", true);
         return(JsonConvert.DeserializeObject <GenericRoot <VideoSearchResponse> >(jsonStr).response);
     }), false, true, new CancellationToken?());
 }
Beispiel #5
0
        public void GetNotifications(int startTime, int endTime, int offset, string fromStr, int count, Action <BackendResult <NotificationData, ResultCode> > callback)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if (startTime > 0)
            {
                parameters["start_time"] = startTime.ToString();
            }
            if (endTime > 0)
            {
                parameters["end_time"] = endTime.ToString();
            }
            if (count > 0)
            {
                parameters["count"] = count.ToString();
            }
            if (offset > 0)
            {
                parameters["offset"] = offset.ToString();
            }
            if (!string.IsNullOrWhiteSpace(fromStr))
            {
                parameters["start_from"] = fromStr;
            }
            parameters["fields"] = "sex,photo_50,photo_100,online,screen_name,first_name_dat,last_name_dat,first_name_gen,last_name_gen";
            Dictionary <string, string> dictionary = parameters;

            dictionary["fields"] = dictionary["fields"] + ",is_closed,type,is_admin,is_member,photo_200";
            VKRequestsDispatcher.DispatchRequestToVK <NotificationData>("notifications.get", parameters, callback, (Func <string, NotificationData>)(jsonStr =>
            {
                int resultCount                      = 0;
                jsonStr                              = VKRequestsDispatcher.GetArrayCountAndRemove(jsonStr, "items", out resultCount);
                jsonStr                              = VKRequestsDispatcher.FixFalseArray(jsonStr, "profiles", false);
                jsonStr                              = VKRequestsDispatcher.FixFalseArray(jsonStr, "groups", false);
                NotificationData response            = JsonConvert.DeserializeObject <GenericRoot <NotificationData> >(jsonStr).response;
                response.TotalCount                  = resultCount;
                List <Notification> notificationList = new List <Notification>();
                foreach (Notification notification in response.items)
                {
                    notification.UpdateNotificationType();
                    object parsedFeedback = notification.ParsedFeedback;
                    object parsedParent   = notification.ParsedParent;
                    if (notification.NotType == NotificationType.unknown)
                    {
                        notificationList.Add(notification);
                    }
                }
                foreach (Notification notification in notificationList)
                {
                    response.items.Remove(notification);
                }
                return(response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #6
0
 public void GetGroupInfo(long groupId, Action <BackendResult <GroupData, ResultCode> > callback)
 {
     VKRequestsDispatcher.DispatchRequestToVK <GroupData>("execute.getGroupInfo", new Dictionary <string, string>()
     {
         {
             "groupId",
             groupId.ToString()
         },
         {
             "func_v",
             "2"
         }
     }, callback, (Func <string, GroupData>)(jsonStr =>
     {
         jsonStr            = VKRequestsDispatcher.FixArrayToObject(jsonStr, "counters");
         jsonStr            = VKRequestsDispatcher.FixFalseArray(jsonStr, "photos", true);
         jsonStr            = VKRequestsDispatcher.FixArrayToObject(jsonStr, "mediaSectionsSettings");
         GroupData response = JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <GroupData> >(jsonStr).response;
         GroupMembershipType groupMembershipType = GroupMembershipType.NotAMember;
         try
         {
             groupMembershipType = (GroupMembershipType)response.group.member_status;
             if (groupMembershipType == GroupMembershipType.InvitationRejected)
             {
                 groupMembershipType = GroupMembershipType.NotAMember;
             }
         }
         catch
         {
             if (response.membership.member == 1)
             {
                 groupMembershipType = GroupMembershipType.Member;
             }
             if (response.membership.invitation == 1)
             {
                 groupMembershipType = GroupMembershipType.InvitationReceived;
             }
             if (response.membership.request == 1)
             {
                 groupMembershipType = GroupMembershipType.RequestSent;
             }
         }
         response.group.MembershipType = groupMembershipType;
         if (Enum.IsDefined(typeof(ProfileMainSectionType), response.group.main_section))
         {
             response.group.MainSection = (ProfileMainSectionType)response.group.main_section;
         }
         this.AddCachedGroup(response.group);
         return(response);
     }), false, true, new CancellationToken?(), null);
 }
Beispiel #7
0
        public void GetLikesList(LikeObjectType type, long owner_id, long item_id, int count, int offset, bool onlyCopies, bool onlyFriends, Action <BackendResult <LikesList, ResultCode> > callback)
        {
            string str = string.Format("var count = {0};\r\nvar offset= {1};\r\nvar owner_id={2};\r\nvar item_id= {3};\r\nvar type = \"{4}\";\r\n\r\n\r\nvar likesAll = API.likes.getList({{\"type\":type,\r\n\"owner_id\": owner_id, \"item_id\":item_id, \"count\":count, \"offset\":offset, \"filter\":\"{5}\", \"friends_only\":{6} }});\r\n\r\nvar userOrGroupIds = likesAll.items;\r\n\r\nvar userIds = [];\r\nvar groupIds = [];\r\n\r\nvar i = 0;\r\n\r\nvar length = userOrGroupIds.length;\r\n\r\nwhile (i < length)\r\n{{\r\n    var id = parseInt(userOrGroupIds[i]);\r\n    \r\n    if (id > 0)\r\n    {{\r\n       if (userIds.length > 0)\r\n       {{\r\n          userIds = userIds + \",\";\r\n       }}\r\n       userIds = userIds + id;\r\n    }}\r\n    else if (id < 0)\r\n    {{\r\n        id = -id;\r\n        if (groupIds.length > 0)\r\n        {{\r\n            groupIds = groupIds + \",\";\r\n        }}\r\n        groupIds = groupIds + id;\r\n    }}\r\n     \r\n    i = i + 1;\r\n}}\r\n\r\nvar users  = API.users.get({{\"user_ids\":userIds, \"fields\":\"sex,photo_max,online,online_mobile\" }});\r\nvar groups = API.groups.getById({{\"group_ids\":groupIds}});\r\n\r\nreturn {{\"AllCount\": likesAll.count, \"All\":users, \"AllGroups\":groups, \"AllIds\" : userOrGroupIds}};", count, offset, owner_id, item_id, type.ToString(), (onlyCopies ? "copies" : "likes"), (onlyFriends ? 1 : 0));
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["code"] = str;
            VKRequestsDispatcher.DispatchRequestToVK <LikesList>("execute", parameters, callback, (Func <string, LikesList>)(jsonStr =>
            {
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "All", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "AllGroups", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "AllIds", false);
                return(JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <LikesList> >(jsonStr).response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #8
0
        public void GetWallById(long ownerId, long postId, Action <BackendResult <WallData, ResultCode> > callback)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["posts"]    = ownerId.ToString() + "_" + postId.ToString();
            parameters["extended"] = "1";
            VKRequestsDispatcher.DispatchRequestToVK <WallData>("wall.getById", parameters, callback, (Func <string, WallData>)(jsonStr =>
            {
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "items", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "profiles", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "groups", false);
                return(JsonConvert.DeserializeObject <GenericRoot <WallData> >(jsonStr).response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #9
0
 public void GetSubscriptions(long uid, Action <BackendResult <UsersAndGroups, ResultCode> > callback)
 {
     VKRequestsDispatcher.DispatchRequestToVK <UsersAndGroups>("execute.getSubscriptions", new Dictionary <string, string>()
     {
         {
             "user_id",
             uid.ToString()
         }
     }, callback, (Func <string, UsersAndGroups>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "users", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "pages", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "groups", false);
         return(JsonConvert.DeserializeObject <GenericRoot <UsersAndGroups> >(jsonStr).response);
     }), false, true, new CancellationToken?(), null);
 }
Beispiel #10
0
        public void GetWallForManyUsers(List <WallService.WallRequestData> requestData, Action <BackendResult <List <WallData>, ResultCode> > callback)
        {
            StringBuilder stringBuilder1 = new StringBuilder().AppendFormat("var users =  API.users.get({{\"user_ids\":\"{0}\", \"fields\":\"wall_default\"}});", new object[1]
            {
                requestData.Select <WallService.WallRequestData, long>((Func <WallService.WallRequestData, long>)(r => r.UserId)).ToList <long>().GetCommaSeparated()
            }).Append(Environment.NewLine);

            for (int index = 0; index < requestData.Count; ++index)
            {
                WallService.WallRequestData wallRequestData = requestData[index];
                stringBuilder1 = stringBuilder1.AppendFormat("var wall{3} = API.wall.get({{\"owner_id\":{0}, \"offset\":{1}, \"count\":{2}, \"extended\":1, \"filter\":users[{3}].wall_default}});", wallRequestData.UserId, wallRequestData.Offset, wallRequestData.Count, index).AppendFormat(Environment.NewLine);
            }
            StringBuilder stringBuilder2 = stringBuilder1.Append("return {");

            for (int index = 0; index < requestData.Count; ++index)
            {
                if (index > 0)
                {
                    stringBuilder2 = stringBuilder2.Append(", ");
                }
                stringBuilder2 = stringBuilder2.AppendFormat("\"Wall{0}\":wall{0} ", new object[1]
                {
                    index
                });
            }
            VKRequestsDispatcher.Execute <List <WallData> >(stringBuilder2.Append("};").ToString(), callback, (Func <string, List <WallData> >)(jsonStr =>
            {
                List <WallData> wallDataList1 = new List <WallData>();
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "wall", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "profiles", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "groups", false);
                for (int index = 0; index < requestData.Count; ++index)
                {
                    jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Wall" + index, true);
                }
                List <int> resultCounts;
                jsonStr = VKRequestsDispatcher.GetArrayCountsAndRemove(jsonStr, "wall", out resultCounts);
                GenericRoot <Dictionary <string, WallData> > genericRoot = JsonConvert.DeserializeObject <GenericRoot <Dictionary <string, WallData> > >(jsonStr);
                List <WallData> wallDataList2 = new List <WallData>();
                foreach (KeyValuePair <string, WallData> keyValuePair in genericRoot.response)
                {
                    wallDataList2.Add(keyValuePair.Value);
                }
                return(wallDataList2);
            }), false, true, new CancellationToken?());
        }
        public void GetNewsComments(int startTime, int endTime, int count, string fromStr, Action <BackendResult <NewsFeedData, ResultCode> > callback)
        {
            string str        = string.Format("    \r\n                    var comments = API.newsfeed.getComments({{ last_comments_count: 3, allow_group_comments: 1{0}{1}{2}{3} }});\r\n\r\n                    var response = \r\n                    {{\r\n                        items: [],\r\n                        profiles: comments.profiles,\r\n                        groups: comments.groups,\r\n                        next_from: comments.next_from\r\n                    }};\r\n\r\n                    var i = 0;\r\n                    while (i < comments.items.length)\r\n                    {{\r\n                        var item = comments.items[i];\r\n    \r\n                        if (item.type == \"video\")\r\n                            item.views = {{ count: item.views }};\r\n\r\n                        response.items.push(item);\r\n                        i = i + 1;\r\n                    }}\r\n\r\n                    return response;\r\n                ", (startTime > 0 ? string.Format(", start_time: {0}", startTime) : ""), (endTime > 0 ? string.Format(", end_time: {0}", endTime) : ""), (count > 0 ? string.Format(", count: {0}", count) : ""), (!string.IsNullOrWhiteSpace(fromStr) ? string.Format(", start_from: {0}", fromStr) : ""));
            string methodName = "execute";
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("code", str);
            Action <BackendResult <NewsFeedData, ResultCode> > callback1 = callback;

            CancellationToken?cancellationToken = new CancellationToken?();

            // ISSUE: variable of the null type

            VKRequestsDispatcher.DispatchRequestToVK <NewsFeedData>(methodName, parameters, callback1, (Func <string, NewsFeedData>)(jsonString =>
            {
                jsonString = VKRequestsDispatcher.FixFalseArray(jsonString, "profiles", false);
                jsonString = VKRequestsDispatcher.FixFalseArray(jsonString, "groups", false);
                return(JsonConvert.DeserializeObject <GenericRoot <NewsFeedData> >(jsonString).response);
            }), false, true, cancellationToken, null);
        }
Beispiel #12
0
 public void GetComments(long ownerId, long vid, int knownCommentsCount, int offset, int count, StatisticsActionSource actionSource, string context, Action <BackendResult <VideoLikesCommentsData, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideoLikesCommentsData>(string.Format("\r\nvar ownerId={0};\r\nvar vid  = {1};\r\nvar countToRead = {4};\r\nvar vidStr= ownerId + \"_\" + vid;\r\n\r\nvar knownCommentsCount = {2};\r\nvar offset = {3};\r\n\r\nvar albums = API.video.getAlbumsByVideo({{\"owner_id\":ownerId, \"video_id\":vid}});\r\n\r\nvar likesAll = API.likes.getList({{ \"type\": \"video\", \"owner_id\":ownerId, \"item_id\":vid, \"count\":10 }});\r\n\r\nvar repostsCount = API.likes.getList({{ \"type\": \"video\", \"owner_id\":ownerId, \"item_id\":vid, \"filter\": \"copies\"}}).count;\r\n\r\nvar comments;\r\n\r\nif (knownCommentsCount == -1)\r\n{{\r\n   comments = API.video.getComments({{\"video_id\":vid, \"owner_id\":ownerId, \"offset\":0, \"count\":countToRead, \"sort\":\"desc\", \"need_likes\":1, \"allow_group_comments\":1 }});\r\n}}\r\n\r\nelse\r\n{{\r\n   var calculatedOffset = knownCommentsCount - offset - countToRead;\r\n   if (calculatedOffset < 0)\r\n{{\r\n    calculatedOffset = 0;\r\n}}\r\n   comments = API.video.getComments({{\"video_id\":vid, \"owner_id\":ownerId, \"offset\":calculatedOffset, \"count\":countToRead, \"sort\":\"asc\", \"need_likes\":1, \"allow_group_comments\":1}});\r\n\r\n}}\r\n\r\nvar users2 = API.getProfiles({{ \"user_ids\":[email protected]_to_user, \"fields\":\"first_name_dat,last_name_dat\"}});\r\n\r\n\r\nvar likesAllIds = likesAll.items;\r\nvar likesAllCount = likesAll.count;\r\n\r\nvar userLiked = API.likes.isLiked({{\"owner_id\":ownerId, \"type\":\"video\", \"item_id\":vid}});\r\n\r\nvar tags = API.video.getTags({{\"owner_id\":ownerId, \"video_id\":vid}});\r\n\r\n\r\nvar userOrGroupIds = likesAllIds;\r\n\r\n\r\n\r\nuserOrGroupIds = userOrGroupIds + [email protected]_id;\r\n\r\nvar userIds = [];\r\nvar groupIds = [];\r\n\r\nvar i = 0;\r\n\r\nif (ownerId < 0)\r\n{{\r\n     var negOwner = -ownerId;\r\n     groupIds = groupIds + negOwner;\r\n}}\r\nelse\r\n{{\r\n    userIds = userIds + ownerId;\r\n}}\r\n\r\nvar length = userOrGroupIds.length;\r\n\r\nwhile (i < length)\r\n{{\r\n    var id = parseInt(userOrGroupIds[i]);\r\n    \r\n    if (id > 0)\r\n    {{\r\n       if (userIds.length > 0)\r\n       {{\r\n          userIds = userIds + \",\";\r\n       }}\r\n       userIds = userIds + id;\r\n    }}\r\n    else if (id < 0)\r\n    {{\r\n        id = -id;\r\n        if (groupIds.length > 0)\r\n        {{\r\n            groupIds = groupIds + \",\";\r\n        }}\r\n        groupIds = groupIds + id;\r\n    }}\r\n     \r\n    i = i + 1;\r\n}}\r\n\r\nvar users  = API.users.get({{\"user_ids\":userIds, \"fields\":\"sex,photo_max,online,online_mobile,friend_status\" }});\r\nvar users3 =API.users.get({{\"user_ids\":userIds, \"fields\":\"first_name_dat,last_name_dat,friend_status\" }}); \r\nvar groups = API.groups.getById({{\"group_ids\":groupIds, \"fields\":\"members_count,photo_100\"}});\r\n\r\n\r\nvar videoRecommendations = API.video.getRecommendations({{count: 8, extended: 1, owner_id: ownerId, video_id: vid, source: \"{5}\", context: \"{6}\"}});\r\n\r\n// for test\r\n//var videoRecomList = API.video.get({{count: 8, extended: 1}});\r\n//var videoRecom = {{\r\n//items: videoRecomList.items,\r\n//count: videoRecomList.count,\r\n//context: \"-1324220032\"\r\n//}};\r\n\r\nreturn {{\"comments\":comments, \"LikesAllIds\":likesAllIds,  \"LikesAllCount\":likesAllCount, \"userLiked\":userLiked, \"Users\":users,\"Users2\":users2, \"Users3\": users3, \"Groups\":groups, \"Tags\":tags, \"RepostsCount\":repostsCount, \"Albums\":albums, \"VideoRecommendations\": videoRecommendations}};\r\n", ownerId, vid, knownCommentsCount, offset, count, actionSource, context), callback, (Func <string, VideoLikesCommentsData>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users2", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users3", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Groups", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "comments", true);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Tags", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "LikesAllIds", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Albums", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "VideoRecommendations", true);
         VideoLikesCommentsData response = JsonConvert.DeserializeObject <GenericRoot <VideoLikesCommentsData> >(jsonStr).response;
         GroupsService.Current.AddCachedGroups((IEnumerable <Group>)response.Groups);
         if (knownCommentsCount < 0)
         {
             response.Comments.Reverse();
         }
         response.Users2.AddRange((IEnumerable <User>)response.Users3);
         return(response);
     }), false, true, new CancellationToken?());
 }
Beispiel #13
0
        public void Search(string searchStr, int count, int startTime, int endTime, string startFrom, Action <BackendResult <NewsFeedData, ResultCode> > callback)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["q"]     = searchStr;
            parameters["count"] = count.ToString();
            if (startTime > 0)
            {
                parameters["start_time"] = startTime.ToString();
            }
            if (endTime > 0)
            {
                parameters["end_time"] = endTime.ToString();
            }
            if (!string.IsNullOrWhiteSpace("startFrom"))
            {
                parameters["start_from"] = startFrom.ToString();
            }
            parameters["extended"] = "1";
            VKRequestsDispatcher.DispatchRequestToVK <NewsFeedData>("newsfeed.search", parameters, callback, (Func <string, NewsFeedData>)(jsonStr =>
            {
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "items", false);
                NewsFeedData response = JsonConvert.DeserializeObject <GenericRoot <NewsFeedData> >(jsonStr).response;
                foreach (NewsItem newsItem in response.items)
                {
                    if (newsItem.user != null)
                    {
                        response.profiles.Add(newsItem.user);
                    }
                    if (newsItem.group != null)
                    {
                        response.groups.Add(newsItem.group);
                    }
                }
                return(response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #14
0
        public void GetUsersAlbums(long userOrGroupid, bool isGroup, int offset, int count, Action <BackendResult <AlbumsData, ResultCode> > callback, bool needGroupSystemAlbums = true)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            string str;

            if (!isGroup)
            {
                str = string.Format("var allPhotos= API.photos.getAll({{extended:\"1\", owner_id:\"{0}\", count:\"3\", offset:\"0\"}});\r\nvar profilePhotos = API.photos.get({{owner_id:\"{0}\", album_id:\"profile\", offset:\"0\", count:\"3\", extended:\"1\", rev:\"1\"}});\r\nvar userPhotos = API.photos.getUserPhotos({{extended:\"1\", user_id:\"{0}\", count:\"3\", offset:\"0\", sort:\"0\"}});\r\nvar wallPhotos = API.photos.get({{owner_id:\"{0}\", album_id:\"wall\", offset:\"0\", count:\"3\", extended:\"1\", rev:\"1\"}});\r\nvar savedPhotos = API.photos.get({{owner_id:\"{0}\", album_id:\"saved\", offset:\"0\", count:\"3\", extended:\"1\", rev:\"1\"}});\r\nvar albumPhotos = API.photos.getAlbums({{need_covers:\"1\", offset:\"{1}\", count:\"{2}\", owner_id:\"{0}\"}}); \r\n\r\nvar full_gen = API.users.get({{\"user_ids\":\"{0}\", \"name_case\":\"gen\"}})[0];\r\n\r\nvar full_ins = API.users.get({{\"user_ids\":\"{0}\", \"name_case\":\"ins\"}})[0];\r\n\r\nvar owners = [email protected]_id;\r\nvar thumbIds = [email protected]_id;\r\n\r\nvar ownersPlusThumbs = [];\r\nvar i=albumPhotos.items.length-1;\r\n\r\nwhile(i != -1)\r\n{{\r\n  var s = owners[i] + \"_\" + thumbIds[i];\r\n  ownersPlusThumbs.push(s);\r\n  i = i -1;\r\n}};\r\n\r\nvar p = [];\r\nif (albumPhotos.items.length >0)\r\n{{\r\n  p= API.photos.getById({{photos:ownersPlusThumbs}});\r\n}};\r\n\r\nreturn {{\"AllPhotos\":allPhotos, \"ProfilePhotos\":profilePhotos, \"UserPhotos\":userPhotos, \r\n\"WallPhotos\":wallPhotos, \"SavedPhotos\":savedPhotos, \"Albums\":albumPhotos, \"covers\":p,\r\n\"userGen\":full_gen, \"userIns\":full_ins}};", userOrGroupid, offset, count);
            }
            else
            {
                str = string.Format("var allPhotos= API.photos.getAll({{extended:\"1\", owner_id:\"{0}\", count:\"3\", offset:\"0\"}});\r\nvar albumPhotos = API.photos.getAlbums({{need_covers:\"1\", offset:\"{2}\", count:\"{3}\", gid:\"{1}\", need_system:\"{4}\"}}); \r\n\r\nvar owners = [email protected]_id;\r\nvar thumbIds = [email protected]_id;\r\n\r\nvar ownersPlusThumbs = [];\r\nvar i=albumPhotos.items.length-1;\r\n\r\nwhile(i != -1)\r\n{{\r\n  var s = owners[i] + \"_\" + thumbIds[i];\r\n  ownersPlusThumbs.push(s);\r\n  i = i -1;\r\n}};\r\n\r\nvar p = [];\r\nif (albumPhotos.items.length >0)\r\n{{\r\n  p= API.photos.getById({{photos:ownersPlusThumbs}});\r\n}};\r\n\r\nreturn {{\"AllPhotos\":allPhotos,  \"Albums\":albumPhotos, \"covers\":p }};", -userOrGroupid, userOrGroupid, offset, count, (needGroupSystemAlbums ? "1" : "0"));
            }
            parameters["code"] = str;
            VKRequestsDispatcher.DispatchRequestToVK <AlbumsData>("execute", parameters, callback, (Func <string, AlbumsData>)(jsonStr =>
            {
                AlbumsData albumsData = new AlbumsData();
                jsonStr             = VKRequestsDispatcher.FixFalseArray(jsonStr, "AllPhotos", true);
                jsonStr             = VKRequestsDispatcher.FixFalseArray(jsonStr, "ProfilePhotos", true);
                jsonStr             = VKRequestsDispatcher.FixFalseArray(jsonStr, "UserPhotos", true);
                jsonStr             = VKRequestsDispatcher.FixFalseArray(jsonStr, "WallPhotos", true);
                jsonStr             = VKRequestsDispatcher.FixFalseArray(jsonStr, "SavedPhotos", true);
                jsonStr             = jsonStr.Replace("\"covers\":false", "\"covers\":[]");
                AlbumsData response = JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <AlbumsData> >(jsonStr).response;
                this.UpdateThumbSrc(response.albums, response.covers);
                if (offset != 0)
                {
                    response.AllPhotos.items.Clear();
                    response.ProfilePhotos.items.Clear();
                    response.SavedPhotos.items.Clear();
                    response.UserPhotos.items.Clear();
                    response.WallPhotos.items.Clear();
                }
                return(response);
            }), false, true, new CancellationToken?(), null);
        }
Beispiel #15
0
        public void GetWallPostByIdWithComments(long postId, long ownerId, int offset, int countToRead, int knownTotalCount, bool needWallPost, Action <BackendResult <GetWallPostResponseData, ResultCode> > callback, long pollId = 0, long pollOwnerId = 0, LikeObjectType likeObjType = LikeObjectType.post)
        {
            long userId = VKRequestsDispatcher.AuthData.user_id;

            if (knownTotalCount != -1 && offset + countToRead > knownTotalCount)
            {
                countToRead = knownTotalCount - offset;
            }
            string str1 = (!needWallPost ? "var likesAll = API.likes.getList({{\"item_id\":{0}, \"owner_id\":{1}, \"count\":20, type:\"{8}\"}});" : " var wallPost = API.wall.getById({{\"posts\":\"{1}_{0}\"}});\r\nvar likesAll = API.likes.getList({{\"item_id\":{0}, \"owner_id\":{1}, \"count\":20, type:wallPost[0].post_type}});" + Environment.NewLine) + "\r\n\r\n\r\n\r\nvar offset = {2};\r\n\r\n\r\nvar comments = API.wall.getComments({{\"post_id\":\"{0}\", \"owner_id\":\"{1}\", \"offset\":offset, \"count\":\"{3}\", \"need_likes\":\"1\", \"sort\":\"desc\", \"preview_length\":\"0\", \"allow_group_comments\":1}});\r\n\r\nvar datUsersNames = [email protected]_to_user + [email protected]_id;\r\nvar users2 = API.users.get({{\"user_ids\":datUsersNames, \"fields\":\"first_name_dat,last_name_dat\"}});\r\n\r\n\r\n\r\nvar userOrGroupIds = likesAll.items;\r\n";

            if (needWallPost)
            {
                str1 += "userOrGroupIds = userOrGroupIds + [email protected]_id + [email protected]_id + [email protected]_id + wallPost[0][email protected]_id + wallPost[0][email protected]_id;\r\n";
            }
            string str2 = str1 + "userOrGroupIds = userOrGroupIds + [email protected]_id;\r\n\r\n\r\nvar userIds = [];\r\nvar groupIds = [];\r\n\r\nvar i = 0;\r\n\r\nvar length = userOrGroupIds.length;\r\n\r\nwhile (i < length)\r\n{{\r\n    var id = parseInt(userOrGroupIds[i]);\r\n    \r\n    if (id > 0)\r\n    {{\r\n       if (userIds.length > 0)\r\n       {{\r\n          userIds = userIds + \",\";\r\n       }}\r\n       userIds = userIds + id;\r\n    }}\r\n    else if (id < 0)\r\n    {{\r\n        id = -id;\r\n        if (groupIds.length > 0)\r\n        {{\r\n            groupIds = groupIds + \",\";\r\n        }}\r\n        groupIds = groupIds + id;\r\n    }}\r\n     \r\n    i = i + 1;\r\n}}\r\n\r\nif ({1} < 0)\r\n{{\r\n    if (groupIds.length > 0) groupIds = groupIds + \",\";\r\n    groupIds = groupIds + ({1} * -1);\r\n}}\r\n\r\nvar users  = API.users.get({{\"user_ids\":userIds, \"fields\":\"sex,photo_max,online,online_mobile\" }});\r\nvar groups = API.groups.getById({{\"group_ids\":groupIds}});";
            string str3 = string.Format(pollId == 0L ? (!needWallPost ? str2 + "return {{\"Users\": users, \"Groups\":groups, \"LikesAll\":likesAll, \"comments\": comments, \"Users2\": users2 }};" : str2 + "return {{\"Users\": users, \"Groups\":groups, \"LikesAll\":likesAll, \"WallPost\":wallPost[0], \"comments\": comments, \"Users2\": users2 }};") : (!needWallPost ? str2 + "\r\nvar poll= API.polls.getById({{\"owner_id\":{7}, \"poll_id\":{6}}});   \r\nreturn {{\"Users\": users, \"Groups\":groups, \"LikesAll\":likesAll, \"comments\": comments, \"Users2\": users2, \"Poll\":poll }};" : str2 + "\r\nvar poll= API.polls.getById({{\"owner_id\":{7}, \"poll_id\":{6}}});   \r\nreturn {{\"Users\": users, \"Groups\":groups, \"LikesAll\":likesAll, \"WallPost\":wallPost[0], \"comments\": comments, \"Users2\": users2, \"Poll\":poll }};"), postId, ownerId, offset, countToRead, knownTotalCount, userId, pollId, pollOwnerId, likeObjType);
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["code"] = str3;
            VKRequestsDispatcher.DispatchRequestToVK <GetWallPostResponseData>("execute", parameters, callback, (Func <string, GetWallPostResponseData>)(jsonStr =>
            {
                VKRequestsDispatcher.GenericRoot <GetWallPostResponseData> genericRoot = JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <GetWallPostResponseData> >(VKRequestsDispatcher.FixFalseArray(VKRequestsDispatcher.FixFalseArray(VKRequestsDispatcher.FixFalseArray(VKRequestsDispatcher.FixFalseArray(VKRequestsDispatcher.FixFalseArray(VKRequestsDispatcher.FixFalseArray(jsonStr, "Users", false), "Users2", false), "Groups", false), "Poll", true), "LikesAll", true), "comments", true));
                if (genericRoot.response.LikesAll.items != null)
                {
                    genericRoot.response.LikesAll.users = new List <UserLike>(genericRoot.response.LikesAll.items.Select <long, UserLike>((Func <long, UserLike>)(it => new UserLike()
                    {
                        uid = it
                    })));
                }
                genericRoot.response.Users.Add(AppGlobalStateManager.Current.GlobalState.LoggedInUser);
                genericRoot.response.Comments.Reverse();
                GroupsService.Current.AddCachedGroups((IEnumerable <Group>)genericRoot.response.Groups);
                if (countToRead == 0)
                {
                    genericRoot.response.Comments.Clear();
                }
                if (genericRoot.response.WallPost == null)
                {
                    genericRoot.response.WallPost = new WallPost();
                }
                return(genericRoot.response);
            }), false, true, new CancellationToken?(), null);
        }