Пример #1
0
 private void RemoveOldTweets()
 {
     Task.Factory.StartNew(() =>
     {
         TweetStorage.GetAll(tvm => (DateTime.Now - tvm.CreatedAt).TotalHours > 12)
         .ForEach(t => TweetStorage.Remove(t.bindingId));
     });
 }
Пример #2
0
        private static void AddUnderControlled(AccountInfo info)
        {
            if (underControls.ContainsKey(info))
            {
                NotifyStorage.Notify("[規制管理: @" + info.ScreenName + " は規制されています。解除予想時刻: " + underControls[info].ToString("HH:mm:ss"));
                return;
            }

            var timestamp = DateTime.Now.Subtract(TwitterDefine.UnderControlTimespan);

            // APIを利用してツイートを遡り受信
            var notify = NotifyStorage.NotifyManually("[規制管理: @" + info.ScreenName + " の直近のツイートを受信しています...]");

            try
            {
                ApiHelper.ExecApi(() => info.GetUserTimeline(count: 150, includeRts: true))
                .Guard()
                .ForEach(i => TweetStorage.Register(i));

                notify.Message = "[規制管理:規制開始時刻を割り出しています...]";

                // 127tweet/3hours
                var originate = TweetStorage.GetAll(
                    t => t.Status.User.ScreenName == info.ScreenName && DateTime.Now.Subtract(t.CreatedAt) < TwitterDefine.UnderControlTimespan)
                                .OrderByDescending((t) => t.Status.CreatedAt)
                                .Skip(TwitterDefine.UnderControlCount - 1)
                                .FirstOrDefault();

                if (originate == null)
                {
                    originate = TweetStorage.GetAll(
                        t => t.Status.User.ScreenName == info.ScreenName && DateTime.Now.Subtract(t.CreatedAt) < TwitterDefine.UnderControlTimespan)
                                .OrderByDescending((t) => t.Status.CreatedAt)
                                .LastOrDefault();
                }

                if (originate == null)
                {
                    NotifyStorage.Notify("[規制管理: @" + info.ScreenName + " はPOST規制されていますが、解除時刻を予想できません。しばらく置いて試してみてください。]");
                }
                else
                {
                    var release = (originate.Status.CreatedAt + TwitterDefine.UnderControlTimespan);
                    NotifyStorage.Notify("[規制管理: @" + info.ScreenName +
                                         " はPOST規制されています。解除予想時刻は " + release.ToString("HH:mm:ss") + " です。]");
                    underControls.AddOrUpdate(info, release);
                    OnOnUnderControlChanged(new UnderControlEventArgs(info, true));
                }
            }
            finally
            {
                notify.Dispose();
            }
        }
Пример #3
0
        private static void TweetSpeedUpdateSink(object o)
        {
            // 鳥人
            var morigin = (DateTime.Now - new TimeSpan(0, 1, 0));

            TweetSpeedPerMin = TweetStorage.GetAll((t) => t.CreatedAt > morigin).Count();
            var horigin = (DateTime.Now - new TimeSpan(1, 0, 0));

            TweetSpeedPerHour = TweetStorage.GetAll((t) => t.CreatedAt > horigin).Count();
            System.Diagnostics.Debug.WriteLine(morigin.ToString() + " / " + horigin.ToString());
            OnTweetSpeedUpdated(EventArgs.Empty);
        }
Пример #4
0
        private string Uniquify(String body)
        {
            var tweets = TweetStorage.GetAll(vm => vm.Status.User.ScreenName == accountInfo.ScreenName)
                         .OrderByDescending(t => t.CreatedAt)
                         .Take(10)
                         .ToArray();

            while (tweets.Any(t => t.Text == body) && body.Length < TwitterDefine.TweetMaxLength)
            {
                body += "‍";//ZWJ
            }
            return(body);
        }
Пример #5
0
        private static void RemoveRetweetCore(AccountInfo d, TweetViewModel status)
        {
            // リツイートステータスの特定
            var rts = TweetStorage.GetAll(vm =>
                                          vm.Status.User.ScreenName == d.ScreenName && vm.Status is TwitterStatus &&
                                          ((TwitterStatus)vm.Status).RetweetedOriginal != null &&
                                          ((TwitterStatus)vm.Status).RetweetedOriginal.Id == status.Status.Id).FirstOrDefault();

            if (rts == null || ApiHelper.ExecApi(() => d.DestroyStatus(rts.Status.Id) == null))
            {
                throw new ApplicationException();
            }
        }
Пример #6
0
        public void InvalidateCache()
        {
            if (DispatcherHelper.UIDispatcher.CheckAccess())
            {
                // ディスパッチャ スレッドではInvalidateCacheを行わない
                throw new InvalidOperationException("Can't invalidate cache on the Dispatcher thread.");
            }

            this._tweetsSource.Clear();
            TweetStorage.GetAll(vm => CheckFilters(vm))
            .Select(tvm => new TabDependentTweetViewModel(tvm, this.Parent))
            .Block(TwitterDefine.TimelineDispatchBlockCount)
            .ForEach(t => this._tweetsSource.AddRangeVolatile(t));
            this.Commit();
        }
