public RefreshMessage(RefreshTarget itemToRefresh)
 {
     this.ItemToRefresh = itemToRefresh;
 }
예제 #2
0
 private void RefreshTimelineAsync(RefreshTarget target)
 {
     if (!TClient.IsLogined)
     {
         // ログインしていないので再ログイン
         Login();
         return;
     }
     ThreadPool.QueueUserWorkItem(state => RefreshTimeline((RefreshTarget)state), target);
 }
예제 #3
0
 public RefreshMessage(RefreshTarget itemToRefresh)
 {
     this.ItemToRefresh = itemToRefresh;
 }
예제 #4
0
        private void RefreshTimeline(RefreshTarget target)
        {
            // タイムラインを取得
            Status[] statuses;
            Status[] notAuthorStatuses;
            var isKeyword = false;
            switch (target)
            {
                case RefreshTarget.All:
                    if (Settings.Default.UseUserStream)
                    {
                        TClient.ChirpUserStream();
                    }
                    this.AsyncInvoke(() => StatusText = "正在获取全部时间线");
                    // Recent を取得する
                    statuses = TClient.RecentTimeline;
                    // 取得できたか確認する
                    if (statuses == null)
                    {
                        SetStatusMessage(false);
                        return;
                    }
                    if (Settings.Default.IgnoreRegex != null)
                    {
                        statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
                    }
                    // ユーザーリストを更新
                    UpdateUsersList(statuses.Select(p => p.Sender).Distinct());
                    UpdateHashtagList(statuses);
                    // ステータスを反映させる

                    Timelines.Update(statuses);
                    // 返信タイムラインを反映させる
                    statuses = TClient.RepliesTimeline;
                    if (Settings.Default.IgnoreRegex != null)
                    {
                        statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
                    }
                    // ユーザーリストを更新
                    if (statuses != null)
                    {
                        UpdateUsersList(statuses.Select(p => p.Sender).Distinct());
                        UpdateHashtagList(statuses);
                    }
                    // ステータスを反映させる
                    {
                        Timelines.Update(TimelineType.Replies, statuses);
                        Timelines.Update(TimelineType.User, statuses);
                    }
                    // アーカイブを反映させる
                    statuses = TClient.ArchiveTimeline;
                    if (statuses != null)
                    {
                        if (Settings.Default.IgnoreRegex != null)
                        {
                            statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
                        }
                        UpdateHashtagList(statuses);
                    }
                    // ステータスを反映させる
                    {
                        Timelines.Update(TimelineType.Archive, statuses);
                        Timelines.Update(TimelineType.User, statuses);
                        // メッセージを受信
                        Timelines.Update(TimelineType.Message, TClient.ReceivedMessages);
                        Timelines.Update(TimelineType.Message, TClient.SentMessages);
                    }
                    // リストを取得
                    lists = TClient.Lists;
                    {
                        foreach (var timeline in Timelines.Where(p => p.Type == TimelineType.List).ToList())
                        {
                            statuses = TClient.GetListStatuses(timeline.Tag, timeline.SinceID);
                            if (statuses == null)
                            {
                                continue;
                            }
                            this.Invoke(p => timeline.Update(p), statuses);
                        }
                        foreach (var timeline in Timelines.Where(p => p.Type == TimelineType.Search).ToList())
                        {
                            statuses = TClient.Search(timeline.Tag, timeline.SinceID);
                            if (statuses == null)
                            {
                                continue;
                            }
                            this.Invoke(p => timeline.Update(p), statuses);
                        }
                    }
                    // 取得完了
                    SetStatusMessage(true);
                    return;
                case RefreshTarget.Recent:
                    this.AsyncInvoke(() => StatusText = "正在获取主时间线");
                    statuses = TClient.RecentTimeline;
                    if (Settings.Default.UseUserStream)
                    {
                        TClient.ChirpUserStream();
                    }
                    if (statuses != null)
                    {

                        statuses = Timelines.Normalize(TimelineType.Recent, statuses);
                        // ユーザーリストを更新
                        UpdateUsersList(statuses.Select(p => p.Sender).Distinct());
                        UpdateHashtagList(statuses);
                    }
                    break;
                case RefreshTarget.Replies:
                    this.AsyncInvoke(() => StatusText = "正在获取回复");
                    statuses = TClient.RepliesTimeline;
                    if (statuses != null)
                    {

                        statuses = Timelines.Normalize(TimelineType.Replies, statuses);
                        // ユーザーリストを更新
                        UpdateUsersList(statuses.Select(p => p.Sender).Distinct());
                        UpdateHashtagList(statuses);
                    }
                    break;
                case RefreshTarget.Archive:
                    this.AsyncInvoke(() => StatusText = "正在获取个人时间线");
                    statuses = TClient.ArchiveTimeline;
                    if (statuses == null)
                    {
                        SetStatusMessage(false);
                        return;
                    }

                    Timelines.Update(statuses);
                    SetStatusMessage(true);
                    return;
                case RefreshTarget.Message:
                    this.AsyncInvoke(() => StatusText = "正在获取私信");
                    var messages = TClient.ReceivedMessages;
                    if (messages == null)
                    {
                        SetStatusMessage(false);
                        return;
                    }
                    {
                        var normalized = Timelines.Normalize(messages);
                        if (normalized.Length > 0 && !_isSilentMode)
                        {
                            if (Settings.Default.EnablePopup)
                            {
                                popupWindow.Show(normalized);
                            }
                            var sound = Settings.Default.SoundBindings.Where(p => p.IsEnabled && p.Action == SoundAction.Message).FirstOrDefault();
                            if (sound != null)
                            {
                                try
                                {
                                    new SoundPlayer(sound.FileName).Play();
                                }
                                catch { }
                            }
                        }
                        Timelines.Update(TimelineType.Message, messages);
                    }
                    SetStatusMessage(true);
                    return;
                case RefreshTarget.List:
                    this.AsyncInvoke(() => StatusText = "正在获取列表");
                    {
                        var tls = Timelines.Where(p => p.Type == TimelineType.List).ToArray();
                        foreach (var timeline in tls)
                        {
                            statuses = TClient.GetListStatuses(timeline.Tag, timeline.SinceID);
                            if (statuses == null)
                            {
                                SetStatusMessage(false);
                                continue;
                            }
                            statuses = timeline.Normalize(statuses);
                            if (Settings.Default.EnableUnreadManager)
                            {
                                Array.ForEach(statuses, item => item.IsNewest = !item.IsAuthor);
                            }
                            if (Settings.Default.IgnoreRegex != null)
                            {
                                statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
                            }
                            notAuthorStatuses = Timelines.TypeAt(TimelineType.Recent).Normalize(statuses.Where(p => !p.IsAuthor));
                            if (notAuthorStatuses.Length > 0 && !_isSilentMode)
                            {
                                if (Settings.Default.EnablePopup)
                                {
                                    if (!Settings.Default.PopupOnlyNotActive || this.Invoke<bool>(() => !IsActive))
                                    {
                                        if (Settings.Default.PopupOnlyFavorite)
                                        {
                                            if (Settings.Default.FavoriteRegex != null)
                                            {
                                                popupWindow.Show(notAuthorStatuses.Where(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)));
                                            }
                                        }
                                        else
                                        {
                                            popupWindow.Show(notAuthorStatuses);
                                        }
                                    }
                                }
                                var action = notAuthorStatuses.Any(p => Regex.IsMatch(p.Text, string.Format(@"{0}[^a-zA-Z_0-9]", TClient.LoginedUser.ScreenName))) ? SoundAction.Reply : SoundAction.Status;
                                var sound = Settings.Default.SoundBindings.Where(p => p.IsEnabled && p.Action == action).FirstOrDefault();
                                if (Settings.Default.FavoriteRegex != null && notAuthorStatuses.Any(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)))
                                {
                                    isKeyword = true;
                                }
                            }
                            var recent = Timelines.TypeAt(TimelineType.Recent);
                            for (int i = 0; i < statuses.Length; ++i)
                            {
                                var item = statuses[i];

                                var status = (Status)recent.Items.FirstOrDefault(p => p.ID == item.ID);

                                if (status != null)
                                {
                                    statuses[i] = status;
                                }
                            }
                            this.Invoke(p => timeline.Update(p), statuses);
                        }
                        if (isKeyword)
                        {
                            var keywordSound = Settings.Default.SoundBindings.FirstOrDefault(p => p.IsEnabled && p.Action == SoundAction.Keyword);

                            if (keywordSound != null)
                            {
                                try
                                {
                                    new SoundPlayer(keywordSound.FileName).Play();
                                }
                                catch { }
                            }
                        }
                    }
                    SetStatusMessage(true);
                    return;
                case RefreshTarget.Search:
                    this.AsyncInvoke(() => StatusText = "正在获取搜索结果");
                    {
                        var stls = Timelines.Where(p => p.Type == TimelineType.Search).ToArray();
                        foreach (var timeline in stls)
                        {
                            statuses = TClient.Search(timeline.Tag, timeline.SinceID);
                            if (statuses == null)
                            {
                                SetStatusMessage(false);
                                continue;
                            }
                            statuses = timeline.Normalize(statuses);
                            if (Settings.Default.EnableUnreadManager)
                            {
                                Array.ForEach(statuses, item => item.IsNewest = !item.IsAuthor);
                            }
                            if (Settings.Default.IgnoreRegex != null)
                            {
                                statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
                            }
                            notAuthorStatuses = Timelines.TypeAt(TimelineType.Recent).Normalize(statuses.Where(p => !p.IsAuthor));
                            if (notAuthorStatuses.Length > 0 && !_isSilentMode)
                            {
                                if (Settings.Default.EnablePopup)
                                {
                                    if (!Settings.Default.PopupOnlyNotActive || this.Invoke<bool>(() => !IsActive))
                                    {
                                        if (Settings.Default.PopupOnlyFavorite)
                                        {
                                            if (Settings.Default.FavoriteRegex != null)
                                            {
                                                popupWindow.Show(notAuthorStatuses.Where(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)));
                                            }
                                        }
                                        else
                                        {
                                            popupWindow.Show(notAuthorStatuses);
                                        }
                                    }
                                }
                                var action = notAuthorStatuses.Any(p => Regex.IsMatch(p.Text, string.Format(@"{0}[^a-zA-Z_0-9]", TClient.LoginedUser.ScreenName))) ? SoundAction.Reply : SoundAction.Status;
                                var sound = Settings.Default.SoundBindings.Where(p => p.IsEnabled && p.Action == action).FirstOrDefault();
                                if (Settings.Default.FavoriteRegex != null && notAuthorStatuses.Any(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)))
                                {
                                    isKeyword = true;
                                }
                            }
                            var recent = Timelines.TypeAt(TimelineType.Recent);
                            for (int i = 0; i < statuses.Length; ++i)
                            {
                                var item = statuses[i];

                                var status = (Status)recent.Items.FirstOrDefault(p => p.ID == item.ID);

                                if (status != null)
                                {
                                    statuses[i] = status;
                                }
                            }
                            this.Invoke(p => timeline.Update(p), statuses);
                        }
                        if (isKeyword)
                        {
                            var keywordSound = Settings.Default.SoundBindings.FirstOrDefault(p => p.IsEnabled && p.Action == SoundAction.Keyword);

                            if (keywordSound != null)
                            {
                                try
                                {
                                    new SoundPlayer(keywordSound.FileName).Play();
                                }
                                catch { }
                            }
                        }
                    }
                    SetStatusMessage(true);
                    return;
                default:
                    return;
            }
            // 取得できたか確認する
            if (statuses == null)
            {
                SetStatusMessage(false);
                return;
            }
            if (Settings.Default.EnableUnreadManager)
            {
                Array.ForEach(statuses, item => item.IsNewest = !item.IsAuthor);
            }
            if (Settings.Default.IgnoreRegex != null)
            {
                statuses = statuses.Where(p => !Settings.Default.IgnoreRegex.IsMatch(p.Text)).ToArray();
            }
            notAuthorStatuses = statuses.Where(p => !p.IsAuthor).ToArray();
            if (notAuthorStatuses.Length > 0 && !_isSilentMode)
            {
                if (Settings.Default.EnablePopup)
                {
                    if (!Settings.Default.PopupOnlyNotActive || this.Invoke<bool>(() => !IsActive))
                    {
                        if (Settings.Default.PopupOnlyFavorite)
                        {
                            if (Settings.Default.FavoriteRegex != null)
                            {
                                popupWindow.Show(notAuthorStatuses.Where(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)));
                            }
                        }
                        else
                        {
                            popupWindow.Show(notAuthorStatuses);
                        }
                    }
                }
                var action = notAuthorStatuses.Any(p => Regex.IsMatch(p.Text, string.Format(@"{0}[^a-zA-Z_0-9]", TClient.LoginedUser.ScreenName))) ? SoundAction.Reply : SoundAction.Status;
                var sound = Settings.Default.SoundBindings.Where(p => p.IsEnabled && p.Action == action).FirstOrDefault();
                if (Settings.Default.FavoriteRegex != null && notAuthorStatuses.Any(p => Settings.Default.FavoriteRegex.IsMatch(p.Text)))
                {
                    var keywordSound = Settings.Default.SoundBindings.FirstOrDefault(p => p.IsEnabled && p.Action == SoundAction.Keyword);

                    if (keywordSound != null)
                    {
                        sound = keywordSound;
                    }
                }
                if (sound != null)
                {
                    try
                    {
                        new SoundPlayer(sound.FileName).Play();
                    }
                    catch { }
                }
            }
            this.Invoke(() =>
            {
                if (TimelineTabControl.SelectedItem != null)
                {
                    ((Timeline)TimelineTabControl.SelectedItem).VerticalOffset = _mainViewer.VerticalOffset;
                }
            });

            Timelines.Update(statuses);
            this.AsyncInvoke(() =>
            {
                if (TimelineTabControl.SelectedItem != null)
                {
                    _mainViewer.ScrollToVerticalOffset(((Timeline)TimelineTabControl.SelectedItem).VerticalOffset);
                }
            });
            // 更新完了
            SetStatusMessage(true);
        }