private View GetMessageTemplateDelegate(int i, MalMessageModel malMessageModel, View arg3)
        {
            var view = arg3;

            if (view == null || !view.Tag.Unwrap <MalMessageModel>().Sender.Equals(malMessageModel.Sender, StringComparison.InvariantCultureIgnoreCase))
            {
                view =
                    Activity.LayoutInflater.Inflate(
                        malMessageModel.Sender.Equals(Credentials.UserName, StringComparison.InvariantCultureIgnoreCase)
                            ? Resource.Layout.MessagingDetailsPageItemMine
                            : Resource.Layout.MessagingDetailsPageItemOther, null);
            }
            view.Tag = malMessageModel.Wrap();

            view.FindViewById <TextView>(Resource.Id.MessagingDetailsPageItemContent).Text = malMessageModel.Content;
            view.FindViewById <TextView>(Resource.Id.MessagingDetailsPageItemDate).Text    = malMessageModel.Date;
            if (malMessageModel.Images.Any())
            {
                var img = view.FindViewById <ImageViewAsync>(Resource.Id.MessagingDetailsPageItemImage);
                img.Visibility = ViewStates.Invisible;
                img.Into(malMessageModel.Images.First());
            }
            else
            {
                view.FindViewById <ImageViewAsync>(Resource.Id.MessagingDetailsPageItemImage).Visibility = ViewStates.Gone;
            }

            return(view);
        }
예제 #2
0
        private MalMessageModel ParseInboxHtmlToMalMessage(HtmlNode msgNode, bool read)
        {
            var current = new MalMessageModel();

            current.Sender = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
            current.Target = Credentials.UserName;
            var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");

            current.Subject =
                WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
            current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
            current.Id      =
                contentNode.FirstOfDescendantsWithClass("a", "subject-link").Attributes["href"].Value.Split('=')
                .Last();
            current.Date   = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
            current.IsRead = read;

            var ids =
                msgNode.FirstOfDescendantsWithClass("span", "mym_actions").Descendants("a").First().Attributes["href"]
                .Value.Split('=');

            current.ThreadId = ids[3].Substring(0, ids[3].IndexOf('&'));
            current.ReplyId  = ids[2].Substring(0, ids[3].IndexOf('&'));
            return(current);
        }
예제 #3
0
        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>());
        }
예제 #4
0
        public async void Init(MalMessageDetailsNavArgs args, bool force = false)
        {
            if (args.WorkMode == MessageDetailsWorkMode.Message)
            {
                var arg = args.Arg as MalMessageModel;
                if (arg == null) //compose new
                {
                    _newMessage = true;
                    MessageSet.Clear();
                    NewMessageFieldsVisibility = true;
                    ViewModelLocator.GeneralMain.OffRefreshButtonVisibility = false;
                    MessageTarget = args.NewMessageTarget;
                    RaisePropertyChanged(() => MessageTarget);
                    return;
                }
                NewMessageFieldsVisibility = false;
                _newMessage = false;

                if (!force && _prevMsg?.Id == arg.Id)
                {
                    return;
                }
                _prevMsg = arg;
                MessageSet.Clear();
                LoadingVisibility = true;
                if (!force && arg.ThreadId != null && MessageThreads.ContainsKey(arg.ThreadId))
                {
                    MessageSet.AddRange(MessageThreads[arg.ThreadId]);
                }
                else
                {
                    var msgs = await new MalMessageDetailsQuery().GetMessagesInThread(arg);
                    msgs.Reverse();
                    MessageSet.AddRange(msgs);
                }
            }
            else
            {
                NewMessageFieldsVisibility = false;
                var arg = args.Arg as MalComment;
                if (!force && arg.ComToCom == (_prevArgs?.Arg as MalComment)?.ComToCom)
                {
                    return;
                }
                _prevMsg          = null;
                LoadingVisibility = true;
                MessageSet.Clear();
                MessageSet =
                    new SmartObservableCollection <MalMessageModel>(
                        (await ProfileCommentQueries.GetComToComMessages(arg.ComToCom)));
                RaisePropertyChanged(() => MessageSet);
            }
            _prevArgs         = args;
            LoadingVisibility = false;
        }
