Ejemplo n.º 1
0
        private async void OnSetAvatar(object sender, RoutedEventArgs e)
        {
            var filePicker = new FileOpenPicker();

            filePicker.FileTypeFilter.Add(".bmp");
            filePicker.FileTypeFilter.Add(".png");
            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".gif");

            filePicker.ViewMode = PickerViewMode.Thumbnail;
            filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            var file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                var filetype = file.ContentType;

                IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                if (fileStream != null)
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    if (decoder != null)
                    {
                        InMemoryRandomAccessStream imageStream = new InMemoryRandomAccessStream();
                        BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(imageStream, decoder);

                        if (encoder != null)
                        {
                            encoder.BitmapTransform.ScaledHeight = 64;
                            encoder.BitmapTransform.ScaledWidth  = 64;

                            try
                            {
                                await encoder.FlushAsync();

                                // Rewind !
                                imageStream.Seek(0);

                                var reader = new DataReader(imageStream);
                                await reader.LoadAsync((uint)imageStream.Size);

                                if (imageStream.Size > 0)
                                {
                                    byte[] image = new byte[imageStream.Size];
                                    reader.ReadBytes(image);
                                    CurrentStatus.SetAvatar(image);

                                    XMPPHelper.PublishAvatar(filetype, image);
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async void OnRemoveContact(object sender, RoutedEventArgs e)
        {
            await Frontend.RunAsync(() =>
            {
                XMPPHelper.RemoveContact(CurrentContact);
            });

            flyoutSelf.Hide();
        }
Ejemplo n.º 3
0
        private async void OnAllow(object sender, RoutedEventArgs e)
        {
            await Frontend.RunAsync(() =>
            {
                XMPPHelper.Subscribed(CurrentContact);
            });

            flyoutSelf.Hide();
        }
Ejemplo n.º 4
0
        private async void OnDeny(object sender, RoutedEventArgs e)
        {
            await Frontend.RunAsync(() =>
            {
                XMPPHelper.Unsubscribed(CurrentContact);

                if (CurrentContact.subscription == XMPP.tags.jabber.iq.roster.item.subscriptionEnum.none)
                {
                    Frontend.Accounts[CurrentContact.account].Roster.Remove(CurrentContact);
                }
            });

            flyoutSelf.Hide();
        }
Ejemplo n.º 5
0
        private async void OnSave(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Alias.Text))
            {
                Warning.Visibility = Windows.UI.Xaml.Visibility.Visible;
                return;
            }

            var account = Frontend.Accounts[CurrentContact.account];

            if (account != null)
            {
                await Frontend.RunAsync(() =>
                {
                    XMPPHelper.EditContact(account, CurrentContact.jid, Alias.Text);
                });

                flyoutSelf.Hide();
            }
        }
Ejemplo n.º 6
0
        private async void OnAdd(object sender, RoutedEventArgs e)
        {
            var account = AccountSelector.SelectedItem as Account;
            var jid     = new XMPP.JID(Jid.Text);

            if (account == null ||
                string.IsNullOrEmpty(jid.Bare) ||
                string.IsNullOrEmpty(jid.Server) ||
                string.IsNullOrEmpty(jid.User))
            {
                Warning.Visibility = Windows.UI.Xaml.Visibility.Visible;
                return;
            }

            await Frontend.RunAsync(() =>
            {
                XMPPHelper.CreateContact(account, jid, Alias.Text);
            });

            flyoutSelf.Hide();
        }
Ejemplo n.º 7
0
        private async void SendMessage()
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    if (CurrentConversation != null && !string.IsNullOrEmpty(SendText.Text))
                    {
                        var account = Frontend.Accounts[CurrentConversation.Self];
                        if (account == null)
                        {
                            return;
                        }

                        if (account.persistantState == AccountState.Enabled)
                        {
                            var self  = GetSelf();
                            var other = GetOther();
                            if (self != null && other != null)
                            {
                                if (!string.IsNullOrEmpty(self.jid) && !string.IsNullOrEmpty(other.CurrentJID))
                                {
                                    var message = XMPPHelper.SendMessage(self.jid, other.CurrentJID, SendText.Text);
                                    if (message != null)
                                    {
                                        message.from = message.Account;
                                        CurrentConversation.AddMessage(message);
                                    }

                                    SendText.Text = string.Empty;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }