예제 #1
0
        public FeedModel(JObject token, FeedDisplayMode mode = FeedDisplayMode.normal) : base(token)
        {
            ShowMessageTitle = !string.IsNullOrEmpty(MessageTitle) && !mode.HasFlag(FeedDisplayMode.notShowMessageTitle);
            if (mode.HasFlag(FeedDisplayMode.isFirstPageFeed))
            {
                Regex r  = new Regex("<a.*?>", RegexOptions.IgnoreCase);
                Regex r1 = new Regex("<a.*?/>", RegexOptions.IgnoreCase);
                Regex r2 = new Regex("</a.*?>", RegexOptions.IgnoreCase);
                Info          = token.Value <string>("infoHtml").Replace("&nbsp;", string.Empty, StringComparison.Ordinal);
                Info          = r.Replace(Info, "");
                Info          = r1.Replace(Info, "");
                Info          = r2.Replace(Info, "");
                ShowDateline  = false;
                ShowReplyRows = token.TryGetValue("replyRows", out JToken value) && ((value as JArray)?.Count ?? 0) > 0;
                if (ShowReplyRows)
                {
                    ReplyRows = value.Select(item => new ReplyRowsItem((JObject)item)).ToList();
                }
            }
            else if (mode.HasFlag(FeedDisplayMode.normal) && token.TryGetValue("info", out JToken value1))
            {
                Info = value1.ToString();
            }

            if (token.Value <string>("entityType") == "article")
            {
                ShowDyh = !mode.HasFlag(FeedDisplayMode.notShowDyhName);
                if (ShowDyh)
                {
                    Dyhurl  = token["dyh_info"].Value <string>("url");
                    Dyhname = token.Value <string>("dyh_name");
                    var dyhlogoUrl = token["dyh_info"].Value <string>("logo");
                    if (!string.IsNullOrEmpty(dyhlogoUrl))
                    {
                        Dyhlogo = new ImageModel(dyhlogoUrl, ImageType.Icon);
                    }
                }
                ShowFromInfo = (token["dyh_info"] as JObject).TryGetValue("fromInfo", out JToken value);
                if (ShowFromInfo)
                {
                    FromInfo = value.ToString();
                    Uurl     = $"/u/{token.Value<int>("from_uid")}";
                }
            }
            else
            {
                ShowLikes = token.Value <string>("feedType") != "question";
                try
                {
                    HaveUserInfo = !string.IsNullOrEmpty((string)token["userInfo"]);
                }
                catch
                {
                    HaveUserInfo = false;
                }
                Uurl = HaveUserInfo ? token["userInfo"].Value <string>("url") : "/u/" + token.Value <string>("uid");
            }

            ShowRelationRows = (token.TryGetValue("location", out JToken vLocation) && !string.IsNullOrEmpty(vLocation.ToString())) |
                               (token.TryGetValue("ttitle", out JToken vTtitle) && !string.IsNullOrEmpty(vTtitle.ToString())) |
                               (token.TryGetValue("dyh_name", out JToken vDyh) && !string.IsNullOrEmpty(vDyh.ToString())) |
                               (token.TryGetValue("relationRows", out JToken vRelationRows) && ((vRelationRows as JArray)?.Count ?? 0) > 0);
            if (ShowRelationRows)
            {
                var buider = new List <RelationRowsItem>();
                if (vLocation != null && !string.IsNullOrEmpty(vLocation.ToString()))
                {
                    buider.Add(new RelationRowsItem {
                        Title = vLocation.ToString()
                    });
                }

                if (vTtitle != null && !string.IsNullOrEmpty(vTtitle.ToString()))
                {
                    buider.Add(new RelationRowsItem {
                        Title = vTtitle.ToString(), Url = token.Value <string>("turl"), Logo = new ImageModel(token.Value <string>("tpic"), ImageType.Icon)
                    });
                }

                if (token.Value <string>("entityType") != "article" && vDyh != null && !string.IsNullOrEmpty(vDyh.ToString()))
                {
                    buider.Add(new RelationRowsItem {
                        Title = vDyh.ToString(), Url = $"/dyh/{token["dyh_id"].ToString().Replace("\"", string.Empty)}"
                    });
                }

                if (vRelationRows != null)
                {
                    foreach (var i in vRelationRows as JArray)
                    {
                        JObject item = i as JObject;
                        buider.Add(new RelationRowsItem
                        {
                            Title = item.Value <string>("title"),
                            Url   = item.Value <string>("url"),
                            Logo  = new ImageModel(item.Value <string>("logo"), ImageType.Icon)
                        });
                    }
                }

                ShowRelationRows = buider.Count != 0;
                RelationRows     = buider;
            }
            IsStickTop = token.TryGetValue("isStickTop", out JToken j) && int.Parse(j.ToString()) == 1;
        }
