Пример #1
0
        private static void RemoveTweetSink(AccountInfo info, long tweetId)
        {
            var tweet = ApiHelper.ExecApi(() => info.DestroyStatus(tweetId));

            if (tweet != null)
            {
                if (tweet.Id != tweetId)
                {
                    NotifyStorage.Notify("削除には成功しましたが、ツイートIDが一致しません。(" + tweetId.ToString() + " -> " + tweet.Id.ToString() + ")");
                }
                else
                {
                    if (tweet.InReplyToStatusId != 0)
                    {
                        var s = TweetStorage.Get(tweet.InReplyToStatusId);
                        if (s != null)
                        {
                            s.RemoveInReplyToThis(tweetId);
                        }
                    }
                    TweetStorage.Remove(tweetId);
                    NotifyStorage.Notify("削除しました:" + tweet.ToString());
                }
            }
            else
            {
                NotifyStorage.Notify("ツイートを削除できませんでした(@" + info.ScreenName + ")");
            }
        }
Пример #2
0
        protected override bool FilterStatus(Dulcet.Twitter.TwitterStatusBase status)
        {
            var ts = TweetStorage.Get(status.Id);

            if (ts == null)
            {
                return(false);
            }
            return(this.Range.Check(ts.FavoredUsers.Count()));
        }
Пример #3
0
        protected override bool FilterStatus(Dulcet.Twitter.TwitterStatusBase status)
        {
            var vm = TweetStorage.Get(status.Id);

            if (vm == null)
            {
                return(false);
            }
            return(vm.RetweetedUsers.Any(u => Match(u.TwitterUser.ScreenName, needle)));
        }
Пример #4
0
 private void ReturnToBox()
 {
     parent.SetOpenText(true, true);
     if (this.inReplyToId != 0 && TweetStorage.Contains(this.inReplyToId) == TweetExistState.Exists)
     {
         parent.SetInReplyTo(TweetStorage.Get(this.inReplyToId));
     }
     parent.SetText(this.body);
     parent.OverrideTarget(new[] { this.accountInfo });
     Remove();
 }
Пример #5
0
        private static void UnretweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはUnretweetできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Retweet オリジナルデータが見つかりません。");
                return;
            }

            bool success = true;

            Parallel.ForEach(infos,
                             d =>
            {
                // リツイート状態更新
                var ud = d.UserViewModel;
                if (ud != null)
                {
                    status.RegisterRetweeted(ud);
                }
                try
                {
                    unretweetInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    if (ud != null)
                    {
                        status.RemoveRetweeted(ud);
                    }
                    success = false;
                    NotifyStorage.Notify("Retweetキャンセルに失敗しました: @" + d.ScreenName);
                    if (!(ex is ApplicationException))
                    {
                        ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                  "Retweetキャンセル操作時にエラーが発生しました");
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Retweetをキャンセルしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Пример #6
0
        private static void UnfavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Unfav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RemoveFavored(ud);
                }
                try
                {
                    unfavoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RegisterFavored(ud);
                    }
                    NotifyStorage.Notify("Unfavに失敗しました: @" + d.ScreenName);
                    if (!(ex is ApplicationException))
                    {
                        ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                  "Unfav操作時にエラーが発生しました");
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Unfavしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Пример #7
0
        protected override bool FilterStatus(Dulcet.Twitter.TwitterStatusBase status)
        {
            // conversation control
            var vm = TweetStorage.Get(status.Id);

            if (status is TwitterDirectMessage)
            {
                var dm = (TwitterDirectMessage)status;
                return
                    ((dm.Sender.ScreenName.Equals(user1, StringComparison.CurrentCultureIgnoreCase) &&
                      dm.Recipient.ScreenName.Equals(user2, StringComparison.CurrentCultureIgnoreCase)) ||
                     (dm.Sender.ScreenName.Equals(user2, StringComparison.CurrentCultureIgnoreCase) &&
                      dm.Recipient.ScreenName.Equals(user1, StringComparison.CurrentCultureIgnoreCase)));
            }
            else
            {
                if (!status.User.ScreenName.Equals(user1, StringComparison.CurrentCultureIgnoreCase) &&
                    !status.User.ScreenName.Equals(user2, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(false);
                }

                // ここおかしい, @が入る
                // あとユーザー名マッチングを使えるように
                if (RegularExpressions.AtRegex.Matches(status.Text).Cast <Match>()
                    .Any(m => m.Value.Equals("@" + user1, StringComparison.CurrentCultureIgnoreCase) ||
                         m.Value.Equals("@" + user2, StringComparison.CurrentCultureIgnoreCase)))
                {
                    return(true);
                }
                if (vm != null && vm.InReplyFroms.Select(id => TweetStorage.Get(id))
                    .Where(irvm => irvm != null)
                    .Any(irvm => irvm.Status.User.ScreenName.Equals(user1, StringComparison.CurrentCultureIgnoreCase) ||
                         irvm.Status.User.ScreenName.Equals(user2, StringComparison.CurrentCultureIgnoreCase)))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #8
0
        private bool TraceId(long id)
        {
            var vm = TweetStorage.Get(id);

            if (vm == null || !vm.IsStatusInfoContains)
            {
                return(false);
            }
            if (vm.Status.Id == tracePoint)
            {
                return(true);
            }
            var ts = vm.Status as TwitterStatus;

            if (ts == null || ts.InReplyToStatusId == 0)
            {
                return(false);
            }
            else
            {
                return(TraceId(ts.InReplyToStatusId));
            }
        }
Пример #9
0
        public static void FavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Fav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RegisterFavored(ud);
                }
                try
                {
                    favoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RemoveFavored(ud);
                    }
                    if (ex is FavoriteSuspendedException && Setting.Instance.InputExperienceProperty.EnableFavoriteFallback)
                    {
                        // ふぁぼ規制 -> フォールバック
                        AccountInfo fallback = null;
                        if (!String.IsNullOrEmpty(d.AccountProperty.FallbackAccount) &&
                            (fallback = AccountStorage.Get(d.AccountProperty.FallbackAccount)) != null &&
                            !status.FavoredUsers.Contains(fallback.UserViewModel))
                        {
                            NotifyStorage.Notify("Fav fallbackします: @" + d.ScreenName + " >> @");
                            FavTweetSink(new[] { fallback }, status);
                        }
                    }
                    else
                    {
                        NotifyStorage.Notify("Favに失敗しました: @" + d.ScreenName);
                        if (!(ex is ApplicationException))
                        {
                            ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                      "Fav操作時にエラーが発生しました");
                        }
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Favしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Пример #10
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());
            }
        }