/// <summary> /// Send reply message. /// </summary> /// <returns></returns> public async Task <bool> SendMessage(string subject, string message, string targetUser, string threadId, string replyId) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var contentPairs = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("subject", subject), new KeyValuePair <string, string>("message", message), new KeyValuePair <string, string>("csrf_token", client.Token), new KeyValuePair <string, string>("sendmessage", "Send Message") }; var content = new FormUrlEncodedContent(contentPairs); var response = await client.PostAsync( $"/mymessages.php?go=send&replyid={replyId}&threadid={threadId}&toname={targetUser}", content); return(response.IsSuccessStatusCode); } catch (Exception) { MalHttpContextProvider.ErrorMessage("Messages"); return(false); } }
/// <summary> /// When we send new message we don't really know its id so we have to pull it. /// Once we have that we will be able to pull thread id. /// </summary> public async Task <string> GetFirstSentMessageId() { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var res = await client.GetAsync("/mymessages.php?go=sent"); var body = await res.Content.ReadAsStringAsync(); try { var doc = new HtmlDocument(); doc.LoadHtml(body); //?go=read&id=8473147&f=1 var id = doc.FirstOfDescendantsWithClass("div", "message read spot2 clearfix") .Descendants("a") .Skip(1) .First() .Attributes["href"].Value.Split('=')[2]; return(id.Substring(0, id.Length - 2)); } catch (Exception) { return("0"); } } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); } return("0"); }
public async Task <List <MalMessageModel> > GetSentMessages(int page = 1) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); string path = $"/mymessages.php?go=sent"; var res = await client.GetAsync(path); var body = await res.Content.ReadAsStringAsync(); var output = new List <MalMessageModel>(); var doc = new HtmlDocument(); doc.LoadHtml(body); output.AddRange( doc.WhereOfDescendantsWithClass("div", "message read spot2 clearfix") .Select(ParseOutboxHtmlToMalMessage)); return(output); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); } return(new List <MalMessageModel>()); }
public static async Task <bool> SendCommentReply(string userId, string comment) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var contentPairs = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("profileMemId", userId), new KeyValuePair <string, string>("commentText", comment), new KeyValuePair <string, string>("area", "2"), new KeyValuePair <string, string>("csrf_token", client.Token), new KeyValuePair <string, string>("commentSubmit", "1") }; var content = new FormUrlEncodedContent(contentPairs); var response = await client.PostAsync("/addcomment.php", content); //edit comment function - not sure what it does // /includes/ajax.inc.php?t=73 //com id - token //id = 31985758 & csrf_token = dfsdfsd //client.PostAsync("/includes/ajax.inc.php?t=73") return(response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.SeeOther); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); return(false); } }
public static async Task <bool> SendComment(string username, string userId, string comment) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var contentPairs = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("profileMemId", userId), new KeyValuePair <string, string>("commentText", comment), new KeyValuePair <string, string>("profileUsername", username), new KeyValuePair <string, string>("csrf_token", client.Token), new KeyValuePair <string, string>("commentSubmit", "Submit Comment") }; var content = new FormUrlEncodedContent(contentPairs); var response = await client.PostAsync("/addcomment.php", content); return(response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.SeeOther); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); return(false); } }
public async Task <List <MalMessageModel> > GetMessagesInThread(MalMessageModel msg) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var response = await client.GetAsync($"/mymessages.php?go=read&id={msg.Id}&threadid={msg.ThreadId}"); var raw = await response.Content.ReadAsStringAsync(); var doc = new HtmlDocument(); doc.LoadHtml(raw); var output = new List <MalMessageModel>(); foreach ( var msgHistoryNode in doc.FirstOfDescendantsWithClass("table", "pmessage-message-history").Descendants("tr")) { var current = new MalMessageModel(); var tds = msgHistoryNode.Descendants("td").ToList(); current.Content = WebUtility.HtmlDecode(tds[2].InnerText.Trim()); if (string.IsNullOrEmpty(current.Content)) { continue; } try { foreach (var img in msgHistoryNode.Descendants("img")) { current.Images.Add(img.Attributes["src"].Value); } } catch (Exception e) { //no images } current.Subject = msg.Subject; current.Date = tds[0].InnerText.Trim(); current.Sender = tds[1].InnerText.Trim(); output.Add(current); } return(output); } catch (Exception) { MalHttpContextProvider.ErrorMessage("Messages"); } return(new List <MalMessageModel>()); }
public async Task <MalMessageModel> GetMessageDetails(MalMessageModel msg, bool sentMessage) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var response = await client.GetAsync($"/mymessages.php?go=read&id={msg.Id}{(sentMessage ? "&f=1" : "")}"); var raw = await response.Content.ReadAsStringAsync(); var doc = new HtmlDocument(); doc.LoadHtml(raw); var msgNode = doc.FirstOfDescendantsWithClass("td", "dialog-text"); var msgContent = msgNode.ChildNodes.Skip(3) .Where(node => node.NodeType == HtmlNodeType.Text) .Aggregate("", (current, textNode) => current + textNode.InnerText); msg.Content = WebUtility.HtmlDecode(msgContent.Trim()); var ids = doc.FirstOfDescendantsWithClass("input", "inputButton btn-middle flat").Attributes["onclick"].Value .Split('='); try { foreach (var img in msgNode.Descendants("img")) { msg.Images.Add(img.Attributes["src"].Value); } } catch (Exception e) { //no images } msg.ThreadId = ids[4].Substring(0, ids[3].IndexOf('&')); msg.ReplyId = ids[3].Substring(0, ids[3].IndexOf('&')); return(msg); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); } return(new MalMessageModel()); }
public static async Task <List <MalMessageModel> > GetComToComMessages(string path) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var response = await client.GetAsync($"/comtocom.php?{path}"); var doc = new HtmlDocument(); doc.LoadHtml(await response.Content.ReadAsStringAsync()); var output = new List <MalMessageModel>(); foreach (var commentBox in doc.FirstOfDescendantsWithId("div", "content").ChildNodes.Where(node => node.Name == "div").Skip(1)) { try { var current = new MalMessageModel(); current.Content = WebUtility.HtmlDecode(commentBox.FirstOfDescendantsWithClass("div", "spaceit").InnerText).Trim(); current.Date = commentBox.Descendants("small").First().InnerText.Trim(new[] { '|', ' ' }); current.Sender = WebUtility.HtmlDecode(commentBox.Descendants("a").Skip(1).First().InnerText.Trim()); foreach (var img in commentBox.Descendants("img").Skip(1)) { if (img.Attributes.Contains("src")) { current.Images.Add(img.Attributes["src"].Value); } } output.Add(current); } catch (Exception) { //html } } output.Reverse(); return(output); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); return(new List <MalMessageModel>()); } }
public static async Task <bool> DeleteComment(string id) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var contentPairs = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("id", id), new KeyValuePair <string, string>("csrf_token", client.Token), }; var content = new FormUrlEncodedContent(contentPairs); var response = await client.PostAsync("/includes/ajax.inc.php?t=78 ", content); return(response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.SeeOther); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); return(false); } }
private async void LoadMore(bool force = false) { LoadingVisibility = true; if (force) { if (DisplaySentMessages) { Outbox = new List <MalMessageModel>(); } else { _loadedPages = 1; Inbox = new List <MalMessageModel>(); } } if (!DisplaySentMessages) { try { if (!_skipLoading) { _loadedSomething = true; try { Inbox.AddRange(await AccountMessagesManager.GetMessagesAsync(_loadedPages++)); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); } } _skipLoading = false; MessageIndex.Clear(); MessageIndex.AddRange(Inbox); LoadMorePagesVisibility = true; } catch (ArgumentOutOfRangeException) { LoadMorePagesVisibility = false; } } else { try { if (Outbox.Count == 0) { Outbox = await AccountMessagesManager.GetSentMessagesAsync(); } MessageIndex.Clear(); MessageIndex.AddRange(Outbox); LoadMorePagesVisibility = false; } catch (Exception) { MalHttpContextProvider.ErrorMessage("Messages"); } } LoadingVisibility = false; }