예제 #2
0
        public FeedModel(JObject token, FeedDisplayMode mode = FeedDisplayMode.normal) : base(token)
        {
            if (!string.IsNullOrEmpty(MessageTitle) && !mode.HasFlag(FeedDisplayMode.notShowMessageTitle))
            {
                ShowMessageTitle = true;
            }
            if (mode.HasFlag(FeedDisplayMode.isFirstPageFeed))
            {
                Info          = token.Value <string>("infoHtml").Replace("&nbsp;", string.Empty);
                ShowDateline  = false;
                ShowReplyRows = token.TryGetValue("replyRows", out JToken value) && (value as JArray ?? new JArray()).Count > 0 ? true : false;
                if (ShowReplyRows)
                {
                    var buider = ImmutableArray.CreateBuilder <ReplyRowsItem>();
                    foreach (var i in value as JArray)
                    {
                        buider.Add(new ReplyRowsItem(i as JObject));
                    }

                    ReplyRows = buider.ToImmutable();
                }
            }
            else if (mode.HasFlag(FeedDisplayMode.normal))
            {
                if (token.TryGetValue("info", out JToken value1))
                {
                    Info = value1.ToString();
                }
            }

            if (token.Value <string>("entityType") != "article")
            {
                if (token.Value <string>("feedType") == "question")
                {
                    ShowLikes = false;
                }
                Uurl = token["userInfo"].Value <string>("url");
            }
            else
            {
                if (!mode.HasFlag(FeedDisplayMode.notShowDyhName))
                {
                    ShowDyh = true;
                    var dyhlogoUrl = token["dyh_info"].Value <string>("logo");
                    if (!string.IsNullOrEmpty(dyhlogoUrl))
                    {
                        Dyhlogo = new ImageModel(dyhlogoUrl, ImageType.Icon);
                    }
                    Dyhurl  = token["dyh_info"].Value <string>("url");
                    Dyhname = token.Value <string>("dyh_name");
                }
                ShowFromInfo = (token["dyh_info"] as JObject).TryGetValue("fromInfo", out JToken value);
                if (ShowFromInfo)
                {
                    FromInfo = value.ToString();
                    Uurl     = $"/u/{token.Value<int>("from_uid")}";
                }
            }

            ShowRelationRows = (token.TryGetValue("location", out JToken valuelocation) && !string.IsNullOrEmpty(valuelocation.ToString()))
                               | (token.TryGetValue("ttitle", out JToken valuettitle) && !string.IsNullOrEmpty(valuettitle.ToString()))
                               | (token.TryGetValue("dyh_name", out JToken valuedyh) && !string.IsNullOrEmpty(valuedyh.ToString()))
                               | (token.TryGetValue("relationRows", out JToken valuerelationRows) && (valuerelationRows as JArray ?? new JArray()).Count > 0);
            if (ShowRelationRows)
            {
                var buider = ImmutableArray.CreateBuilder <RelationRowsItem>();
                if (!(valuelocation == null || string.IsNullOrEmpty(valuelocation.ToString())))
                {
                    buider.Add(new RelationRowsItem {
                        Title = valuelocation.ToString()
                    });
                }

                if (!(valuettitle == null || string.IsNullOrEmpty(valuettitle.ToString())))
                {
                    buider.Add(new RelationRowsItem {
                        Title = valuettitle.ToString(), Url = token.Value <string>("turl"), Logo = new ImageModel(token.Value <string>("tpic"), ImageType.Icon)
                    });
                }

                if (!(token.Value <string>("entityType") == "article" || valuedyh == null || string.IsNullOrEmpty(valuedyh.ToString())))
                {
                    buider.Add(new RelationRowsItem {
                        Title = valuedyh.ToString(), Url = $"/dyh/{token["dyh_id"].ToString().Replace("\"", string.Empty)}"
                    });
                }

                if (valuerelationRows != null)
                {
                    foreach (var i in valuerelationRows as JArray)
                    {
                        JObject item = i as JObject;
                        buider.Add(new RelationRowsItem {
                            Title = item.Value <string>("title"), Url = item.Value <string>("url"), Logo = new ImageModel(item.Value <string>("logo"), ImageType.Icon)
                        });
                    }
                }

                RelationRows = buider.ToImmutable();
                if (buider.Count == 0)
                {
                    ShowRelationRows = false;
                }
            }
            IsStickTop = token.TryGetValue("isStickTop", out JToken j) && int.Parse(j.ToString()) == 1;
        }
