public static async Task LikeComment(comment c) { await VerifyAccountV3AndRefreshIfNecessary(); var req = NewJsonRequest(); if (c.parent_object_name == "article") req.Resource = "minisite/article_reply_liking.json"; else if (c.parent_object_name == "post") req.Resource = "group/post_reply_liking.json"; req.Method = Method.POST; req.AddParameter(new Parameter() { Name = "access_token", Value = ViewModelLocator.ApplicationSettingsStatic.GuokrAccountProfile.access_token, Type = ParameterType.GetOrPost }); req.AddParameter(new Parameter() { Name = "reply_id", Value = c.reply_id, Type = ParameterType.GetOrPost }); var resp = await RestSharpAsync.RestSharpExecuteAsyncTask<GuokrResponse>(ApiClient, req); ProcessError(resp); // TODO: need to improve error handling if (resp.Data.ok == false) throw new Exception(); }
public static async Task DeleteCommentV2(comment c) { await VerifyAccountV3AndRefreshIfNecessary(); var client = ApiClient; var req = NewJsonRequest(); if (c.parent_object_name == "article") req.Resource = "minisite/article_reply.json"; else if (c.parent_object_name == "post") req.Resource = "group/post_reply.json"; req.Method = Method.DELETE; req.AddParameter(new Parameter() { Name = "reply_id", Value = c.reply_id, Type = ParameterType.GetOrPost }); req.AddParameter(new Parameter() { Name = "access_token", Value = ViewModelLocator.ApplicationSettingsStatic.GuokrAccountProfile.access_token, Type = ParameterType.GetOrPost }); var response = await RestSharpAsync.RestSharpExecuteAsyncTask(client, req); try { ProcessError(response); Messenger.Default.Send<DeleteCommentComplete>(new DeleteCommentComplete() { comment = c }); } catch (GuokrException e) { Messenger.Default.Send<DeleteCommentComplete>(new DeleteCommentComplete() { comment = c, Exception = e }); } }
private static List<comment> InternalParsePostComments(HtmlDocument htmlDocument) { var xpath = new Dictionary<string, string>() { { "ul", @"//ul[@class=""cmts-list""]"}, { "content" , @"//div[contains(@class,""cmt-content"")]"}, { "date_create" , @"//span[@class=""cmt-info""]"}, { "floor" , @"//span[@class=""cmt-floor""]"}, { "head_48" , @"//div[contains(@class,""cmt-img"")]//img"}, { "home_url" , @"//div[contains(@class,""cmt-img"")]/a"}, { "nickname" , @"//a[@class=""cmt-author cmtAuthor""]"}, { "reply_id" , @"//li"} }; var ul = htmlDocument.DocumentNode.SelectSingleNode(xpath["ul"]); if (ul == null) return new List<comment>(); var contents = ul.SelectNodes(ul.XPath + xpath["content"]); if (contents == null || contents.Count == 0) return new List<comment>(); var date_creates = ul.SelectNodes(ul.XPath + xpath["date_create"]); var floors = ul.SelectNodes(ul.XPath + xpath["floor"]); var head_48s = ul.SelectNodes(ul.XPath + xpath["head_48"]); var home_urls = ul.SelectNodes(ul.XPath + xpath["home_url"]); var nicknames = ul.SelectNodes(ul.XPath + xpath["nickname"]); var reply_ids = ul.SelectNodes(ul.XPath + xpath["reply_id"]); if (contents.Count != date_creates.Count || contents.Count != floors.Count || contents.Count != head_48s.Count || contents.Count != home_urls.Count || contents.Count != nicknames.Count || contents.Count != reply_ids.Count) throw new ArgumentOutOfRangeException(); List<comment> ress = new List<comment>(); for (int i = 0; i < contents.Count; i++) { var p = new comment(); ress.Add(p); try { p.contentHtml = contents[i].InnerHtml; // don't do DeEntitize because this will be loaded as HTMLDocument p.date_create = date_creates[i].InnerText; if (p.date_create.Contains("刚刚")) p.date_create = ServerNow.ToString(); else if (p.date_create.Contains("今天")) p.date_create = p.date_create.Replace("今天", ServerNow.Date.ToShortDateString()); else if (p.date_create.Contains("前")) { string[] a = new string[] { "秒前", "分钟前", "小时前" }; int m = 1; foreach (var item in a) { if (p.date_create.Contains(item)) { p.date_create = p.date_create.Replace(item, ""); break; } else m = m * 60; } if (m > 3600) throw new NotImplementedException(); TimeSpan ts = TimeSpan.FromSeconds(m * Convert.ToInt32(p.date_create)); p.date_create = (ServerNow - ts).ToString(); } p.floor = Convert.ToInt32(floors[i].InnerText.Substring(0, floors[i].InnerText.Length - 1)); p.head_48 = head_48s[i].GetAttributeValue("src", ""); p.userUrl = home_urls[i].GetAttributeValue("href", ""); p.nickname = nicknames[i].InnerText; p.reply_id = Convert.ToInt64(reply_ids[i].GetAttributeValue("id", "0")); } catch (Exception e) { DebugLogging.Append("exception", e.Message, ""); } } return ress; }