public NewStatusViewModel(ComposerViewModel owner, NewStatus status)
		{
			this.owner = owner;
			this.NewStatus = status;

			this.Media = ViewModelHelper.CreateReadOnlyDispatcherCollection(
				status.MediaPaths,
				path => new MediaViewModel(path, () => status.MediaPaths.Remove(path)),
				App.Current.Dispatcher);

			this.CompositeDisposable.Add(this.Media);
			this.CompositeDisposable.Add(new PropertyChangedEventListener(status)
			{
				(sender, e) => this.RaisePropertyChanged(e.PropertyName),
				{ "Exception", (sender, e) => this.RaisePropertyChanged("ErrorMessage") },
			});

			this.CompositeDisposable.Add(new EventListener<EventHandler<CaretIndexChangeRequestedEventArgs>>(
				h => this.NewStatus.CaretIndexChangeRequested += h,
				h => this.NewStatus.CaretIndexChangeRequested -= h,
				(sender, e) => this.Messenger.Raise(new SetCaretMessage("SetCaretIndex") { CaretIndex = e.CaretIndex })));

			this.CompositeDisposable.Add(new EventListener<EventHandler<TextSelectionRequestedEventArgs>>(
				h => this.NewStatus.TextSelectionRequested += h,
				h => this.NewStatus.TextSelectionRequested -= h,
				(sender, e) => this.Messenger.Raise(new SelectTextMessage("SelectText") { Start = e.Start, Length = e.Length })));
		}
		/// <summary>
		/// ツイートを投稿します。
		/// </summary>
		public static Task<Status> UpdateStatus(this TwitterToken token, NewStatus status)
		{
			return status.MediaPaths.HasValue()
				? token.UpdateStatus(status.TextWithFooter, status.MediaPaths.ToArray(), status.InReplyTo == null ? null : new StatusId?(status.InReplyTo.Id))
				: token.UpdateStatus(status.TextWithFooter, status.InReplyTo == null ? null : new StatusId?(status.InReplyTo.Id));
		}
Example #3
0
		/// <summary>
		/// 指定したツイートを投稿します。
		/// </summary>
		public async void Update(NewStatus status)
		{
			if (!status.CanUpdate) return;

			if(!this.NewStatuses.Contains(status)) this.NewStatuses.Add(status);
			
			try
			{
				status.IsUpdating = true;
				status.Exception = null;
				await status.Account.CurrentToken.UpdateStatus(status);
			}
			catch (Exception ex)
			{
				ex.Write();

				// 投稿に失敗した場合、例外情報を持たせる
				status.Exception = ex;
				return;
			}
			finally
			{
				status.IsUpdating = false;
			}

			// 投稿に成功した場合、キューから削除し、インスタンス破棄
			this.NewStatuses.Remove(status);
			status.Dispose();
		}