예제 #3
0
        public FeedModelBase(JObject token) : base(token)
        {
            if (token.TryGetValue("info", out JToken value1))
            {
                Info = value1.ToString();
            }
            Likenum  = token["likenum"].ToString().Replace("\"", string.Empty);
            Replynum = token["replynum"].ToString().Replace("\"", string.Empty);
            ShareNum = token["forwardnum"].ToString().Replace("\"", string.Empty);
            if (token.Value <string>("entityType") != "article")
            {
                if (IsQuestionFeed)
                {
                    QuestionAnswerNum = token["question_answer_num"].ToString().Replace("\"", string.Empty);
                    QuestionFollowNum = token["question_follow_num"].ToString().Replace("\"", string.Empty);
                }
                ShowSourceFeedGrid = !IsQuestionFeed && !string.IsNullOrEmpty(token["source_id"]?.ToString());
                if (ShowSourceFeedGrid)
                {
                    ShowSourceFeed = token.TryGetValue("forwardSourceFeed", out JToken jsonValue) &&
                                     jsonValue != null &&
                                     jsonValue.ToString() != "null" &&
                                     jsonValue.ToString() != string.Empty;
                    if (ShowSourceFeed)
                    {
                        SourceFeed = new SourceFeedModel(jsonValue as JObject);
                    }
                }
                //if (token["entityTemplate"].GetString() == "feedByDyhHeader") showUser = false;
                if (ShowUser)
                {
                    var userSmallAvatarUrl = token["userInfo"]["userSmallAvatar"].ToString();
                    if (!string.IsNullOrEmpty(userSmallAvatarUrl))
                    {
                        UserSmallAvatar = new ImageModel(userSmallAvatarUrl, ImageType.BigAvatar);
                    }
                }

                ShowExtraUrl = token.TryGetValue("extra_title", out JToken valueextra_title) && !string.IsNullOrEmpty(valueextra_title.ToString());
                if (ShowExtraUrl)
                {
                    ExtraTitle = valueextra_title.ToString();
                    ExtraUrl   = token.Value <string>("extra_url");
                    if (!string.IsNullOrEmpty(ExtraUrl))
                    {
                        if (ExtraUrl.IndexOf("http") == 0)
                        {
                            ExtraUrl2 = new Uri(ExtraUrl).Host;
                        }
                        else
                        {
                            ExtraUrl2 = string.Empty;
                        }
                    }
                    else
                    {
                        ExtraUrl2 = string.Empty;
                    }
                    var extraPicUrl = token.Value <string>("extra_pic");
                    if (!string.IsNullOrEmpty(extraPicUrl))
                    {
                        ExtraPic = new ImageModel(extraPicUrl, ImageType.Icon);
                    }
                }
                DeviceTitle = token.Value <string>("device_title");
            }
            //else showUser = false;
            Liked = token.TryGetValue("userAction", out JToken v) ? int.Parse(v["like"].ToString()) == 1 : false;
        }
