示例#1
0
        private void CreateButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ITwitterService srv = ServiceDispatcher.GetService(DataTransfer.CurrentAccount);
            TwitterListMode mode;

            if (PublicBtn.IsChecked == true)
            {
                mode = TwitterListMode.Public;
            }
            else
            {
                mode = TwitterListMode.Private;
            }
            Dispatcher.BeginInvoke(() => pBar.IsVisible = true);
            srv.CreateList(new CreateListOptions {
                ListOwner = DataTransfer.CurrentAccount.ScreenName, Name = ListName.Text, Description = ListDescp.Text, Mode = mode
            }, (list, response) =>
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show(Localization.Resources.ListCreated);
                        NavigationService.GoBack();
                    });
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show(Localization.Resources.ErrorCreatingList));
                }

                Dispatcher.BeginInvoke(() => pBar.IsVisible = false);
            });
        }
示例#2
0
        public void OnLoad()
        {
            lastCheckTime = DateSync.GetLastCheckDate();

            var mentionOptions = new ListTweetsMentioningMeOptions
            {
                Count = 20,
            };

            var dmOption = new ListDirectMessagesReceivedOptions
            {
                Count = 20,
            };

            foreach (var account in Config.Accounts)
            {
                if (account.Preferences.MentionsPreferences != Library.Notifications.NotificationType.None)
                {
                    IsLoading = true;
                    Interlocked.Increment(ref requestsPending);
                    ServiceDispatcher.GetService(account).ListTweetsMentioningMe(mentionOptions, (t, r) => FilterAndAddStatuses(t.Cast <ITweetable>(), r)); // Ugh.
                }
                if (account.Preferences.MessagesPreferences != Library.Notifications.NotificationType.None)
                {
                    IsLoading = true;
                    Interlocked.Increment(ref requestsPending);
                    ServiceDispatcher.GetService(account).ListDirectMessagesReceived(dmOption, (t, r) => FilterAndAddStatuses(t.Cast <ITweetable>(), r));
                }
            }
#if WP8
            this.LoadFinished += (s, e) => SpeakNotifications();
#endif
        }
示例#3
0
        void GetLists()
        {
            List <TwitterResource> userLists;

            lock (listCacheSync)
                userLists = listsCache.Where(x => x.User == user).ToList();

            if (userLists.Count > 0)
            {
                lock (resourcesSync)
                    foreach (var item in userLists.Except(Resources))
                    {
                        Resources.Add(item);
                    }
            }
            else
            {
                var service = ServiceDispatcher.GetService(user);

                loading += 2;
                service.ListListsFor(new ListListsForOptions {
                    ScreenName = user.ScreenName
                }, ReceiveLists);
                service.ListSubscriptions(new ListSubscriptionsOptions {
                    ScreenName = user.ScreenName
                }, ReceiveLists);
            }
        }
示例#4
0
        void ChooserCompleted(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK)
            {
                return;
            }

            IsLoading = true;
            BarText   = Resources.UploadingPicture;

            TwitterService srv = ServiceDispatcher.GetService(DataTransfer.CurrentAccount) as TwitterService;

            if (srv == null)
            {
                return; // Dirty trick: it will never be null if we're not testing.
            }
            RestRequest req    = srv.PrepareEchoRequest();
            RestClient  client = new RestClient {
                Authority = "http://api.twitpic.com/", VersionPath = "1"
            };

            req.AddFile("media", e.OriginalFileName, e.ChosenPhoto);
            req.AddField("key", "1abb1622666934158f4c2047f0822d0a");
            req.AddField("message", TweetText);
            req.AddField("consumer_token", Ocell.Library.SensitiveData.ConsumerToken);
            req.AddField("consumer_secret", SensitiveData.ConsumerSecret);
            req.AddField("oauth_token", DataTransfer.CurrentAccount.Key);
            req.AddField("oauth_secret", DataTransfer.CurrentAccount.Secret);
            req.Path = "upload.xml";
            //req.Method = Hammock.Web.WebMethod.Post;

            client.BeginRequest(req, (RestCallback)uploadCompleted);
        }
