Esempio n. 1
0
        private DynamicItemDisplayModel ConvertToDisplayRepost(DynamicCardModel item)
        {
            var card = JObject.Parse(item.card);
            var data = new DynamicItemDisplayModel()
            {
                Datetime    = Utils.TimestampToDatetime(item.desc.timestamp).ToString(),
                DynamicID   = item.desc.dynamic_id,
                Mid         = item.desc.uid,
                Time        = Utils.HandelTimestamp(item.desc.timestamp.ToString()),
                UserCommand = UserCommand
            };
            var content = "";

            //内容
            if (card.ContainsKey("item") && card["item"]["content"] != null)
            {
                content = card["item"]["content"]?.ToString();
            }
            data.ContentStr = content;

            if (item.desc.user_profile != null)
            {
                data.UserName = item.desc.user_profile.info.uname;
                data.Photo    = item.desc.user_profile.info.face;
                if (item.desc.user_profile.vip != null)
                {
                    data.IsYearVip = item.desc.user_profile.vip.vipType == 2;
                }
                switch (item.desc.user_profile.card?.official_verify?.type ?? 3)
                {
                case 0:
                    data.Verify = AppHelper.VERIFY_PERSONAL_IMAGE;
                    break;

                case 1:
                    data.Verify = AppHelper.VERIFY_OGANIZATION_IMAGE;
                    break;

                default:
                    data.Verify = AppHelper.TRANSPARENT_IMAGE;
                    break;
                }
                if (!string.IsNullOrEmpty(item.desc.user_profile.pendant?.image))
                {
                    data.Pendant = item.desc.user_profile.pendant.image;
                }
            }
            return(data);
        }