예제 #4
0
        public FeedDetailModel(JObject o) : base(o)
        {
            Title = o.Value <string>("title");
            if (o.Value <string>("entityType") != "article")
            {
                if (o.Value <string>("feedType") == "feedArticle")
                {
                    IsFeedArticle = true;
                }
                if (IsFeedArticle)
                {
                    HasMessageCover = o.TryGetValue("message_cover", out JToken value) && !string.IsNullOrEmpty(value.ToString());
                    if (HasMessageCover)
                    {
                        MessageCover = new ImageModel(value.ToString(), ImageType.SmallImage);
                    }

                    MessageRawOutput = string.Empty;
                    StringBuilder builder = new StringBuilder();
                    foreach (JObject item in JArray.Parse(o.Value <string>("message_raw_output")))
                    {
                        switch (item.Value <string>("type"))
                        {
                        case "text":
                            builder.Append(item.Value <string>("message"));
                            break;

                        case "image":
                            string description = string.IsNullOrEmpty(item.Value <string>("description")) ? string.Empty : item.Value <string>("description");
                            string uri         = item.Value <string>("url");
                            builder.Append($"\n<a t=\"image\" href=\"{uri}\">{description}</a>\n");
                            break;
                        }
                    }
                    MessageRawOutput = builder.ToString();
                }
                IsAnswerFeed = o.Value <string>("feedType") == "answer";
                if (IsAnswerFeed)
                {
                    JObject j = JObject.Parse(o.Value <string>("extraData"));
                    QuestionAnswerNum = j.Value <int>("questionAnswerNum");
                    QuestionUrl       = j.Value <string>("questionUrl");
                }
            }
            ShowTtitle = o.TryGetValue("ttitle", out JToken valuettitle) && !string.IsNullOrEmpty(valuettitle.ToString());
            if (ShowTtitle)
            {
                Ttitle = valuettitle.ToString();
                Turl   = o.Value <string>("turl");
                Tpic   = new ImageModel(o.Value <string>("tpic"), ImageType.Icon);
            }

            ShowDyhName = o.TryGetValue("dyh_name", out JToken valuedyh) && !string.IsNullOrEmpty(valuedyh.ToString());
            if (ShowDyhName)
            {
                DyhName = valuedyh.ToString();
                DyhUrl  = $"/dyh/{o.Value<int>("dyh_id")}";
            }
            ShowRelationRows = (o.TryGetValue("location", out JToken valuelocation) && !string.IsNullOrEmpty(valuelocation.ToString()))
                               | (o.TryGetValue("relationRows", out JToken valuerelationRows) && (valuerelationRows as JArray ?? new JArray()).Count > 0);
            if (ShowRelationRows)
            {
                var builder = ImmutableArray.CreateBuilder <RelationRowsItem>();
                if (valuelocation != null && !string.IsNullOrEmpty(valuelocation.ToString()))
                {
                    builder.Add(new RelationRowsItem {
                        Title = valuelocation.ToString()
                    });
                }

                if (valuerelationRows != null)
                {
                    foreach (JObject item in valuerelationRows as JArray)
                    {
                        builder.Add(new RelationRowsItem {
                            Title = item.Value <string>("title"), Url = item.Value <string>("url"), Logo = new ImageModel(item.Value <string>("logo"), ImageType.Icon)
                        });
                    }
                }

                if (builder.Count == 0)
                {
                    ShowRelationRows = false;
                }
                RelationRows = builder.ToImmutable();
            }

            ShowHotReplies = o.TryGetValue("hotReplyRows", out JToken hotReplyRows) && !string.IsNullOrEmpty(hotReplyRows.ToString());
            if (ShowHotReplies)
            {
                var builder = ImmutableArray.CreateBuilder <FeedReplyModel>();
                foreach (JObject item in hotReplyRows as JArray)
                {
                    builder.Add(new FeedReplyModel(item));
                }

                HotReplies = builder.ToImmutable();
            }
        }