예제 #5
0
        private MalMessageModel ParseOutboxHtmlToMalMessage(HtmlNode msgNode)
        {
            var current = new MalMessageModel();

            current.Target = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
            current.Sender = Credentials.UserName;
            var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");

            current.Subject =
                WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
            current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
            current.Date    = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
            current.IsMine  = true;
            return(current);
        }
예제 #6
0
        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());
        }
예제 #7
0
        public static async Task <List <MalMessageModel> > GetComToComMessages(string path)
        {
            try
            {
                var client = await ResourceLocator.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)
            {
                ResourceLocator.MalHttpContextProvider.ErrorMessage("Messages");
                return(new List <MalMessageModel>());
            }
        }
예제 #8
0
 public MessageEntry(MalMessageModel msg)
 {
     Msg = msg;
     if (Msg.Sender.Equals(Credentials.UserName, StringComparison.CurrentCultureIgnoreCase))
     {
         HorizontalAlignment = HorizontalAlignment.Right;
         Margin       = new Thickness(20, 0, 0, 0);
         CornerRadius = new CornerRadius(10, 10, 0, 10);
         Background   = Application.Current.Resources["SystemControlHighlightAltListAccentLowBrush"] as Brush;
     }
     else
     {
         HorizontalAlignment = HorizontalAlignment.Left;
         Margin             = new Thickness(0, 0, 20, 0);
         CornerRadius       = new CornerRadius(10, 10, 10, 0);
         Background         = Application.Current.Resources["SystemControlHighlightListAccentLowBrush"] as Brush;
         Background.Opacity = .5;
     }
 }
예제 #9
0
        private View GetMessageTemplateDelegate(int i, MalMessageModel malMessageModel, View convertView)
        {
            var view = convertView;

            if (view == null)
            {
                view        = Activity.LayoutInflater.Inflate(Resource.Layout.MessagingPageItem, null);
                view.Click += MessageOnClick;
            }

            view.Tag = malMessageModel.Wrap();

            view.FindViewById <TextView>(Resource.Id.MessagingPageItemSender).Text  = malMessageModel.Sender;
            view.FindViewById <TextView>(Resource.Id.MessagingPageItemDate).Text    = malMessageModel.Date;
            view.FindViewById <TextView>(Resource.Id.MessagingPageItemContent).Text = malMessageModel.Content;
            view.FindViewById <TextView>(Resource.Id.MessagingPageItemTitle).Text   = malMessageModel.Subject;
            var stateImg = view.FindViewById <ImageView>(Resource.Id.MessagingPageItemStateSymbol);

            if (malMessageModel.IsRead)
            {
                stateImg.SetImageResource(Resource.Drawable.icon_message_read);
                stateImg.ImageTintList = ColorStateList.ValueOf(new Color(ResourceExtension.BrushText));
            }
            else
            {
                if (malMessageModel.IsMine)
                {
                    stateImg.SetImageResource(Resource.Drawable.icon_message_sent);
                    stateImg.ImageTintList = ColorStateList.ValueOf(new Color(ResourceExtension.BrushText));
                }
                else
                {
                    stateImg.SetImageResource(Resource.Drawable.icon_message_alert);
                    stateImg.ImageTintList = ColorStateList.ValueOf(new Color(ResourceExtension.AccentColourDark));
                }
            }

            return(view);
        }
