コード例 #1
0
        public override async Task <TwitterStatus> Send(TwitterAccount account)
        {
            // ReSharper disable RedundantIfElseBlock
            if (_createRetweet)
            {
                Exception thrown;
                // make retweet
                var acc = account;
                do
                {
                    try
                    {
                        var result = await acc.RetweetAsync(_id);

                        BackstageModel.NotifyFallbackState(acc, false);
                        return(result);
                    }
                    catch (TwitterApiException tae)
                    {
                        thrown = tae;
                        if (tae.Message.Contains(LimitMessage))
                        {
                            BackstageModel.NotifyFallbackState(acc, true);
                            if (acc.FallbackAccountId != null)
                            {
                                // reached post limit, fallback
                                var prev = acc;
                                acc = Setting.Accounts.Get(acc.FallbackAccountId.Value);
                                BackstageModel.RegisterEvent(new FallbackedEvent(prev, acc));
                                continue;
                            }
                        }
                    }
                    var id = await acc.GetMyRetweetIdOfStatusAsync(_id);

                    if (id.HasValue)
                    {
                        // already retweeted.
                        return(null);
                    }
                    throw thrown;
                } while (acc != null && acc.Id != account.Id);
                throw thrown;
            }
            else
            {
                // get retweet id
                var id = await account.GetMyRetweetIdOfStatusAsync(_id);

                if (!id.HasValue)
                {
                    // retweet is not existed.
                    return(null);
                }
                // destroy retweet
                return(await account.DestroyAsync(id.Value));
            }
            // ReSharper restore RedundantIfElseBlock
        }