예제 #5
0
 public FeedDetailModel(JObject token) : base(token)
 {
     Title = token.Value <string>("title");
     if (token.Value <string>("entityType") != "article")
     {
         if (token.TryGetValue("share_num", out JToken s))
         {
             Share_num = s.ToString().Replace("\"", string.Empty);
         }
         if (token.Value <string>("feedType") == "feedArticle")
         {
             IsFeedArticle = true;
         }
         if (IsFeedArticle)
         {
             Has_message_cover = token.TryGetValue("message_cover", out JToken value) && !string.IsNullOrEmpty(value.ToString());
             if (Has_message_cover)
             {
                 Message_cover = new ImageModel(value.ToString(), ImageType.SmallImage);
             }
             JArray array = JArray.Parse(token.Value <string>("message_raw_output"));
             Message_raw_output = string.Empty;
             StringBuilder builder = new StringBuilder();
             List <string> vs      = new List <string>();
             foreach (var i in array)
             {
                 JObject item = i as JObject;
                 if (item.Value <string>("type") == "text")
                 {
                     builder.Append(item.Value <string>("message"));
                 }
                 else if (item.Value <string>("type") == "image")
                 {
                     string description = string.IsNullOrEmpty(item.Value <string>("description")) ? string.Empty : item.Value <string>("description");
                     string uri         = item.Value <string>("url");
                     builder.Append($"\n<a t=\"image\" href=\"{uri}\">{description}</a>\n");
                     vs.Add(uri);
                 }
             }
             FeedArticlePics    = vs.ToArray();
             Message_raw_output = builder.ToString();
         }
         if (token.Value <string>("feedType") == "answer")
         {
             IsAnswerFeed = true;
         }
         if (IsAnswerFeed)
         {
             JObject j = JObject.Parse(token.Value <string>("extraData"));
             QuestionAnswerNum = j.Value <int>("questionAnswerNum").ToString();
             QuestionUrl       = j.Value <string>("questionUrl");
         }
     }
     ShowTtitle = token.TryGetValue("ttitle", out JToken valuettitle) && !string.IsNullOrEmpty(valuettitle.ToString());
     if (ShowTtitle)
     {
         Ttitle = valuettitle.ToString();
         Turl   = token.Value <string>("turl");
         Tpic   = new ImageModel(token.Value <string>("tpic"), ImageType.Icon);
     }
     Show_dyh_name = token.TryGetValue("dyh_name", out JToken valuedyh) && !string.IsNullOrEmpty(valuedyh.ToString());
     if (Show_dyh_name)
     {
         Dyh_name = valuedyh.ToString();
         DyhUrl   = $"/dyh/{token.Value<int>("dyh_id")}";
     }
     ShowRelationRows = (token.TryGetValue("location", out JToken valuelocation) && !string.IsNullOrEmpty(valuelocation.ToString()))
                        | (token.TryGetValue("relationRows", out JToken valuerelationRows) && (valuerelationRows as JArray ?? new JArray()).Count > 0);
     if (ShowRelationRows)
     {
         List <RelationRowsItem> vs = new List <RelationRowsItem>();
         if (valuelocation != null && !string.IsNullOrEmpty(valuelocation.ToString()))
         {
             vs.Add(new RelationRowsItem {
                 Title = valuelocation.ToString()
             });
         }
         if (valuerelationRows != null)
         {
             foreach (var i in valuerelationRows as JArray)
             {
                 JObject item = i as JObject;
                 vs.Add(new RelationRowsItem {
                     Title = item.Value <string>("title"), Url = item.Value <string>("url"), Logo = new ImageModel(item.Value <string>("logo"), ImageType.Icon)
                 });
             }
         }
         if (vs.Count == 0)
         {
             ShowRelationRows = false;
         }
         RelationRows = vs.ToArray();
     }
 }