示例#5
0
 public void Execute(object parameter)
 {
     Dependency.Resolve <IMessageService>().SetLoadingBar(true);
     ServiceDispatcher.GetService(DataTransfer.CurrentAccount).Retweet(new RetweetOptions {
         Id = ((ITweetable)parameter).Id
     }, (sts, resp) =>
     {
         Dependency.Resolve <IMessageService>().ShowLightNotification(Resources.Retweeted);
     });
 }
示例#6
0
        void ListManager_Loaded(object sender, RoutedEventArgs e)
        {
            if (!NavigationContext.QueryString.TryGetValue("user", out _userName))
            {
                NavigationService.GoBack();
                return;
            }

            _srv = ServiceDispatcher.GetService(DataTransfer.CurrentAccount);

            LoadListsIn();
            LoadUserLists();
        }
示例#7
0
        void ReceiveTLResponse(TwitlongerPost post, TwitlongerResponse response)
        {
            if (response.StatusCode != HttpStatusCode.OK || post == null || post.Post == null || string.IsNullOrEmpty(post.Post.Content) || response.Sender == null)
            {
                IsLoading = false;
                MessageService.ShowError(Resources.ErrorCreatingTwitlonger);
                return;
            }

            BarText = Resources.SendingTweet;

            string name = response.Sender.Username;

            var account = Config.Accounts.FirstOrDefault(x => x.ScreenName == name);

            if (account == null)
            {
                IsLoading = false;
                MessageService.ShowError(Resources.ErrorCreatingTwitlonger);
                return;
            }

            try
            {
                lock (dicLock)
                    TwitlongerIds.Add(name, post.Post.Id);
            }
            catch
            {
                // TODO: Sometimes, this gives a weird OutOfRange exception. Don't know why, investigate it.
            }

            if (IsGeotagged)
            {
                var location = geoWatcher.Position.Location;
                ServiceDispatcher.GetService(account).SendTweet(new SendTweetOptions
                {
                    Status            = post.Post.Content,
                    InReplyToStatusId = DataTransfer.ReplyId,
                    Lat  = location.Latitude,
                    Long = location.Longitude
                }, ReceiveResponse);
            }
            else
            {
                ServiceDispatcher.GetService(account).SendTweet(new SendTweetOptions {
                    Status = post.Post.Content, InReplyToStatusId = DataTransfer.ReplyId
                }, ReceiveResponse);
            }
        }
示例#8
0
        void task_Completed(object sender, PhotoResult e)
        {
            UserToken usr;

            usr = Config.Accounts.FirstOrDefault(item => item != null && item.ScreenName == User.ScreenName);
            if (e.TaskResult == TaskResult.OK && User != null)
            {
                BarText   = Resources.UploadingPicture;
                IsLoading = true;
                ITwitterService srv = ServiceDispatcher.GetService(usr);
                srv.UpdateProfileImage(new UpdateProfileImageOptions {
                    ImagePath = e.OriginalFileName
                }, ReceivePhotoUpload);
            }
        }
示例#9
0
        private void LoadLists()
        {
            var service = ServiceDispatcher.GetService(DataTransfer.CurrentAccount);

            IsLoading = true;
            BarText   = Localization.Resources.LoadingLists;

            loading = 2;
            service.ListListsFor(new ListListsForOptions {
                ScreenName = DataTransfer.CurrentAccount.ScreenName
            }, ReceiveLists);
            service.ListSubscriptions(new ListSubscriptionsOptions {
                ScreenName = DataTransfer.CurrentAccount.ScreenName
            }, ReceiveLists);
        }
