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)); }); }
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); }
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); }