Пример #1
0
        private async void PostTweet()
        {
            Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)false), (object)ViewModelMessages.EnableReplyOptions);
            this.sendingTweetInProgress = true;
            this.PostTweetEnabled = false;
            this.TweetEntryEnabled = false;
            this.ImageUploadButtonIsEnabled = false;
            this.PostTweetProgressVisibility = Visibility.Visible;
            bool error = false;
            int numberOfStatus = 0;
            if ((this.CharCount <= SettingsData.Instance.TweetCharLimit || Enumerable.Count<ITweetService>(Enumerable.Where<ITweetService>((IEnumerable<ITweetService>)CoreServices.Instance.TweetServices, (Func<ITweetService, bool>)(x => x.OverrideTweetCharLimit))) > 0) && this.CharCount > 0)
            {
                try
                {
                    this.TweetTextCounter();
                    if (this.CurrentlySelectedImage != null && !this.TwitterImageServiceIsEnabled)
                    {
                        this.uploadImageCountDownEvent = new CountdownEvent(1);
                        this.ProcessImageUpload(this.CurrentlySelectedImage.FilePath, (Action<string>)(s =>
                        {
                            TwitViewModel temp_978 = this;
                            string temp_982 = temp_978.ActualTweetText + " " + s;
                            temp_978.ActualTweetText = temp_982;
                            this.TweetTextCounter();
                        }));
                        await Task.Run((Action)(() => this.uploadImageCountDownEvent.Wait()));
                    }
                    if (this.imageUploadsFailed)
                    {
                        await System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            SimpleErrorPrompt local_0 = new SimpleErrorPrompt()
                            {
                                DataContext = (object)new
                                {
                                    ErrorHeading = "image upload failed",
                                    ErrorText = "Image failed to upload, please try again."
                                }
                            };
                            Messenger.Default.Send<PromptMessage>(new PromptMessage()
                            {
                                IsModal = true,
                                PromptView = (FrameworkElement)local_0,
                                IsCentered = false
                            }, (object)ViewModelMessages.ShowSlidePrompt);
                        }), new object[0]);
                        error = true;
                        this.sendingTweetInProgress = false;
                        this.PostTweetEnabled = true;
                        this.TweetEntryEnabled = true;
                        this.ImageUploadButtonIsEnabled = true;
                        this.PostTweetProgressVisibility = Visibility.Collapsed;
                        return;
                    }
                    else if (this.CharCount > SettingsData.Instance.TweetCharLimit && Enumerable.Count<ITweetService>(Enumerable.Where<ITweetService>((IEnumerable<ITweetService>)CoreServices.Instance.TweetServices, (Func<ITweetService, bool>)(x => x.OverrideTweetCharLimit))) == 0)
                    {
                        await System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, (Action<MessageBoxResult>)(o => { })), (object)DialogType.TweetLength)), new object[0]);
                        error = true;
                        return;
                    }
                    else
                    {
                        TwitterResponse<Status> updateResponse = (TwitterResponse<Status>)null;
                        TwitterResponse<TwitterDirectMessage> directMessageResponse = (TwitterResponse<TwitterDirectMessage>)null;
                        Match dmMatch = (Match)null;
                        string userName = string.Empty;
                        string tweetpoststring = this.ActualTweetText;
                        if (this.newTweetType == TwitViewModel.NewTweetType.DirectMessage)
                        {
                            dmMatch = TwitViewModel.DM_EXPRESSION.Match(tweetpoststring);
                            userName = dmMatch.Groups[1].Value;
                            tweetpoststring = tweetpoststring.Replace(dmMatch.Groups[0].Value, "").Trim();
                        }
                        else
                        {
                            foreach (ITweetService tweetService in CoreServices.Instance.TweetServices)
                            {
                                if (tweetService.WantsPreCreation)
                                {
                                    PreTweetCreationResponse creationResponse = tweetService.PreTweetCreation(tweetpoststring, this.CharCount, this.ReplyToID.ToString(), this.UserName, this.newTweetType == TwitViewModel.NewTweetType.DirectMessage, App.AppState.Accounts[this.TwitterAccountID].TwitterAccountName);
                                    if (string.IsNullOrEmpty(creationResponse.Error) && !string.IsNullOrEmpty(creationResponse.TweetContent))
                                        tweetpoststring = creationResponse.TweetContent;
                                }
                            }
                        }
                        if (this.newTweetType == TwitViewModel.NewTweetType.DirectMessage)
                        {
                            if (dmMatch.Success && userName.Length > 0)
                            {
                                directMessageResponse = await DirectMessages.SendAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, userName, tweetpoststring, (OptionalProperties)null);
                                if (directMessageResponse != null && directMessageResponse.Result == RequestResult.Success)
                                {
                                    TwitterDirectMessage responseObject = directMessageResponse.ResponseObject;
                                    this.lastTweet = new UndoTweetState()
                                    {
                                        Id = responseObject.Id,
                                        LastTweetText = this.ActualTweetText,
                                        TweetType = TwitViewModel.NewTweetType.DirectMessage,
                                        UserName = this.UserName
                                    };
                                    this.CurrentTweetDocument = (FlowDocument)null;
                                    if (responseObject != null)
                                    {
                                        numberOfStatus = responseObject.Sender.NumberOfStatuses;
                                        App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterUserImage = responseObject.Sender.ProfileImageSecureLocation;
                                    }
                                }
                                else
                                {
                                    this.StatusType = -2;
                                    this.StatusText = Enumerable.First<TwitterError>(directMessageResponse.Errors).Message;
                                }
                                this.StatusLabelVisibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            switch (this.newTweetType)
                            {
                                case TwitViewModel.NewTweetType.Reply:
                                    StatusUpdateOptions statusUpdateOptons = MetroTwitTwitterizer.StatusUpdateOptions;
                                    statusUpdateOptons.InReplyToStatusId = this.ReplyToID;
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), statusUpdateOptons);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, statusUpdateOptons);
                                        break;
                                    }
                                case TwitViewModel.NewTweetType.Retweet:
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), MetroTwitTwitterizer.StatusUpdateOptions);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, MetroTwitTwitterizer.StatusUpdateOptions);
                                        break;
                                    }
                                default:
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), MetroTwitTwitterizer.StatusUpdateOptions);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, MetroTwitTwitterizer.StatusUpdateOptions);
                                        break;
                                    }
                            }
                            if (updateResponse != null && updateResponse.Result == RequestResult.Success)
                            {
                                Status responseObject = updateResponse.ResponseObject;
                                this.lastTweet = new UndoTweetState()
                                {
                                    Id = responseObject.Id,
                                    LastTweetText = this.ActualTweetText,
                                    TweetType = this.newTweetType,
                                    UserName = this.UserName,
                                    ReplyToID = this.ReplyToID
                                };
                                this.CurrentTweetDocument = (FlowDocument)null;
                                if (responseObject != null)
                                {
                                    numberOfStatus = responseObject.User.NumberOfStatuses;
                                    App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterUserImage = responseObject.User.ProfileImageSecureLocation;
                                    foreach (ITweetService tweetService in CoreServices.Instance.TweetServices)
                                    {
                                        if (tweetService.WantsPostCreation)
                                            tweetService.PostTweetCreation(responseObject.Text, this.CharCount, responseObject.InReplyToStatusId.ToString(), responseObject.InReplyToScreenName, false, App.AppState.Accounts[this.TwitterAccountID].TwitterAccountName, responseObject.Id);
                                    }

                                }
                            }
                            else
                            {
                                this.StatusType = -2;
                                this.StatusText = Enumerable.First<TwitterError>(updateResponse.Errors).Message;
                                if (this.StatusText == "Status is a duplicate.")
                                    this.StatusText = "Tweet error: tweet is a duplicate of a last tweet posted.";
                                this.StatusLabelVisibility = Visibility.Visible;
                            }
                        }
                    }
                }
                catch
                {
                    error = true;
                }
            }
            else
                error = true;
            if (!this.imageUploadsFailed && !error)
            {
                base.RaisePropertyChanged("SingleImageTypeEnabled");
                this.CurrentlySelectedImage = (SingleImageUploadRequest)null;
                this.EnableTweetArea();
                if (numberOfStatus > 0)
                {
                    this.PostTweetEnabled = false;
                    this.ResetNewTweet(true);
                    if (App.AppState.Accounts[this.TwitterAccountID].TwitterUserTweetCount != numberOfStatus.ToString() + " tweets")
                    {
                        App.AppState.Accounts[this.TwitterAccountID].TwitterUserTweetCount = numberOfStatus.ToString() + " tweets";
                        Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)this.MultiAccountifyToken((System.Enum)ViewModelMessages.ProfileUpdated));
                    }
                }
            }
            else
                this.EnableTweetArea();
        }