Esempio n. 2
0
        private DynamicItemDisplayModel ConvertToDisplay(DynamicCardModel item)
        {
            try
            {
                var card        = JObject.Parse(item.card);
                var extend_json = JObject.Parse(item.extend_json);
                var data        = new DynamicItemDisplayModel()
                {
                    CommentCount      = item.desc.comment,
                    Datetime          = Utils.TimestampToDatetime(item.desc.timestamp).ToString(),
                    DynamicID         = item.desc.dynamic_id,
                    LikeCount         = item.desc.like,
                    Mid               = item.desc.uid,
                    ShareCount        = item.desc.repost,
                    Time              = Utils.HandelTimestamp(item.desc.timestamp.ToString()),
                    IntType           = item.desc.type,
                    ReplyID           = item.desc.rid_str,
                    ReplyType         = item.desc.r_type,
                    Type              = DynamicParse.ParseType(item.desc.type),
                    UserCommand       = UserCommand,
                    LaunchUrlCommand  = LaunchUrlCommand,
                    WebCommand        = WebCommand,
                    TagCommand        = TagCommand,
                    LotteryCommand    = LotteryCommand,
                    VoteCommand       = VoteCommand,
                    IsSelf            = item.desc.uid == SettingHelper.Account.UserID,
                    ImageCommand      = ImageCommand,
                    CommentCommand    = CommentCommand,
                    LikeCommand       = LikeCommand,
                    DeleteCommand     = DeleteCommand,
                    RepostCommand     = RepostCommand,
                    DetailCommand     = DetailCommand,
                    WatchLaterCommand = watchLaterVM.AddCommand,
                    Liked             = item.desc.is_liked == 1
                };
                if (data.Type == DynamicDisplayType.Other)
                {
                    return(new DynamicItemDisplayModel()
                    {
                        Type = DynamicDisplayType.Other,
                        IntType = 999,
                        DynamicID = item.desc.dynamic_id,
                        ContentStr = $"未适配的类型{data.IntType}:\r\n" + JsonConvert.SerializeObject(item)
                    });
                }
                data.OneRowInfo = DynamicParse.ParseOneRowInfo(data.Type, card);
                if (data.Type == DynamicDisplayType.ShortVideo)
                {
                    data.ShortVideoInfo = DynamicParse.ParseShortVideoInfo(card);
                }
                if (data.Type == DynamicDisplayType.Photo)
                {
                    List <DyanmicItemDisplayImageInfo> imgs = new List <DyanmicItemDisplayImageInfo>();
                    List <string> allImageUrl = new List <string>();
                    int           i           = 0;
                    foreach (var img in card["item"]["pictures"])
                    {
                        allImageUrl.Add(img["img_src"].ToString());
                        imgs.Add(new DyanmicItemDisplayImageInfo()
                        {
                            ImageUrl     = img["img_src"].ToString(),
                            Height       = img["img_height"].ToInt32(),
                            Width        = img["img_width"].ToInt32(),
                            Index        = i,
                            ImageCommand = ImageCommand
                        });
                        i++;
                    }

                    //偷懒方法,点击图片时可以获取全部图片信息,好孩子不要学
                    imgs.ForEach((x) => x.AllImages = allImageUrl);

                    data.ImagesInfo = imgs;
                }

                if (data.Type == DynamicDisplayType.Repost)
                {
                    if (card.ContainsKey("origin_user"))
                    {
                        var originUser    = JsonConvert.DeserializeObject <DynamicCardDescUserProfileModel>(card["origin_user"].ToString());
                        var originDisplay = ConvertToDisplay(new DynamicCardModel()
                        {
                            extend_json = card["origin_extend_json"].ToString(),
                            card        = card["origin"].ToString(),
                            display     = item.display?.origin,
                            desc        = new DynamicCardDescModel()
                            {
                                user_profile = originUser,
                                uid          = originUser.info.uid,
                                dynamic_id   = item.desc.orig_dy_id,
                                type         = item.desc.orig_type
                            }
                        });
                        originDisplay.IsRepost = true;
                        data.OriginInfo        = new List <DynamicItemDisplayModel>()
                        {
                            originDisplay
                        };
                    }
                    else
                    {
                        data.OriginInfo = new List <DynamicItemDisplayModel>()
                        {
                            new DynamicItemDisplayModel()
                            {
                                IsRepost = true,
                                IntType  = 1024,
                                Type     = DynamicDisplayType.Miss
                            }
                        };
                    }
                }
                if (item.desc.comment == 0 && card.ContainsKey("stat"))
                {
                    data.CommentCount = card["stat"]["reply"].ToInt32();
                }
                //Season数据会出现desc.comment为0的情况
                if (item.desc.comment == 0 && card.ContainsKey("reply_count"))
                {
                    data.CommentCount = card["reply_count"].ToInt32();
                }
                //专栏数据会出现desc.comment为0的情况
                if (item.desc.comment == 0 && card.ContainsKey("stats"))
                {
                    data.CommentCount = card["stats"]["reply"].ToInt32();
                }
                var content = "";
                //内容
                if (card.ContainsKey("item") && card["item"]["content"] != null)
                {
                    content = card["item"]["content"]?.ToString();
                    extend_json["at_control"] = card["item"]["ctrl"];
                }
                else if (card.ContainsKey("item") && card["item"]["description"] != null)
                {
                    content = card["item"]["description"]?.ToString();
                    extend_json["at_control"] = card["item"]["at_control"];
                }
                else if (card.ContainsKey("dynamic"))
                {
                    content = card["dynamic"]?.ToString();
                }
                else if (card.ContainsKey("vest") && card["vest"]["content"] != null)
                {
                    content = card["vest"]["content"]?.ToString();
                }

                if (!string.IsNullOrEmpty(content))
                {
                    data.ContentStr = content;
                    data.Content    = DynamicParse.StringToRichText(item.desc.dynamic_id, content, item.display?.emoji_info?.emoji_details, extend_json);
                }
                else
                {
                    data.ShowContent = false;
                }


                if (item.desc.user_profile != null)
                {
                    data.UserName = item.desc.user_profile.info.uname;
                    data.Photo    = item.desc.user_profile.info.face;
                    if (item.desc.user_profile.vip != null)
                    {
                        data.IsYearVip = item.desc.user_profile.vip.vipType == 2;
                    }
                    switch (item.desc.user_profile.card?.official_verify?.type ?? 3)
                    {
                    case 0:
                        data.Verify = AppHelper.VERIFY_PERSONAL_IMAGE;
                        break;

                    case 1:
                        data.Verify = AppHelper.VERIFY_OGANIZATION_IMAGE;
                        break;

                    default:
                        data.Verify = AppHelper.TRANSPARENT_IMAGE;
                        break;
                    }
                    if (!string.IsNullOrEmpty(item.desc.user_profile.pendant?.image))
                    {
                        data.Pendant = item.desc.user_profile.pendant.image;
                    }
                    //装扮
                    data.DecorateName  = item.desc.user_profile.decorate_card?.name;
                    data.DecorateText  = item.desc.user_profile.decorate_card?.fan?.num_desc;
                    data.DecorateColor = item.desc.user_profile.decorate_card?.fan?.color;
                    data.DecorateImage = item.desc.user_profile.decorate_card?.big_card_url;
                }


                if (card.ContainsKey("apiSeasonInfo"))
                {
                    data.UserName = card["apiSeasonInfo"]["title"].ToString();
                    data.Photo    = card["apiSeasonInfo"]["cover"].ToString();
                    data.TagName  = card["apiSeasonInfo"]["type_name"].ToString();
                    data.ShowTag  = true;
                    data.Time     = data.Time + "更新了";
                }
                if (card.ContainsKey("season"))
                {
                    data.UserName = card["season"]["title"].ToString();
                    data.Photo    = card["season"]["cover"].ToString();
                    data.TagName  = card["season"]["type_name"].ToString();
                    data.ShowTag  = true;
                    data.Time     = data.Time + "更新了";
                }
                return(data);
            }
            catch (Exception)
            {
                return(new DynamicItemDisplayModel()
                {
                    Type = DynamicDisplayType.Other,
                    IntType = 999,
                    DynamicID = item.desc.dynamic_id,
                    ContentStr = "动态加载失败:\r\n" + JsonConvert.SerializeObject(item)
                });
            }
        }