예제 #10
0
        //private async void FetchHistory()
        //{
        //    LoadingVisibility = true;
        //    FetchHistoryVisibility = false;
        //    MessageSet.Clear();
        //    var result = await new MalMessageDetailsQuery().GetMessagesInThread(_prevMsg);
        //    result.Reverse(); //newest first
        //    _messageThreads[_prevMsg.ThreadId] = result;
        //    MessageSet.AddRange(result.Select(model => new MessageEntry(model)));
        //    LoadingVisibility = false;
        //}

        private async void SendMessage()
        {
            IsSendButtonEnabled = false;
            if (!string.IsNullOrEmpty(MessageText))
            {
                if (_prevArgs == null || _prevArgs.WorkMode == MessageDetailsWorkMode.Message)
                {
                    if (_newMessage)
                    {
                        if (MessageSubject == null || MessageTarget == null)
                        {
                            IsSendButtonEnabled = true;
                            return;
                        }
                        if (await new SendMessageQuery().SendMessage(MessageSubject, MessageText, MessageTarget))
                        {
                            try
                            {
                                await Task.Delay(500); //let mal process the thing

                                var message = new MalMessageModel();
                                var id      = await new MalMessagesQuery().GetFirstSentMessageId();
                                message.Id      = id;
                                message         = await new MalMessageDetailsQuery().GetMessageDetails(message, true);
                                message.Target  = MessageTarget;
                                message.Sender  = Credentials.UserName;
                                message.IsRead  = true;
                                message.Date    = DateTime.Now.ToString("d");
                                message.Subject = MessageSubject;
                                MessageThreads[message.ThreadId] = new List <MalMessageModel> {
                                    message
                                };
                                _prevMsg    = message;
                                _newMessage = false;
                                NewMessageFieldsVisibility = false;
                                ViewModelLocator.GeneralMain.CurrentOffStatus = $"{message.Sender} - {message.Subject}";
                                MessageSet.Clear();
                                MessageSet.AddRange(new[]
                                {
                                    message
                                });
                                MessageText    = "";
                                MessageSubject = "";
                                MessageTarget  = "";
                            }
                            catch (Exception)
                            {
                                ResourceLocator.MessageDialogProvider.ShowMessageDialog("Unable to send this message.",
                                                                                        "Error");
                            }
                        }
                        else
                        {
                            ResourceLocator.MessageDialogProvider.ShowMessageDialog("Unable to send this message.",
                                                                                    "Error");
                        }
                        IsSendButtonEnabled = true;
                        return;
                    }

                    if (
                        await
                        new SendMessageQuery().SendMessage(_prevMsg.Subject, MessageText, _prevMsg.Target,
                                                           _prevMsg.ThreadId,
                                                           _prevMsg.ReplyId))
                    {
                        var message = new MalMessageModel
                        {
                            Subject  = _prevMsg.Subject,
                            Content  = MessageText,
                            Date     = DateTime.Now.ToString("d"),
                            Id       = "0",
                            Sender   = Credentials.UserName,
                            Target   = _prevMsg.Target,
                            ThreadId = _prevMsg.ThreadId,
                            ReplyId  = _prevMsg.ReplyId
                        };
                        if (MessageThreads.ContainsKey(_prevMsg.ThreadId))
                        {
                            MessageThreads[_prevMsg.ThreadId].Insert(0, message);
                        }
                        else
                        {
                            MessageThreads[_prevMsg.ThreadId] = new List <MalMessageModel> {
                                _prevMsg, message
                            };
                        }
                        MessageSet.AddRange(new[]
                        {
                            message
                        });
                        MessageText    = "";
                        MessageSubject = "";
                        MessageTarget  = "";
                        RaisePropertyChanged(() => MessageText);
                    }
                    else
                    {
                        ResourceLocator.MessageDialogProvider.ShowMessageDialog("Unable to send this message.", "Error");
                    }
                }
                else //comment
                {
                    var comment = _prevArgs.Arg as MalComment;
                    if (await ProfileCommentQueries.SendCommentReply(comment.ComToCom.Split('=').Last(), MessageText))
                    {
                        MessageSet.Add(

                            new MalMessageModel
                        {
                            Content = MessageText,
                            Sender  = Credentials.UserName,
                            Date    = DateTime.Now.ToString("d")
                        }
                            );
                        MessageText = "";
                        RaisePropertyChanged(() => MessageSet);
                        RaisePropertyChanged(() => MessageText);
                    }
                }
            }
            IsSendButtonEnabled = true;
        }