Exemplo n.º 1
0
        public static async Task <ProfileRelationshipData.ProfileRelationship> GetProfileRelationship(string id)
        {
            string         requestURI = "https://story.kakao.com/a/profiles/" + id + "?profile_only=true";
            HttpWebRequest webRequest = GenerateDefaultProfile(requestURI);
            string         response   = await GetResponseFromRequest(webRequest);

            ProfileRelationshipData.ProfileRelationship obj = JsonConvert.DeserializeObject <ProfileRelationshipData.ProfileRelationship>(response);
            return(obj);
        }
        public async Task RefreshTimeline(string from, bool isClear)
        {
            if (from == null)
            {
                lastOffset = -1;
            }
            BT_Refresh.IsEnabled = false;
            PR_Loading.IsActive  = true;
            TB_RefreshBT.Text    = "갱신중...";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.ProgressClock;

            List <CommentData.PostData> feeds;

            if (!isProfile)
            {
                TimeLineData.TimeLine feedData = await KakaoRequestClass.GetFeed(from);

                nextRequest = feedData.next_since;
                feeds       = feedData.feeds;
            }
            else
            {
                string from2 = from;
                if (showBookmarked)
                {
                    from2 = null;
                }
                var profile = await KakaoRequestClass.GetProfileFeed(profileID, from2);

                relationship = await KakaoRequestClass.GetProfileRelationship(profileID);

                if (profile.profile.bg_image_url != null)
                {
                    string imgUri = profile.profile.profile_video_url_square_small ?? profile.profile.profile_image_url2;
                    if (Properties.Settings.Default.GIFProfile && profile.profile.profile_video_url_square_small != null)
                    {
                        imgUri = profile.profile.profile_video_url_square_small;
                    }
                    GlobalHelper.AssignImage(IMG_Profile, imgUri);
                    GlobalHelper.AssignImage(IMG_ProfileBG, profile.profile.bg_image_url);
                    IMG_Profile.MouseLeftButtonDown   += GlobalHelper.SaveImageHandler;
                    IMG_ProfileBG.MouseLeftButtonDown += GlobalHelper.SaveImageHandler;

                    TB_Name.Text = profile.profile.display_name;

                    if (profile.profile.status_objects?.Count > 0)
                    {
                        TB_Desc.Text = profile.profile.status_objects?[0]?.message ?? "한줄 소개 없음";
                    }
                    else
                    {
                        TB_Desc.Text = "한줄 소개 없음";
                    }

                    TB_Desc2.Text  = profile.mutual_friend?.message ?? "함께 아는 친구 없음";
                    TB_Desc2.Text += "/ " + profile.profile.activity_count.ToString() + "개의 스토리";
                }
                GD_Favorite.Visibility = Visibility.Collapsed;
                if (relationship.relationship.Equals("F"))
                {
                    IC_Friend.Kind         = MaterialDesignThemes.Wpf.PackIconKind.AccountMinus;
                    IC_Friend.ToolTip      = "친구 삭제";
                    GD_Favorite.Visibility = Visibility.Visible;
                    if (profile.profile.is_favorite)
                    {
                        IC_Favorite.Fill = Brushes.OrangeRed;
                    }
                    else
                    {
                        IC_Favorite.Fill = Brushes.Gray;
                    }
                    MainWindow.SetClickObject(IC_Favorite);
                    ICP_Favorite.MouseEnter += (s, e) =>
                    {
                        Mouse.OverrideCursor = Cursors.Hand;
                        e.Handled            = true;
                    };
                    async void onMouseDown(object s, MouseButtonEventArgs e)
                    {
                        await KakaoRequestClass.FavoriteRequest(profile.profile.id, profile.profile.is_favorite);

                        await RefreshTimeline(null, true);

                        e.Handled = true;
                    }

                    IC_Favorite.MouseLeftButtonDown  += onMouseDown;
                    ICP_Favorite.MouseLeftButtonDown += onMouseDown;
                }
                else if (relationship.relationship.Equals("R"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountRemove;
                    IC_Friend.ToolTip = "친구 신청 취소";
                }
                else if (relationship.relationship.Equals("C"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountQuestionMark;
                    IC_Friend.ToolTip = "친구 신청 처리";
                }
                else if (relationship.relationship.Equals("N"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountPlus;
                    IC_Friend.ToolTip = "친구 추가";
                }
                else
                {
                    IC_Friend.Visibility = Visibility.Collapsed;
                }

                BT_Write.Visibility = Visibility.Collapsed;
                if (profile.activities.Count > 15)
                {
                    nextRequest = profile.activities.Last().id;
                }

                if (MainWindow.UserProfile.id.Equals(profileID) && showBookmarked != true)
                {
                    Title         = "내 프로필";
                    TB_Desc2.Text = profile.profile.activity_count.ToString() + "개의 스토리";
                }
                else
                {
                    Title = profile.profile.display_name + "님의 프로필";
                }
                if (showBookmarked)
                {
                    Title = "관심글 조회";
                    var bookmarks = await KakaoRequestClass.GetBookmark(profileID, from);

                    var feedsNow = new List <CommentData.PostData>();
                    foreach (var bookmark in bookmarks.bookmarks)
                    {
                        if (bookmark.status == 0)
                        {
                            feedsNow.Add(bookmark.activity);
                        }
                    }
                    feeds       = feedsNow;
                    nextRequest = bookmarks.bookmarks.Last().id;
                }
                else
                {
                    feeds = profile.activities;
                }
            }

            if (isProfile && feeds.Count != 18)
            {
                scrollEnd = true;
            }

            if (isClear)
            {
                SP_Content.Children.Clear();
                SV_Content.ScrollToVerticalOffset(0);
            }
            foreach (var feed in feeds)
            {
                if (feed.verb.Equals("post") || feed.verb.Equals("share"))
                {
                    TimeLinePageControl tlp = GenerateTimeLinePageControl(feed);
                    SP_Content.Children.Add(tlp);
                    SP_Content.Children.Add(new Rectangle()
                    {
                        Height = 10,
                        Fill   = Brushes.Transparent
                    });
                }
                else if (feed.verb.Equals("bundled_feed"))
                {
                    try
                    {
                        if (feed.bundled_feed != null && feed.bundled_feed.type.Equals("share"))
                        {
                            CommentData.PostData feedNow = feed.bundled_feed.activities?[0];
                            if (feedNow != null)
                            {
                                feedNow.@object = feed.bundled_feed.original_activity;
                                TimeLinePageControl tlp = GenerateTimeLinePageControl(feedNow);
                                GlobalHelper.SetShareFriendsTB(tlp.TB_Title, feed.bundled_feed.title_decorators);
                                tlp.TB_Title.Visibility    = Visibility.Visible;
                                tlp.TB_TitleSep.Visibility = Visibility.Visible;
                                SP_Content.Children.Add(tlp);
                                SP_Content.Children.Add(new Rectangle()
                                {
                                    Height = 10,
                                    Fill   = Brushes.Transparent
                                });
                            }
                        }
                        else if (feed.bundled_feed != null && feed.bundled_feed.type.Equals("up"))
                        {
                            CommentData.PostData feedNow = feed.bundled_feed.original_activity;
                            if (feedNow != null)
                            {
                                TimeLinePageControl tlp = GenerateTimeLinePageControl(feedNow);
                                GlobalHelper.SetShareFriendsTB(tlp.TB_Title, feed.bundled_feed.title_decorators);
                                tlp.TB_Title.Visibility    = Visibility.Visible;
                                tlp.TB_TitleSep.Visibility = Visibility.Visible;
                                SP_Content.Children.Add(tlp);
                                SP_Content.Children.Add(new Rectangle()
                                {
                                    Height = 10,
                                    Fill   = Brushes.Transparent
                                });
                            }
                        }
                    }
                    catch (Exception) { }
                }
            }
            BT_Refresh.IsEnabled = true;
            TB_RefreshBT.Text    = "새로고침";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.Refresh;

            PR_Loading.IsActive = false;
            return;
        }