Exemple #1
0
        public void ReportAsSpam()
        {
            var msg = new TaskDialogMessage(new TaskDialogOptions
            {
                Title                   = "ユーザーをスパムとして報告",
                MainIcon                = VistaTaskDialogIcon.Warning,
                MainInstruction         = "ユーザー " + this.Status.User.ScreenName + " をスパム報告しますか?",
                Content                 = "全てのアカウントからブロックし、代表のアカウントからスパム報告します。",
                CustomButtons           = new[] { "スパム報告", "キャンセル" },
                AllowDialogCancellation = true,
            });
            var response = this.Parent.Messenger.GetResponse(msg);

            if (response.Response.CustomButtonResult != 0)
            {
                return;
            }
            // report as a spam
            var accounts = Setting.Accounts.Collection.ToArray();
            var reporter = accounts.FirstOrDefault();

            if (reporter == null)
            {
                return;
            }
            var rreq = new UpdateRelationRequest(this.User.User, RelationKind.Block);

            accounts.ToObservable()
            .SelectMany(a =>
                        RequestQueue.Enqueue(a, rreq)
                        .Do(r => BackstageModel.RegisterEvent(
                                new BlockedEvent(a.GetPserudoUser(), this.User.User))))
            .Merge(
                RequestQueue.Enqueue(reporter,
                                     new UpdateRelationRequest(this.User.User, RelationKind.ReportAsSpam))
                .Do(r =>
                    BackstageModel.RegisterEvent(
                        new BlockedEvent(reporter.GetPserudoUser(), this.User.User))))
            .Subscribe(
                _ => { },
                ex => BackstageModel.RegisterEvent(new InternalErrorEvent(ex.Message)), () =>
            {
                var tid    = this.Status.User.Id;
                var tidstr = tid.ToString(CultureInfo.InvariantCulture);
                StatusProxy.FetchStatuses(
                    s => s.User.Id == tid ||
                    (s.RetweetedOriginal != null && s.RetweetedOriginal.User.Id == tid),
                    "UserId = " + tidstr + " OR BaseUserId = " + tidstr)
                .Subscribe(s => StatusInbox.EnqueueRemoval(s.Id));
            });
        }
Exemple #2
0
        public static async Task <TwitterStatus> GetTweetAsync(long id)
        {
            var status = await StatusProxy.GetStatusAsync(id).ConfigureAwait(false);

            if (status == null)
            {
                var acc = Setting.Accounts.GetRandomOne();
                if (acc == null)
                {
                    return(null);
                }
                status = await acc.ShowTweetAsync(id).ConfigureAwait(false);

                StatusInbox.Enqueue(status);
            }
            return(status);
        }
Exemple #3
0
        public static async Task <TwitterStatus> GetTweetAsync(long id)
        {
            var status = await StatusProxy.GetStatusAsync(id).ConfigureAwait(false);

            if (status == null)
            {
                var acc = Setting.Accounts.GetRandomOne();
                if (acc == null)
                {
                    return(null);
                }
                status = (await acc.CreateAccessor().ShowTweetAsync(id, CancellationToken.None)
                          .ConfigureAwait(false)).Result;
                StatusInbox.Enqueue(status);
            }
            return(status);
        }
Exemple #4
0
 private async Task <TwitterStatus> SendInternal(
     [NotNull] TwitterAccount account, [NotNull] RequestBase <TwitterStatus> request)
 {
     if (account == null)
     {
         throw new ArgumentNullException("account");
     }
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     return(await Task.Run(async() =>
     {
         var status = await RequestQueue.EnqueueAsync(account, request);
         StatusInbox.Enqueue(status);
         return status;
     }));
 }
            public void OnStatusActivity(StreamStatusActivity item)
            {
                switch (item.Event)
                {
                case StreamStatusActivityEvent.Unknown:
                    BackstageModel.RegisterEvent(new UnknownEvent(item.Source, item.EventRawString));
                    break;

                case StreamStatusActivityEvent.Favorite:
                    NotificationService.NotifyFavorited(item.Source, item.Status);
                    break;

                case StreamStatusActivityEvent.Unfavorite:
                    NotificationService.NotifyUnfavorited(item.Source, item.Status);
                    break;
                }
                if (item.Status != null)
                {
                    StatusInbox.Enqueue(item.Status);
                }
            }
Exemple #6
0
        public static void PostInitialize()
        {
            // initialize subsystems
            StatisticsService.Initialize();
            PostLimitPredictionService.Initialize();
            MuteBlockManager.Initialize();
            StatusBroadcaster.Initialize();
            StatusInbox.Initialize();
            AutoUpdateService.StartSchedule();
            NotificationService.Initialize();
            UINotificationProxy.Initialize();

            // activate plugins
            PluginManager.LoadedPlugins.ForEach(p => p.Initialize());

            // activate scripts
            ScriptingManagerImpl.Initialize();

            // other core systems initialize
            ReceiveManager.Initialize();
            TwitterConfigurationService.Initialize();
            BackstageModel.Initialize();
        }
