Пример #1
0
        private static async Task OnContactPanelActivated(ContactPanelActivatedEventArgs task)
        {
            Analytics.TrackEvent("Unicord_LaunchForMyPeople");

            if (!(Window.Current.Content is Frame rootFrame))
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                try
                {
                    var id = await ContactListManager.TryGetChannelIdAsync(task.Contact);

                    if (id != 0)
                    {
                        rootFrame.Navigate(typeof(MainPage), new MainPageArgs()
                        {
                            UserId = id, FullFrame = true, IsUriActivation = false
                        });
                    }
                }
                catch
                {
                    Analytics.TrackEvent("Unicord_MyPeopleFailedToFindPerson");
                    var dialog = new MessageDialog("Something went wrong trying to find this person, sorry!", "Whoops!");
                    await dialog.ShowAsync();
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            Window.Current.Activate();
        }
Пример #2
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // BUGBUG: this is messy
                var items = new List <object> {
                    new { Name = "Direct Messages" }
                };
                items.AddRange(App.Discord.Guilds.Values.OrderBy(g => g.Name));
                guildBox.ItemsSource = items;

                channelsBox.ItemTemplateSelector = new ChannelTemplateSelector()
                {
                    ServerChannelTemplate = (DataTemplate)App.Current.Resources["NoIndicatorChannelListTemplate"],
                    DirectMessageTemplate = (DataTemplate)App.Current.Resources["NoIndicatorDMChannelTemplate"]
                };

                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                {
                    var contact = _shareOperation.Contacts.FirstOrDefault();
                    if (contact != null)
                    {
                        var id = await ContactListManager.TryGetChannelIdAsync(contact);

                        if (id != 0)
                        {
                            guildBox.SelectedIndex   = 0;
                            channelsBox.SelectedItem = await App.Discord.CreateDmChannelAsync(id);

                            target.Text = contact.DisplayName;
                            destinationGrid.Visibility = Visibility.Collapsed;
                        }
                    }
                }

                _shareOperation.ReportStarted();

                var data = _shareOperation.Data;
                if (data.AvailableFormats.Contains(StandardDataFormats.StorageItems))
                {
                    _file = (await data.GetStorageItemsAsync()).FirstOrDefault() as StorageFile;

                    var img = new BitmapImage();
                    thumbnailImage.Source = img;
                    await img.SetSourceAsync(await _file.GetThumbnailAsync(ThumbnailMode.SingleItem));

                    return;
                }
                else if (data.AvailableFormats.Contains(StandardDataFormats.Bitmap))
                {
                    // do shit

                    _file = await Tools.GetImageFileFromDataPackage(data);

                    var img = new BitmapImage();
                    thumbnailImage.Source = img;
                    await img.SetSourceAsync(await _file.GetThumbnailAsync(ThumbnailMode.PicturesView));

                    return;
                }
                else
                {
                    thumbnailImage.Visibility   = Visibility.Collapsed;
                    captionText.PlaceholderText = "Type a message!";
                }

                if (data.AvailableFormats.Contains(StandardDataFormats.Text))
                {
                    var text = await data.GetTextAsync();

                    captionText.Text += text;
                }

                if (data.AvailableFormats.Contains(StandardDataFormats.WebLink))
                {
                    var text = await data.GetWebLinkAsync();

                    captionText.Text += text;
                }
            }
            finally
            {
                _shareOperation.ReportDataRetrieved();
                this.FindParent <MainPage>().HideConnectingOverlay();

                if (_file != null)
                {
                    var maxSize = (ulong)(App.Discord.CurrentUser.UploadLimit());
                    var props   = await _file.GetBasicPropertiesAsync();

                    if (props.Size >= maxSize)
                    {
                        await UIUtilities.ShowErrorDialogAsync("This file is too big!", $"We're gonna need something under {(Files.SizeSuffix((long)maxSize, 0))} please!");

                        Window.Current.Close();
                    }
                }
            }
        }