示例#10
0
        void ReceiveUsers(IEnumerable <TwitterUser> users, TwitterResponse response)
        {
            BarText   = "";
            IsLoading = false;
            if (response.StatusCode != HttpStatusCode.OK || !users.Any())
            {
                MessageService.ShowError(Resources.CouldntFindUser);
                return;
            }

            User = users.First();

            if (User.ProfileImageUrl != null)
            {
                Avatar = User.ProfileImageUrl.Replace("_normal", "");
            }

            Name           = User.Name;
            ScreenName     = User.ScreenName;
            Website        = User.Url;
            Biography      = User.Description;
            Tweets         = User.StatusesCount.ToString();
            Followers      = User.FollowersCount.ToString();
            Following      = User.FriendsCount.ToString();
            WebsiteEnabled = Uri.IsWellFormedUriString(User.Url, UriKind.Absolute);
            IsOwner        = Config.Accounts.Any(item => item.Id == User.Id);

            if (DataTransfer.CurrentAccount != null)
            {
                var service = ServiceDispatcher.GetService(DataTransfer.CurrentAccount);
                service.GetFriendshipInfo(new GetFriendshipInfoOptions {
                    SourceScreenName = DataTransfer.CurrentAccount.ScreenName, TargetScreenName = User.ScreenName
                }, ReceiveFriendshipInfo);
                service.ListBlockedUserIds(new ListBlockedUserIdsOptions {
                    Cursor = -1
                }, ReceiveBlockedUsers);
            }

            followUser.RaiseCanExecuteChanged();
            unfollowUser.RaiseCanExecuteChanged();
            block.RaiseCanExecuteChanged();
            unblock.RaiseCanExecuteChanged();
            pinUser.RaiseCanExecuteChanged();
            reportSpam.RaiseCanExecuteChanged();
            manageLists.RaiseCanExecuteChanged();
            changeAvatar.RaiseCanExecuteChanged();
        }
示例#11
0
        private void UnsafeExecute()
        {
            PendingCalls = 0;
            foreach (var user in Task.Accounts)
            {
#if BACKGROUND_AGENT
                ITwitterService service = new TwitterService(SensitiveData.ConsumerToken, SensitiveData.ConsumerSecret,
                                                             user.Key, user.Secret);
#else
                ITwitterService service = ServiceDispatcher.GetService(user);
#endif
                service.SendTweet(new SendTweetOptions {
                    Status = Task.Text, InReplyToStatusId = Task.InReplyTo
                }, ReceiveResponse);
                PendingCalls++;
            }
            if (PendingCalls == 0 && Completed != null)
            {
                Completed(this, new EventArgs());
            }
        }
示例#12
0
        void GetSearches()
        {
            List <TwitterResource> userSearches;

            lock (listCacheSync)
                userSearches = searchesCache.Where(x => x.User == user).ToList();

            if (userSearches.Count > 0)
            {
                lock (resourcesSync)
                    foreach (var item in userSearches.Except(Resources))
                    {
                        Resources.Add(item);
                    }
            }
            else
            {
                var service = ServiceDispatcher.GetService(user);

                loading++;
                service.ListSavedSearches(ReceiveSearches);
            }
        }
示例#13
0
        public void Execute(object parameter)
        {
            TwitterStatus param = (TwitterStatus)parameter;

            if (param.IsFavorited)
            {
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).UnfavoriteTweet(new UnfavoriteTweetOptions {
                    Id = param.Id
                }, (sts, resp) =>
                {
                    Dependency.Resolve <IMessageService>().ShowLightNotification(Resources.Unfavorited);
                });
            }
            else
            {
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).FavoriteTweet(new FavoriteTweetOptions {
                    Id = param.Id
                }, (sts, resp) =>
                {
                    Dependency.Resolve <IMessageService>().ShowLightNotification(Resources.Favorited);
                });
            }
        }
