private async void Save_OnClick(object sender, RoutedEventArgs e)
        {
            var error = "";

            try
            {
                var imageSource = sender as Button;
                var attachment  = imageSource?.CommandParameter as Attachment;
                if (attachment == null)
                {
                    return;
                }
                var fileName = Path.GetFileName(new Uri(attachment.Url).AbsolutePath);
                var client   = new HttpClient();
                var stream   = await client.GetStreamAsync(attachment.Url);

                await FileAccessCommands.SaveStreamToCameraRoll(stream, fileName);

                // TODO: Setup alert system to say photo saved to camera roll.
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                await MessageDialogMaker.SendMessageDialogAsync("Saved the picture to your camera roll!", true);
            }
            else
            {
                await MessageDialogMaker.SendMessageDialogAsync(error, false);
            }
        }
        public async Task SendStatus()
        {
            IsLoading = true;
            if (string.IsNullOrEmpty(Status) || Status.Length > 500)
            {
                return;
            }
            IEnumerable <int> mediaIds = null;

            if (PhotoList.Any())
            {
                mediaIds = PhotoList.Select(node => node.Attachment.Id);
            }
            int?replyId = null;

            if (ReplyStatus != null)
            {
                replyId = ReplyStatus.Id;
            }
            try
            {
                var result = await Client.PostStatus(Status, StatusVisibility, replyId, mediaIds, Sensitive, SpoilerText.Any()?SpoilerText : null);

                await NavigationService.NavigateAsync(typeof(MainPage), "home");
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }
            IsLoading = false;
        }
Esempio n. 3
0
        public async Task <Status> ReShareOption(Status status)
        {
            // TODO: This "works", but it could be more simple. The API layer needs to be tweeked.
            // It would make more sense to replace the status object in the list with the one it gets from the API
            // But it's not updating, because OnPropertyChanged is not in Status...
            // Reblog returns "reblogged" status, not the original status updated.
            try
            {
                Status newStatus = status;
                if (status.Reblogged == null)
                {
                    await Client.Reblog(status.Id);

                    newStatus.Reblogged   = true;
                    newStatus.ReblogCount = newStatus.ReblogCount + 1;
                }
                else
                {
                    var reblogged = !status.Reblogged.Value;
                    if (reblogged)
                    {
                        await Client.Reblog(status.Id);

                        newStatus.Reblogged   = true;
                        newStatus.ReblogCount = newStatus.ReblogCount + 1;
                    }
                    else
                    {
                        await Client.Unreblog(status.Id);

                        newStatus.Reblogged   = false;
                        newStatus.ReblogCount = newStatus.ReblogCount - 1;
                    }
                }
                if (Statuses != null)
                {
                    var index = Statuses.IndexOf(status);
                    Statuses[index] = newStatus;
                }
                var notifications = Notifications?.Where(node => node.Status == status).ToList();
                if (notifications != null)
                {
                    for (var i = 0; i < notifications.Count(); i++)
                    {
                        var index           = Notifications.IndexOf(notifications[i]);
                        var newNotification = notifications[i];
                        newNotification.Status = newStatus;
                        Notifications[index]   = newNotification;
                    }
                }
                status = newStatus;
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }
            return(status);
        }
Esempio n. 4
0
        public async Task <Status> FavoriteOption(Status status)
        {
            // TODO: This "works", but it could be more simple. The API layer needs to be tweeked.
            // It would make more sense to replace the status object in the list with the one it gets from the API
            // But it's not updating, because OnPropertyChanged is not in Status...
            try
            {
                Status newStatus;
                if (status.Favourited == null)
                {
                    newStatus = await Client.Favourite(status.Id);
                }
                else
                {
                    var favorite = !status.Favourited.Value;
                    if (favorite)
                    {
                        newStatus = await Client.Favourite(status.Id);
                    }
                    else
                    {
                        // API Bug: Unfavorite returns a status that still says it's favorited, even though it's not.
                        // Not sure if it's mastodon, or the instance I'm on. So for now, we'll force it to say it's
                        // not there.
                        newStatus = await Client.Unfavourite(status.Id);

                        newStatus.Favourited      = false;
                        newStatus.FavouritesCount = newStatus.FavouritesCount - 1;
                    }
                }
                if (Statuses != null)
                {
                    var index = Statuses.IndexOf(status);
                    Statuses[index] = newStatus;
                }
                var notifications = Notifications?.Where(node => node.Status == status).ToList();
                if (notifications != null)
                {
                    for (var i = 0; i < notifications.Count(); i++)
                    {
                        var index           = Notifications.IndexOf(notifications[i]);
                        var newNotification = notifications[i];
                        newNotification.Status = newStatus;
                        Notifications[index]   = newNotification;
                    }
                }
                status = newStatus;
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }
            return(status);
        }