Exemple #7
0
        public void Delete()
        {
            TwitterAccount info;

            if (this.IsDirectMessage)
            {
                var ids = new[] { this.Status.User.Id, this.Status.Recipient.Id };
                info = ids
                       .Select(Setting.Accounts.Get).FirstOrDefault(_ => _ != null);
            }
            else
            {
                info = Setting.Accounts.Get(this.OriginalStatus.User.Id);
            }
            if (info == null)
            {
                return;
            }
            var dreq = new DeletionRequest(this.OriginalStatus);

            RequestQueue.Enqueue(info, dreq)
            .Subscribe(_ => StatusInbox.EnqueueRemoval(_.Id),
                       ex => BackstageModel.RegisterEvent(new OperationFailedEvent("ツイートを削除できませんでした", ex)));
        }
 public void OnDeleted(StreamDelete item)
 {
     StatusInbox.EnqueueRemoval(item.Id);
 }
 public void OnStatus(TwitterStatus status)
 {
     StatusInbox.Enqueue(status);
 }
        private IStreamHandler InitializeHandler()
        {
            var handler = StreamHandler.Create(StatusInbox.Enqueue,
                                               ex =>
            {
                BehaviorLogger.Log("U/S", _account.UnreliableScreenName + ":" + ex.ToString());
                BackstageModel.RegisterEvent(new StreamDecodeFailedEvent(_account.UnreliableScreenName, ex));
            });

            handler.AddHandler <StreamDelete>(d => StatusInbox.EnqueueRemoval(d.Id));
            handler.AddHandler <StreamDisconnect>(
                d => BackstageModel.RegisterEvent(new UserStreamsDisconnectedEvent(_account, d.Reason)));
            handler.AddHandler <StreamLimit>(
                limit => NotificationService.NotifyLimitationInfoGot(_account, (int)limit.UndeliveredCount));
            handler.AddHandler <StreamStatusEvent>(s =>
            {
                switch (s.Event)
                {
                case StatusEvents.Unknown:
                    BackstageModel.RegisterEvent(new UnknownEvent(s.Source, s.RawEvent));
                    break;

                case StatusEvents.Favorite:
                    NotificationService.NotifyFavorited(s.Source, s.TargetObject);
                    break;

                case StatusEvents.Unfavorite:
                    NotificationService.NotifyUnfavorited(s.Source, s.TargetObject);
                    break;

                case StatusEvents.FavoriteRetweet:
                    NotificationService.NotifyFavorited(s.Source, s.TargetObject);
                    break;

                case StatusEvents.RetweetRetweet:
                    NotificationService.NotifyRetweeted(s.Source, s.TargetObject.RetweetedOriginal, s.TargetObject);
                    break;

                case StatusEvents.Quote:
                    // do nothing
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                if (s.TargetObject != null)
                {
                    StatusInbox.Enqueue(s.TargetObject);
                }
            });
            handler.AddHandler <StreamUserEvent>(async item =>
            {
                var active  = item.Source.Id == _account.Id;
                var passive = item.Target.Id == _account.Id;
                var reldata = _account.RelationData;
                switch (item.Event)
                {
                case UserEvents.Unknown:
                    BackstageModel.RegisterEvent(new UnknownEvent(item.Source, item.RawEvent));
                    break;

                case UserEvents.Follow:
                    if (active)
                    {
                        await reldata.Followings.SetAsync(item.Target.Id, true).ConfigureAwait(false);
                    }
                    if (passive)
                    {
                        await reldata.Followers.SetAsync(item.Source.Id, true).ConfigureAwait(false);
                    }
                    NotificationService.NotifyFollowed(item.Source, item.Target);
                    break;

                case UserEvents.Unfollow:
                    if (active)
                    {
                        await reldata.Followings.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                    }
                    if (passive)
                    {
                        await reldata.Followers.SetAsync(item.Source.Id, false).ConfigureAwait(false);
                    }
                    NotificationService.NotifyUnfollowed(item.Source, item.Target);
                    break;

                case UserEvents.Block:
                    if (active)
                    {
                        await reldata.Followings.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                        await reldata.Followers.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                        await reldata.Blockings.SetAsync(item.Target.Id, true).ConfigureAwait(false);
                    }
                    if (passive)
                    {
                        await reldata.Followers.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                    }
                    NotificationService.NotifyBlocked(item.Source, item.Target);
                    break;

                case UserEvents.Unblock:
                    if (active)
                    {
                        await reldata.Blockings.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                    }
                    NotificationService.NotifyUnblocked(item.Source, item.Target);
                    break;

                case UserEvents.UserUpdate:
                    NotificationService.NotifyUserUpdated(item.Source);
                    break;

                case UserEvents.Mute:
                    if (active)
                    {
                        await reldata.Mutes.SetAsync(item.Target.Id, true).ConfigureAwait(false);
                    }
                    NotificationService.NotifyBlocked(item.Source, item.Target);
                    break;

                case UserEvents.UnMute:
                    if (active)
                    {
                        await reldata.Mutes.SetAsync(item.Target.Id, false).ConfigureAwait(false);
                    }
                    NotificationService.NotifyUnblocked(item.Source, item.Target);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });
            return(handler);
        }