示例#14
0
        public UserModel()
            : base("User")
        {
            User = null;
            GenericCanExecute = (obj) => User != null && DataTransfer.CurrentAccount != null;

            followUser = new DelegateCommand((obj) =>
            {
                IsLoading = true;
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).FollowUser(new FollowUserOptions {
                    UserId = User.Id
                }, ReceiveFollow);
            }, x => FriendshipRetrieved && GenericCanExecute.Invoke(null));

            unfollowUser = new DelegateCommand((obj) =>
            {
                IsLoading = true;
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).UnfollowUser(new UnfollowUserOptions {
                    UserId = User.Id
                }, ReceiveFollow);
            }, x => FriendshipRetrieved && GenericCanExecute.Invoke(null));

            pinUser = new DelegateCommand((obj) =>
            {
                Config.Columns.Add(new TwitterResource
                {
                    Data = User.ScreenName,
                    Type = ResourceType.Tweets,
                    User = DataTransfer.CurrentAccount
                });
                Config.SaveColumns();
                MessageService.ShowLightNotification(Resources.UserPinned);
                pinUser.RaiseCanExecuteChanged();
            }, item => GenericCanExecute.Invoke(null) &&
                                          !Config.Columns.Any(o => o.Type == ResourceType.Tweets && o.Data == User.ScreenName));

            block = new DelegateCommand((obj) =>
            {
                IsLoading = true;
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).BlockUser(new BlockUserOptions {
                    UserId = User.Id
                }, ReceiveBlock);
            }, obj => GenericCanExecute(obj) && DataTransfer.CurrentAccount.ScreenName != User.ScreenName);

            unblock = new DelegateCommand((obj) =>
            {
                IsLoading = true;
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).UnblockUser(new UnblockUserOptions {
                    UserId = User.Id
                }, ReceiveBlock);
            }, obj => GenericCanExecute(obj) && DataTransfer.CurrentAccount.ScreenName != User.ScreenName);

            reportSpam = new DelegateCommand((obj) =>
            {
                IsLoading = true;
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).ReportSpam(new ReportSpamOptions {
                    UserId = User.Id
                }, ReceiveReportSpam);
            }, obj => GenericCanExecute(obj) && DataTransfer.CurrentAccount.ScreenName != User.ScreenName);

            changeAvatar = new DelegateCommand((obj) =>
            {
                PhotoChooserTask task = new PhotoChooserTask();
                task.ShowCamera       = true;
                task.Completed       += new EventHandler <PhotoResult>(task_Completed);
                task.Show();
            }, (obj) => GenericCanExecute.Invoke(null) && IsOwner);

            navigateTo = new DelegateCommand((url) =>
            {
                var task = new WebBrowserTask();
                task.Uri = new Uri((string)url, UriKind.Absolute);
                task.Show();
            }, (url) => url is string && Uri.IsWellFormedUriString(url as string, UriKind.Absolute));

            manageLists = new DelegateCommand((obj) => Navigate("/Pages/Lists/ListManager.xaml?user="******"FollowsMe")
                {
                    UpdateRelationshipText();
                }
                if (e.PropertyName == "ScreenName")
                {
                    UpdateRelationshipText();
                }
            };
        }