Esempio n. 5
0
        public async Task <Relationship> MuteOption(Status status)
        {
            try
            {
                return(await Client.Mute(status.Account.Id));
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }

            return(new Relationship());
        }
Esempio n. 6
0
 public async Task SetFollowField()
 {
     try
     {
         if (Relationship.Following)
         {
             Relationship = await Client.Unfollow(Account.Id);
         }
         else
         {
             Relationship = await Client.Follow(Account.Id);
         }
     }
     catch (Exception e)
     {
         await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
     }
 }
Esempio n. 7
0
 public async Task SetBlockField()
 {
     try
     {
         if (Relationship.Blocking)
         {
             Relationship = await Client.Unblock(Account.Id);
         }
         else
         {
             Relationship = await Client.Block(Account.Id);
         }
     }
     catch (Exception e)
     {
         await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
     }
 }
Esempio n. 8
0
        public async Task LoginOauth()
        {
            if (string.IsNullOrEmpty(Server))
            {
                return;
            }
            IsLoading = true;
            try
            {
                var appRegistration = await GetAppRegistration();

                var authClient = new AuthenticationClient(appRegistration);
                var oauthUrl   = authClient.OAuthUrl((string.Format(_serverRedirect, Server)));
                var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
                    WebAuthenticationOptions.None,
                    new Uri(oauthUrl),
                    new System.Uri(string.Format(_serverRedirect, Server)));

                string result;
                string code = "";
                switch (webAuthenticationResult.ResponseStatus)
                {
                case Windows.Security.Authentication.Web.WebAuthenticationStatus.Success:
                    // Successful authentication.
                    result = webAuthenticationResult.ResponseData.ToString();
                    var query    = QueryString.Parse(result);
                    var testCode = query.FirstOrDefault();
                    code = testCode?.Value;
                    break;

                case Windows.Security.Authentication.Web.WebAuthenticationStatus.ErrorHttp:
                    // HTTP error.
                    result = webAuthenticationResult.ResponseErrorDetail.ToString();
                    break;

                default:
                    // Other error.
                    result = webAuthenticationResult.ResponseData.ToString();
                    break;
                }

                if (string.IsNullOrEmpty(code))
                {
                    // TODO Add error screen
                }
                else
                {
                    var auth = await authClient.ConnectWithCode(code, string.Format(_serverRedirect, Server));

                    SettingsService.UserAuth = auth;
                    var client  = new MastodonClient(appRegistration, auth);
                    var account = await client.GetCurrentUser();

                    SettingsService.UserAccount             = account;
                    SettingsService.Instance.ServerInstance = Server;
                    IsLoggedIn = true;

                    if (App.IsTenFoot)
                    {
                        // NavigationService.Navigate(typeof(XboxViews.MainPage));
                    }
                    else
                    {
                        Views.Shell.Instance.ViewModel.IsLoggedIn = true;
                        NavigationService.Navigate(typeof(Views.MainPage));
                    }
                }
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }

            //var authUri = $"https://{Server}/oauth/authorize?response_type=code&client_id="

            IsLoading = false;
        }
Esempio n. 9
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            IsLoading = true;
            Title     = "";
            await LoginUser();

            var getNewStatus = false;

            // TODO: The navigation cache will make it so that it will always get a new page.
            // I need to figure out a better way to handle this. This is a mess.
            if (IsLoggedIn)
            {
                try
                {
                    if (parameter != null)
                    {
                        var testAccount = JsonConvert.DeserializeObject <Account>((string)parameter);
                        if (Account == null || testAccount.Id != Account.Id)
                        {
                            Account = await Client.GetAccount(testAccount.Id);

                            try
                            {
                                var relationships = await Client.GetAccountRelationships(testAccount.Id);

                                if (relationships.Any())
                                {
                                    Relationship = relationships.FirstOrDefault();
                                }
                            }
                            catch (Exception e)
                            {
                                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);

                                Relationship = new Relationship();
                            }
                            getNewStatus  = true;
                            IsCurrentUser = false;
                        }
                    }
                    else
                    {
                        var serviceAccountTest = SettingsService.Instance.UserAccount;
                        if (Account == null || serviceAccountTest.Id != Account.Id)
                        {
                            Account = await Client.GetAccount(serviceAccountTest.Id);

                            SettingsService.Instance.UserAccount = Account;
                            getNewStatus  = true;
                            IsCurrentUser = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    // TODO: Show an error if we can't show the user account.
                    await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);

                    Account = SettingsService.Instance.UserAccount;
                }
                Title = Account.UserName;
                if (getNewStatus)
                {
                    Statuses = new TimelineScrollingCollection(Client, "account", Account.Id);
                }
                RaisePropertyChanged("Statuses");
            }
            IsLoading = false;
        }