// process group comments private void OnWallGetComments(JObject data, String cookie) { if (data[VkRestApi.ResponseBody] == null) { isRunning = false; return; } if (totalCount == 0) { totalCount = data[VkRestApi.ResponseBody]["count"].ToObject<long>(); } // now calculate items in response var count = data[VkRestApi.ResponseBody]["items"].Count(); var gId = (long)(isGroup ? decimal.Negate(groupId) : groupId); var comments = new List<Comment>(); // process response body for (var i = 0; i < count; ++i) { var postObj = data[VkRestApi.ResponseBody]["items"][i].ToObject<JObject>(); var comment = new Comment(); comment.id = Utils.getLongField("id", postObj); comment.post_id = Convert.ToInt64(cookie); // passed as a cookie comment.from_id = Utils.getLongField("from_id", postObj); // post date comment.date = Utils.getStringDateField("date", postObj); comment.reply_to_uid = Utils.getLongField("reply_to_uid", postObj); comment.reply_to_cid = Utils.getLongField("reply_to_cid", postObj); // likes/dislikes comment.likes = Utils.getLongField("likes", "count", postObj); if (comment.likes > 0) { var like = new Like(); like.type = "comment"; like.owner_id = gId; like.item_id = comment.id; likes.Add(like); } // attachments count if (postObj["attachments"] != null) { comment.attachments = postObj["attachments"].ToArray().Length; } // post text comment.text = Utils.getTextField("text", postObj); // update posters if (comment.from_id != gId) { if (!posters.ContainsKey(comment.from_id)) { posters[comment.from_id] = new Poster(); } posters[comment.from_id].comments += 1; // increment number of comments posters[comment.from_id].rec_likes += comment.likes; // add to the poster ids posterIds.Add(comment.from_id); } comments.Add(comment); } if (comments.Count > 0) { // save the posts list Utils.PrintFileContent(groupCommentsWriter, comments); } }
// process group board topic comments private void OnBoardGetComments(JObject data, string cookie) { if (data[VkRestApi.ResponseBody] == null) { isRunning = false; return; } if (totalCount == 0) { totalCount = data[VkRestApi.ResponseBody]["count"].ToObject<int>(); if (totalCount == 0) { isRunning = false; return; } step = CalcStep(totalCount, POSTS_PER_REQUEST); } // calculate items in response var count = data[VkRestApi.ResponseBody]["items"].Count(); if (!CheckAndIncrement(count)) return; var comments = new List<Comment>(); var board_id = Convert.ToInt64(cookie); // passed as a cookie // process response body for (int i = 0; i < count; ++i) { var postObj = data[VkRestApi.ResponseBody]["items"][i].ToObject<JObject>(); var comment = new Comment(); comment.id = Utils.getLongField("id", postObj); comment.post_id = board_id; comment.from_id = Utils.getLongField("from_id", postObj); // post date comment.date = Utils.getStringDateField("date", postObj); comment.reply_to_uid = Utils.getLongField("reply_to_uid", postObj); comment.reply_to_cid = Utils.getLongField("reply_to_cid", postObj); comment.likes = Utils.getLongField("likes", "count", postObj); // likes if (comment.likes > 0) { var like = new Like(); like.type = "topic_comment"; like.owner_id = (long)this.groupId; like.item_id = comment.id; likes.Add(like); } // attachments count if (postObj["attachments"] != null) { comment.attachments = postObj["attachments"].ToArray().Length; } // post text comment.text = Utils.getTextField("text", postObj); // update posters if (!posters.ContainsKey(comment.from_id)) { posters[comment.from_id] = new Poster(); } posters[comment.from_id].BoardComments += 1; // increment number of board comments posters[comment.from_id].RecLikes += comment.likes; // add to the poster ids if (comment.from_id != this.groupId) posterIds.Add(comment.from_id); comments.Add(comment); // add to board post info if (!boardPostInfo.ContainsKey(comment.id)) { boardPostInfo[comment.id] = new PostInfo(comment.id, comment.from_id); } // update u2u matrix for replies var to = ParseCommentForReplyTo(comment.text); if (to > 0) { UpdateU2UMatrix(comment.from_id, to, true); // reply is comment posters[comment.from_id].Comments += 1; // there must by a poster down there - update posters if (!posters.ContainsKey(to)) { posters[to] = new Poster(); } posters[to].RecComments += 1; // increment number of received comments } } // save the board comments Utils.PrintFileContent(groupBoardCommentsWriter, comments); }
// process group posts private void OnWallGet(JObject data) { if (data[VkRestApi.ResponseBody] == null) { isRunning = false; return; } if(totalCount == 0) { totalCount = data[VkRestApi.ResponseBody]["count"].ToObject<long>(); if (totalCount == 0) { isRunning = false; return; } step = (int)(10000 * POSTS_PER_REQUEST / totalCount); } // now calculate items in response var count = data[VkRestApi.ResponseBody]["items"].Count(); //this.backgroundGroupsWorker.ReportProgress(0, "Processing next " + count + " posts out of " + totalCount); var gId = (long)(isGroup ? decimal.Negate(groupId) : groupId); var posts = new List<Post>(); // process response body for (var i = 0; i < count; ++i) { var postObj = data[VkRestApi.ResponseBody]["items"][i].ToObject<JObject>(); // see if post is in the range var dt = Utils.getDateField("date", postObj); if(dt < postsFromDate || dt > postsToDate) { continue; } var post = new Post(); post.id = Utils.getLongField("id", postObj); post.owner_id = Utils.getLongField("owner_id", postObj); post.from_id = Utils.getLongField("from_id", postObj); post.signer_id = Utils.getLongField("signer_id", postObj); // post date post.date = Utils.getStringDateField("date", postObj); // post_type post.post_type = Utils.getStringField("post_type", postObj); // comments post.comments = Utils.getLongField("comments", "count", postObj); if (post.comments > 0) { postsWithComments.Add(post.id); // add post's id to the ref list for comments processing } // likes post.likes = Utils.getLongField("likes", "count", postObj); if (post.likes > 0) { var like = new Like(); like.type = "post"; like.owner_id = gId; like.item_id = post.id; likes.Add(like); } // reposts post.reposts = Utils.getLongField("reposts", "count", postObj); // attachments count if(postObj["attachments"] != null) { post.attachments = postObj["attachments"].ToArray().Length; } // post text post.text = Utils.getTextField("text", postObj); // update posters if different from the group if (post.from_id != gId) { if (!posters.ContainsKey(post.from_id)) { posters[post.from_id] = new Poster(); } posters[post.from_id].posts += 1; // increment number of posts posters[post.from_id].rec_likes += post.likes; // add to the poster ids posterIds.Add(post.from_id); } // if post has a signer - update posters if (post.signer_id > 0 && post.signer_id != post.from_id) { if (!posters.ContainsKey(post.signer_id)) { posters[post.signer_id] = new Poster(); } posters[post.signer_id].posts += 1; // increment number of posts posters[post.signer_id].rec_likes += post.likes; // add to the poster ids posterIds.Add(post.signer_id); } posts.Add(post); } if (posts.Count > 0) { // save the posts list Utils.PrintFileContent(groupPostsWriter, posts); } }
// process group posts private void OnWallGet(JObject data) { if (data[VkRestApi.ResponseBody] == null) { isRunning = false; return; } if (totalCount == 0) { totalCount = data[VkRestApi.ResponseBody]["count"].ToObject<int>(); if (totalCount == 0) { isRunning = false; return; } step = CalcStep(totalCount, POSTS_PER_REQUEST ); } // calculate items in response int count = data[VkRestApi.ResponseBody]["items"].Count(); if (!CheckAndIncrement(count)) return; var posts = new List<Post>(); // process response body for (int i = 0; i < count; ++i) { var postObj = data[VkRestApi.ResponseBody]["items"][i].ToObject<JObject>(); // see if post is in the range var dt = Utils.getDateField("date", postObj); if (dt < this.postsFromDate || dt > this.postsToDate) { continue; } var post = new Post(); post.id = Utils.getLongField("id", postObj); post.owner_id = Utils.getLongField("owner_id", postObj); post.from_id = Utils.getLongField("from_id", postObj); post.signer_id = Utils.getLongField("signer_id", postObj); // post date post.date = Utils.getStringDateField("date", postObj); // post_type post.post_type = Utils.getStringField("post_type", postObj); // comments post.comments = Utils.getLongField("comments", "count", postObj); if (post.comments > 0) { this.postsWithComments.Add(post.id); // add post's id to the ref list for comments processing } // likes post.likes = Utils.getLongField("likes", "count", postObj); if (post.likes > 0) { var like = new Like(); like.type = "post"; like.owner_id = (long)this.groupId; like.item_id = post.id; this.likes.Add(like); } // reposts post.reposts = Utils.getLongField("reposts", "count", postObj); // attachments count if (postObj["attachments"] != null) { post.attachments = postObj["attachments"].ToArray().Length; } // post text post.text = Utils.getTextField("text", postObj); // post may have a copy_history field, which is repost from other community - save it in a file var copyHistory = Utils.GetArray("copy_history", postObj); if (copyHistory != null) { ProcessCopyHistory(post.id, copyHistory); } // if post has a signer - update posters with a signer if (post.signer_id > 0) { if (!posters.ContainsKey(post.signer_id)) { posters[post.signer_id] = new Poster(); } posters[post.signer_id].Posts += 1; // increment number of posts posters[post.signer_id].RecLikes += post.likes; // add to the poster ids posterIds.Add(post.signer_id); } else { if (!posters.ContainsKey(post.from_id)) { posters[post.from_id] = new Poster(); } posters[post.from_id].Posts += 1; // increment number of posts posters[post.from_id].RecLikes += post.likes; // add to the poster ids if different from the group if(post.from_id != this.groupId) posterIds.Add(post.from_id); } posts.Add(post); // add to the post infos if (!postInfo.ContainsKey(post.id)) { var uid = post.signer_id > 0 ? post.signer_id : post.from_id; postInfo[post.id] = new PostInfo(post.id, uid); } } // save the posts list Utils.PrintFileContent(groupPostsWriter, posts); }