示例#15
0
        private void CreateCommands()
        {
            deleteTweet = new DelegateCommand((obj) =>
            {
                var user = Config.Accounts.FirstOrDefault(item => item != null && item.ScreenName == Tweet.Author.ScreenName);

                ServiceDispatcher.GetService(user).DeleteTweet(new DeleteTweetOptions {
                    Id = Tweet.Id
                }, (s, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        MessageService.ShowMessage(Localization.Resources.TweetDeleted, "");
                    }
                    else
                    {
                        MessageService.ShowError(Localization.Resources.ErrorDeletingTweet);
                    }
                });
            }, (obj) => Tweet != null && Tweet.Author != null && Config.Accounts.Any(item => item != null && item.ScreenName == Tweet.Author.ScreenName));


            share = new DelegateCommand((obj) => Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                EmailComposeTask emailComposeTask = new EmailComposeTask();

                emailComposeTask.Subject = String.Format(Localization.Resources.TweetFrom, Tweet.Author.ScreenName);
                emailComposeTask.Body    = "@" + Tweet.Author.ScreenName + ": " + Tweet.Text +
                                           Environment.NewLine + Environment.NewLine + Tweet.CreatedDate.ToString();

                emailComposeTask.Show();
            }), obj => Tweet != null);

            quote = new DelegateCommand((obj) =>
            {
                DataTransfer.Text = "RT @" + Tweet.Author.ScreenName + ": " + Tweet.Text;
                Navigate(Uris.WriteTweet);
            }, obj => Config.Accounts.Any() && Tweet != null);

            favorite = new DelegateCommand((parameter) =>
            {
                TwitterStatus param = (TwitterStatus)parameter;
                if (IsFavorited)
                {
                    ServiceDispatcher.GetService(DataTransfer.CurrentAccount).UnfavoriteTweet(new UnfavoriteTweetOptions {
                        Id = param.Id
                    }, (sts, resp) =>
                    {
                        MessageService.ShowLightNotification(Localization.Resources.Unfavorited);
                        IsFavorited = false;
                    });
                }
                else
                {
                    ServiceDispatcher.GetService(DataTransfer.CurrentAccount).FavoriteTweet(new FavoriteTweetOptions {
                        Id = param.Id
                    }, (sts, resp) =>
                    {
                        MessageService.ShowLightNotification(Localization.Resources.Favorited);
                        IsFavorited = true;
                    });
                }
            }, parameter => (parameter is TwitterStatus) && Config.Accounts.Count > 0 && DataTransfer.CurrentAccount != null);

            sendTweet = new DelegateCommand((parameter) =>
            {
                IsLoading = true;
                BarText   = Resources.SendingTweet;
                ServiceDispatcher.GetCurrentService().SendTweet(new SendTweetOptions
                {
                    InReplyToStatusId = Tweet.Id,
                    Status            = ReplyText
                }, (status, response) =>
                {
                    IsLoading = false;
                    BarText   = "";
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        MessageService.ShowError(response.Error != null ? response.Error.Message : Resources.UnknownValue);
                    }
                    else if (TweetSent != null)
                    {
                        TweetSent(this, new EventArgs <ITweetable>(status));
                    }
                });
            });
        }
示例#16
0
        void Send(object param)
        {
            if (!CheckProtectedAccounts())
            {
                return;
            }

            requestsLeft = 0;

            if (SelectedAccounts.Count == 0)
            {
                MessageService.ShowError(Resources.SelectAccount);
                return;
            }

            BarText   = Resources.SendingTweet;
            IsLoading = true;

            if (IsDM)
            {
                ServiceDispatcher.GetService(DataTransfer.CurrentAccount).SendDirectMessage(new SendDirectMessageOptions {
                    UserId = (int)DataTransfer.DMDestinationId, Text = TweetText
                }, ReceiveDM);
            }
            else
            {
                if (UsesTwitlonger)
                {
                    if (!EnsureTwitlonger())
                    {
                        IsLoading = false;
                        return;
                    }

                    BarText = Resources.UploadingTwitlonger;
                    foreach (UserToken account in SelectedAccounts.Cast <UserToken>())
                    {
                        ServiceDispatcher.GetTwitlongerService(account).PostUpdate(TweetText, ReceiveTLResponse);
                        requestsLeft++;
                    }
                }
                else
                {
                    if (IsGeotagged)
                    {
                        var location = geoWatcher.Position.Location;

                        foreach (UserToken account in SelectedAccounts.Cast <UserToken>())
                        {
                            ServiceDispatcher.GetService(account).SendTweet(new SendTweetOptions
                            {
                                Status            = TweetText,
                                InReplyToStatusId = DataTransfer.ReplyId,
                                Lat  = location.Latitude,
                                Long = location.Longitude
                            }, ReceiveResponse);
                            requestsLeft++;
                        }
                    }
                    else
                    {
                        foreach (UserToken account in SelectedAccounts.Cast <UserToken>())
                        {
                            ServiceDispatcher.GetService(account).SendTweet(new SendTweetOptions {
                                Status = TweetText, InReplyToStatusId = DataTransfer.ReplyId
                            }, ReceiveResponse);
                            requestsLeft++;
                        }
                    }
                }
            }

            if (DataTransfer.Draft != null)
            {
                if (Config.Drafts.Contains(DataTransfer.Draft))
                {
                    Config.Drafts.Remove(DataTransfer.Draft);
                }

                DataTransfer.Draft = null;
                Config.SaveDrafts();
            }
        }