Пример #7
0
 public static bool IsMentionedThis(TweetViewModel tweetViewModel)
 {
     return(TweetStorage.GetAll(t => TwitterHelper.IsMyTweet(t))
            .OfType <TwitterStatus>()
            .Any(t => t.InReplyToStatusId == tweetViewModel.bindingId));
 }
Пример #8
0
        public static Tuple <DateTime, int> GetUnderControlChunk(AccountInfo info)
        {
            // based on http://ltzz.info/alpha/twitter_kisei.html
            // セクション(Under control chunk)を導出する

            // とりあえずこのユーザーの全ツイートを持ってくる
            // 投稿時間配列にする
            var times = TweetStorage.GetAll(t => t.Status.User.ScreenName == info.ScreenName)
                        .Select(t => t.Status.CreatedAt)
                        .OrderByDescending(t => t) // 新着順に並べる
                        .ToArray();

            // 全ツイートのうち、3時間以上の投稿の空きがある部分を調べる
            int initPoint = -1;

            for (int i = 0; i < times.Length; i++)
            {
                // 前のツイートまで、3時間以上の空きがあるとそこがチャンクの切れ目
                if (i + 1 < times.Length &&
                    times[i] - times[i + 1] > TwitterDefine.UnderControlTimespan)
                {
                    // ここがチャンクの切れ目
                    initPoint = i;
                    break;
                }
                else if (i + TwitterDefine.UnderControlCount < times.Length &&
                         times[i + 1] - times[i + TwitterDefine.UnderControlCount] <
                         TwitterDefine.UnderControlTimespan)
                {
                    // UnderControlTimespanの期間中、UnderControlCountを超える投稿がある
                    // →チャンクの切れ目
                    initPoint = i;
                    break;
                }
            }

            while (initPoint >= 0 &&
                   DateTime.Now.Subtract(times[initPoint]) > TwitterDefine.UnderControlTimespan)
            {
                // 導出したチャンクから現在消費中のチャンクを推測する
                // チャンクのスタートポイントがチャンク時間内でない場合、チャンク時間後のツイートを順番に辿る
                var  chunkEnd = times[initPoint] + TwitterDefine.UnderControlTimespan;
                bool found    = false;
                for (int i = initPoint; i >= 0; i--)
                {
                    if (times[initPoint] >= chunkEnd)
                    {
                        initPoint = i;
                        found     = true;
                        break;
                    }
                }
                // チャンクの導出ができないとは何事だ
                if (!found)
                {
                    initPoint = -1;
                }
            }

            if (initPoint >= 0)
            {
                // 結局チャンクの導出がしっかりできた
                return(new Tuple <DateTime, int>(times[initPoint].Add(TwitterDefine.UnderControlTimespan), initPoint));
            }
            else
            {
                // なんかだめだった
                // 規制開始ポイントが分からないので、とりあえずウィンドウタイムだけ遡る
                var window = times.Where(d => d > DateTime.Now.Subtract(TwitterDefine.UnderControlTimespan))
                             .OrderBy(d => d);
                var initt = window.FirstOrDefault();
                if (initt != null)
                {
                    return(new Tuple <DateTime, int>(initt.Add(TwitterDefine.UnderControlTimespan),
                                                     window.Count()));
                }
                else
                {
                    return(new Tuple <DateTime, int>(DateTime.MinValue, 0));
                }
            }
        }
Пример #9
0
        private void RecursiveCheckId(long id)
        {
            if (id == 0)
            {
                RaiseRequireReaccept();
                return;
            }
            var cont = TweetStorage.Contains(id);

            if (cont == TweetExistState.Exists)
            {
                // データをチェックして、先があれば再帰
                var tweet = TweetStorage.Get(id);
                if (tweet == null)
                {
                    RaiseRequireReaccept();
                    return;
                }
                var ts = tweet.Status as TwitterStatus;
                if (ts != null && ts.InReplyToStatusId != 0)
                {
                    this.tracePoint = ts.InReplyToStatusId;
                    RaisePartialRequireReaccept(ts);
                    RecursiveCheckId(ts.InReplyToStatusId);
                    tweet.RefreshInReplyToInfo(); // 返信情報の更新を通知
                }
                else
                {
                    RaiseRequireReaccept();
                }
            }
            else if (cont == TweetExistState.ServerDeleted)
            {
                // 消されてるからダメ
                RaiseRequireReaccept();
                return;
            }
            else
            {
                // tweetを受信しようか
                Action receive = null;
                receive = () =>
                {
                    try
                    {
                        var status = ApiHelper.ExecApi(() => AccountStorage.GetRandom().GetStatus(id));
                        if (status != null)
                        {
                            var vm = TweetStorage.Register(status);
                            this.tracePoint = status.Id; // temporarily id
                            Task.Factory.StartNew(() => RecursiveCheckId(status.Id));
                            Task.Factory.StartNew(() =>
                                                  TweetStorage.GetAll(tvm => (tvm.Status is TwitterStatus) && ((TwitterStatus)tvm.Status).InReplyToStatusId == id)
                                                  .ForEach(tvm => tvm.RefreshInReplyToInfo()));
                        }
                        else
                        {
                            RaiseRequireReaccept();
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ツイート " + id + " の受信に失敗しました。", receive);
                        RaiseRequireReaccept();
                    }
                };
                Task.Factory.StartNew(() => receive());
            }
        }