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); }
public PhotoViewModel(Photo photo, PhotoWithFullInfo photoWithFullInfo = null) : this() { this._photo = photo; this._ownerId = photo.owner_id; this._pid = photo.pid; this._accessKey = photo.access_key; this._photoWithFullInfo = photoWithFullInfo; PhotoWithFullInfo photoWithFullInfo1 = this._photoWithFullInfo; VKClient.Common.Backend.DataObjects.Comments comments; if (photoWithFullInfo1 == null) { comments = (VKClient.Common.Backend.DataObjects.Comments)null; } else { Photo photo1 = photoWithFullInfo1.Photo; comments = photo1 != null ? photo1.comments : (VKClient.Common.Backend.DataObjects.Comments)null; } if (comments == null) { return; } this._knownCommentsCount = this._photoWithFullInfo.Photo.comments.count; }
protected override void HandleOnNavigatedTo(NavigationEventArgs e) { base.HandleOnNavigatedTo(e); bool flag = true; if (!this._isInitialized) { this._ownerId = long.Parse(((Page)this).NavigationContext.QueryString["ownerId"]); this._pid = long.Parse(((Page)this).NavigationContext.QueryString["pid"]); string accessKey = ((Page)this).NavigationContext.QueryString["accessKey"]; Photo parameterForIdAndReset1 = ParametersRepository.GetParameterForIdAndReset("Photo") as Photo; PhotoWithFullInfo parameterForIdAndReset2 = ParametersRepository.GetParameterForIdAndReset("PhotoWithFullInfo") as PhotoWithFullInfo; this._friendsOnly = ((Page)this).NavigationContext.QueryString["FriendsOnly"] == bool.TrueString; this._fromDialog = ((Page)this).NavigationContext.QueryString["FromDialog"] == bool.TrueString; PhotoViewModel photoViewModel; if (parameterForIdAndReset1 == null) { photoViewModel = new PhotoViewModel(this._ownerId, this._pid, accessKey); } else { if (string.IsNullOrEmpty(parameterForIdAndReset1.access_key)) { parameterForIdAndReset1.access_key = accessKey; } photoViewModel = new PhotoViewModel(parameterForIdAndReset1, parameterForIdAndReset2); } this.InitializeCommentVM(); base.DataContext = photoViewModel; // ISSUE: method pointer photoViewModel.LoadInfoWithComments(new Action <bool, int>(this.OnPhotoInfoLoaded)); this.RestoreUnboundState(); this._isInitialized = true; flag = false; } if (!flag && (!e.IsNavigationInitiator || e.NavigationMode != NavigationMode.New)) { WallPostVMCacheManager.TryDeserializeInstance(this._commentVM); } this.ProcessInputData(); this.UpdateAppBar(); }
private void ReadPhotos(List <Photo> photos) { ((Collection <PhotoViewModel>) this._photosCollection).Clear(); List <Photo> .Enumerator enumerator = photos.GetEnumerator(); try { while (enumerator.MoveNext()) { Photo current = enumerator.Current; PhotoWithFullInfo photoWithFullInfo1 = null; if (current.owner_id == AppGlobalStateManager.Current.LoggedInUserId && current.album_id == -3L) { PhotoWithFullInfo photoWithFullInfo2 = new PhotoWithFullInfo(); photoWithFullInfo2.Photo = current; photoWithFullInfo2.Users = new List <User>() { AppGlobalStateManager.Current.GlobalState.LoggedInUser }; List <Group> groupList = new List <Group>(); photoWithFullInfo2.Groups = groupList; List <PhotoVideoTag> photoVideoTagList = new List <PhotoVideoTag>(); photoWithFullInfo2.PhotoTags = photoVideoTagList; List <Comment> commentList = new List <Comment>(); photoWithFullInfo2.Comments = commentList; List <long> longList = new List <long>(); photoWithFullInfo2.LikesAllIds = longList; List <User> userList1 = new List <User>(); photoWithFullInfo2.Users2 = userList1; List <User> userList2 = new List <User>(); photoWithFullInfo2.Users3 = userList2; photoWithFullInfo1 = photoWithFullInfo2; } ((Collection <PhotoViewModel>) this._photosCollection).Add(new PhotoViewModel(current, photoWithFullInfo1)); } } finally { enumerator.Dispose(); } }
public void LoadInfoWithComments(Action <bool, int> callback) { if (this.IsGif) { callback.Invoke(true, 0); } else if (this._photoWithFullInfo != null) { Group group = (Group)Enumerable.FirstOrDefault <Group>(this._photoWithFullInfo.Groups, (Func <Group, bool>)(g => g.id == -this._ownerId)); callback.Invoke(true, group != null ? group.admin_level : 0); } else { if (this._isLoading) { return; } this._isLoading = true; this.SetInProgress(true, ""); PhotosService.Current.GetPhotoWithFullInfo(this._ownerId, this._pid, this._accessKey, -1, 0, this.CountToLoad, (Action <BackendResult <PhotoWithFullInfo, ResultCode> >)(res => { int num1 = 0; if (res.ResultCode == ResultCode.Succeeded) { int num2 = string.IsNullOrEmpty(this.ImageSrc) ? 1 : 0; this._photoWithFullInfo = res.ResultData; this._photo = res.ResultData.Photo; if (this._photo != null && string.IsNullOrEmpty(this._photo.access_key) && !string.IsNullOrEmpty(this._accessKey)) { this._photo.access_key = this._accessKey; } this._knownCommentsCount = this._photoWithFullInfo.Photo.comments.count; PhotoWithFullInfo resultData = res.ResultData; Group group = resultData != null ? Enumerable.FirstOrDefault <Group>(resultData.Groups, (Func <Group, bool>)(g => g.id == -this._ownerId)) : null; if (group != null) { num1 = group.admin_level; } if (num2 != 0) { this.NotifyPropertyChanged <string>((System.Linq.Expressions.Expression <Func <string> >)(() => this.ImageSrc)); } this.NotifyPropertyChanged <string>((System.Linq.Expressions.Expression <Func <string> >)(() => this.CommentsCountStr)); this.NotifyPropertyChanged <string>((System.Linq.Expressions.Expression <Func <string> >)(() => this.Text)); this.NotifyPropertyChanged <bool>((System.Linq.Expressions.Expression <Func <bool> >)(() => this.IsLoadedFullInfo)); this.NotifyPropertyChanged <string>((System.Linq.Expressions.Expression <Func <string> >)(() => this.UserCountStr)); this.NotifyPropertyChanged <Visibility>((System.Linq.Expressions.Expression <Func <Visibility> >)(() => this.UserVisibility)); this.NotifyPropertyChanged <string>((System.Linq.Expressions.Expression <Func <string> >)(() => this.LikesCountStr)); this.NotifyPropertyChanged <bool>((System.Linq.Expressions.Expression <Func <bool> >)(() => this.UserLiked)); this.NotifyPropertyChanged <double>((System.Linq.Expressions.Expression <Func <double> >)(() => this.LikeOpacity)); this.NotifyPropertyChanged <SolidColorBrush>((System.Linq.Expressions.Expression <Func <SolidColorBrush> >)(() => this.LikeBackgroundBrush)); this.NotifyPropertyChanged <SolidColorBrush>((System.Linq.Expressions.Expression <Func <SolidColorBrush> >)(() => this.LikeTextForegroundBrush)); this.NotifyPropertyChanged <Visibility>((System.Linq.Expressions.Expression <Func <Visibility> >)(() => this.IsFullInfoLoadedVisibility)); this.NotifyPropertyChanged <double>((System.Linq.Expressions.Expression <Func <double> >)(() => this.IsFullInfoLoadedOpacity)); } this.SetInProgress(false, ""); this._isLoading = false; callback.Invoke(res.ResultCode == ResultCode.Succeeded, num1); })); } }