internal void LikeUnlike() { if (this._likesCommentsData == null) { return; } if (this._likesCommentsData.UserLiked == 0) { LikesService.Current.AddRemoveLike(true, this.OwnerId, this.VideoId, LikeObjectType.video, (Action <BackendResult <ResponseWithId, ResultCode> >)(res => { }), this._accessKey); VideoLikesCommentsData likesCommentsData = this._likesCommentsData; int?likesAllCount = likesCommentsData.LikesAllCount; int?nullable = likesAllCount.HasValue ? new int?(likesAllCount.GetValueOrDefault() + 1) : new int?(); likesCommentsData.LikesAllCount = nullable; this._likesCommentsData.UserLiked = 1; } else { LikesService.Current.AddRemoveLike(false, this.OwnerId, this.VideoId, LikeObjectType.video, (Action <BackendResult <ResponseWithId, ResultCode> >)(res => { }), this._accessKey); VideoLikesCommentsData likesCommentsData = this._likesCommentsData; int?likesAllCount = likesCommentsData.LikesAllCount; int?nullable = likesAllCount.HasValue ? new int?(likesAllCount.GetValueOrDefault() - 1) : new int?(); likesCommentsData.LikesAllCount = nullable; this._likesCommentsData.UserLiked = 0; } }
public void LoadMoreComments(int countToLoad, Action <bool> callback) { if (this._isLoadingComments) { return; } this._isLoadingComments = true; VideoService.Instance.GetComments(this.OwnerId, this.VideoId, this._knownCommentsCount, this._likesCommentsData == null || this._likesCommentsData.Comments == null ? 0 : this._likesCommentsData.Comments.Count, countToLoad, this._actionSource, this._videoContext, (Action <BackendResult <VideoLikesCommentsData, ResultCode> >)(res => { if (res.ResultCode == ResultCode.Succeeded) { if (this._likesCommentsData == null) { this._likesCommentsData = res.ResultData; this._knownCommentsCount = this._likesCommentsData.TotalCommentsCount; this.UpdateOwnerInfo(); this.NotifyPropertiesChanged(); } else { List <Comment> comments = this._likesCommentsData.Comments; this._likesCommentsData.Comments = res.ResultData.Comments; this._likesCommentsData.Comments.AddRange((IEnumerable <Comment>)comments); this._likesCommentsData.Users.AddRange((IEnumerable <User>)res.ResultData.Users); this._likesCommentsData.Groups.AddRange((IEnumerable <Group>)res.ResultData.Groups); } if (this._likesCommentsData != null) { EventAggregator.Current.Publish(new VideoCommentsLikesUpdated() { CommentsCount = this._likesCommentsData.TotalCommentsCount, LikesCount = (this._likesCommentsData.LikesAllCount ?? 0), OwnerId = this.OwnerId, VideoId = this.VideoId }); } callback(true); } else { callback(false); } this._isLoadingComments = false; })); }
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?()); }