예제 #1
0
        private void ShowFriends(string filter)
        {
            SP_Content.Children.Clear();
            controls.Clear();

            foreach (var friend in MainWindow.UserFriends.profiles)
            {
                if (friend.blocked != true && friend.display_name.ToLower().Contains(filter.ToLower()))
                {
                    if (CB_OnlyFavorite.IsChecked == true && !friend.is_favorite)
                    {
                        continue;
                    }

                    FriendSelectControl fsc = new FriendSelectControl
                    {
                        id   = friend.id,
                        name = friend.display_name
                    };
                    MainWindow.SetClickObject(fsc.Grid);
                    string imgUri = friend.profile_thumbnail_url;
                    if (Properties.Settings.Default.GIFProfile && friend.profile_video_url_square_small != null)
                    {
                        imgUri = friend.profile_video_url_square_small;
                    }
                    GlobalHelper.AssignImage(fsc.IMG_Profile, imgUri);
                    fsc.TB_Name.Text         = friend.display_name;
                    fsc.TB_Name.Tag          = friend.is_favorite;
                    fsc.Grid.Tag             = friend.id;
                    fsc.MouseLeftButtonDown += OnGridClick;
                    fsc.Tag        = false;
                    fsc.Background = Brushes.Transparent;
                    controls.Add(fsc);
                    SP_Content.Children.Add(fsc);
                }
            }
            SV_Content.ScrollToTop();
            if (controls.Count == 0)
            {
                TB_Empty.Visibility = Visibility.Visible;
            }
            else
            {
                TB_Empty.Visibility = Visibility.Collapsed;
            }
        }
        public async Task Refresh()
        {
            PR_Loading.IsActive  = true;
            BT_Refresh.IsEnabled = false;
            TB_RefreshBT.Text    = "갱신중..";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.ProgressClock;
            List <CSNotification> notifications = await KakaoRequestClass.RequestNotification(true);

            SP_Content.Children.Clear();
            foreach (var notification in notifications)
            {
                string thumbnailURL = notification.actor?.profile_thumbnail_url ?? "";
                if (Properties.Settings.Default.GIFProfile && notification.actor?.profile_video_url_square_small != null)
                {
                    thumbnailURL = notification.actor?.profile_video_url_square_small;
                }
                string message              = notification.message;
                string timestamp            = PostWindow.GetTimeString(notification.created_at);
                NotificationControl content = new NotificationControl();
                MainWindow.SetClickObject(content);
                content.TB_Content.Text    = message;
                content.TB_Content.ToolTip = content.TB_Content.Text;
                string contentMessage = notification.content ?? "내용 없음";
                if (contentMessage.Contains("\n"))
                {
                    contentMessage = contentMessage.Split(new string[] { "\n" }, StringSplitOptions.None)[0];
                }

                content.TB_Message.Text    = contentMessage;
                content.TB_Message.ToolTip = content.TB_Message.Text;
                if (!notification.is_new)
                {
                    content.RA_Notify.Fill = Brushes.Transparent;
                }
                if (content.TB_Message.Text.Trim().Length == 0)
                {
                    content.TB_Message.Text = "내용 없음";
                }
                content.TB_Date.Text = timestamp;
                string uri = "https://story.kakao.com/";
                GlobalHelper.AssignImage(content.IMG_Thumbnail, thumbnailURL);
                MainWindow.SetClickObject(content.IMG_Thumbnail);
                content.IMG_Thumbnail.MouseLeftButtonDown += (s, e) =>
                {
                    try
                    {
                        TimeLineWindow tlw = new TimeLineWindow(notification.actor.id);
                        tlw.Show();
                        tlw.Activate();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("접근이 불가능한 스토리입니다.");
                    }
                    e.Handled = true;
                };
                if (notification.scheme.Contains("?profile_id="))
                {
                    var ObjStr   = notification.scheme.Split(new string[] { "?profile_id=" }, StringSplitOptions.None);
                    var Profile  = ObjStr[1];
                    var Identity = ObjStr[0].Split('.')[1];
                    uri += Profile + "/" + Identity + "!" + ObjStr[0];
                    var feedID = ObjStr[0].Split(new string[] { "activities/" }, StringSplitOptions.None)[1];
                    content.MouseLeftButtonDown += async(s, e) =>
                    {
                        string target = uri.Split(new string[] { "!" }, StringSplitOptions.None)[0];
                        try
                        {
                            var post = await KakaoRequestClass.GetPost(feedID);

                            PostWindow.ShowPostWindow(post, feedID);
                        }
                        catch (Exception) { }
                        content.RA_Notify.Fill = Brushes.Transparent;
                        e.Handled = true;
                    };
                }
                else if (notification.scheme.Contains("kakaostory://profiles/"))
                {
                    content.MouseLeftButtonDown += (s, e) =>
                    {
                        try
                        {
                            string         id  = notification.scheme.Replace("kakaostory://profiles/", "");
                            TimeLineWindow tlw = new TimeLineWindow(id);
                            tlw.Show();
                            tlw.Activate();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("접근할 수 없는 스토리입니다.");
                        }
                        e.Handled = true;
                    };
                }
                SP_Content.Children.Add(content);
            }
            BT_Refresh.IsEnabled = true;
            TB_RefreshBT.Text    = "새로고침";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.Refresh;

            SV_Content.ScrollToTop();
            RA_Loading.Visibility = Visibility.Collapsed;
            PR_Loading.IsActive   = false;
        }