Пример #2
0
 public void UndoTweet(UndoTweetState state, bool undoLastTweetTriggered = false)
 {
     ProgressPromptViewModel progressPromptViewModel = new ProgressPromptViewModel
     {
         ErrorMessage = "The DeLorean is not working! Please try again.",
         ProgressText = "back to the future!...",
         Title = "undoing the tweet"
     };
     string errorTitle = "tweet could not be undone";
     Action<RequestResult> UndoCallback = result => System.Windows.Application.Current.Dispatcher.Invoke(delegate
     {
         if (result == RequestResult.Success)
         {
             this.ActualTweetText = state.LastTweetText;
             this.UserName = state.UserName;
             this.newTweetType = state.TweetType;
             this.ReplyToID = state.ReplyToID;
             Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(string.Empty), this.MultiAccountifyToken(ViewModelMessages.NewTweetEditUpdateText));
             Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(null), ViewModelMessages.UndoTweetClose);
         }
         else
         {
             progressPromptViewModel.Title = errorTitle;
             progressPromptViewModel.ShowAnimation = false;
             progressPromptViewModel.ShowErrorMessage = true;
             if (undoLastTweetTriggered)
             {
                 this.lastTweet = null;
             }
         }
     });
     Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, delegate(MessageBoxResult answer)
     {
         if (answer == MessageBoxResult.Yes)
         {
             Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>(progressPromptViewModel), DialogType.UndoTweet);
             if ((state.TweetType == NewTweetType.Normal) || (state.TweetType == NewTweetType.Reply))
             {
                 CommonCommands.DeleteTweet(state.Id, this.TwitterAccountID, UndoCallback, true);
             }
             else if (state.TweetType == NewTweetType.DirectMessage)
             {
                 CommonCommands.DeleteDirectMessage(state.Id, this.TwitterAccountID, UndoCallback, true);
             }
         }
     }), DialogType.UndoTweetConfirmation);
 }