Exemplo n.º 1
0
        private void InitiateImageUpload(string filePath, string fileName)
        {
            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                if (chatRoom == null) //This code will be executed only in case of new conversation
                {
                    CreateChatRoom(LinphoneManager.Instance.LinphoneCore.InterpretURL(NewChatSipAddress.Text));
                }
                if (chatRoom != null)
                {
                    ProgressPopup.Visibility = Visibility.Visible;
                    MessageBox.Visibility    = Visibility.Collapsed;
                    AddCancelUploadButtonInAppBar();

                    FileInfo fileInfo       = new FileInfo(filePath);
                    LinphoneChatMessage msg = chatRoom.CreateFileTransferMessage("application", "octet-stream", fileName, (int)fileInfo.Length, filePath);
                    msg.AppData             = filePath;
                    chatRoom.SendMessage(msg, this);
                }
                else
                {
                    ProgressPopup.Visibility = Visibility.Collapsed;
                    MessageBox.Visibility    = Visibility.Visible;
                    AddSendButtonsToAppBar();
                    System.Windows.MessageBox.Show(AppResources.ChatRoomCreationError, AppResources.GenericError, MessageBoxButton.OK);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Public constructor.
        /// </summary>
        public OutgoingChatBubble(LinphoneChatMessage message) :
            base(message)
        {
            InitializeComponent();

            string filePath       = message.AppData;
            bool   isImageMessage = filePath != null && filePath.Length > 0;

            if (isImageMessage)
            {
                Message.Visibility = Visibility.Collapsed;
                Copy.Visibility    = Visibility.Collapsed;
                Image.Visibility   = Visibility.Visible;
                Save.Visibility    = Visibility.Visible;

                BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
                Image.Source = image;
            }
            else
            {
                Message.Visibility = Visibility.Visible;
                Image.Visibility   = Visibility.Collapsed;
                Message.Blocks.Add(TextWithLinks);
            }

            Timestamp.Text  = HumanFriendlyTimeStamp;
            Background.Fill = _darkAccentBrush;
            Path.Fill       = _darkAccentBrush;
        }
        /// <summary>
        /// Public constructor.
        /// </summary>
        public IncomingChatBubble(LinphoneChatMessage message) :
            base (message)
        {
            InitializeComponent();
            Timestamp.Text = HumanFriendlyTimeStamp;

            string fileName = message.FileTransferName;
            string filePath = message.AppData;
            bool isImageMessage = fileName != null && fileName.Length > 0;
            if (isImageMessage)
            {
                Message.Visibility = Visibility.Collapsed;
                Copy.Visibility = Visibility.Collapsed;
                if (filePath != null && filePath.Length > 0)
                {
                    // Image already downloaded
                    Image.Visibility = Visibility.Visible;
                    Save.Visibility = Visibility.Visible;

                    BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
                    Image.Source = image;
                }
                else
                {
                    // Image needs to be downloaded
                    Download.Visibility = Visibility.Visible;
                }
            }
            else
            {
                Message.Visibility = Visibility.Visible;
                Image.Visibility = Visibility.Collapsed;
                Message.Blocks.Add(TextWithLinks);
            }
        }
        /// <summary>
        /// Public constructor.
        /// </summary>
        public OutgoingChatBubble(LinphoneChatMessage message) :
            base(message)
        {
            InitializeComponent();

            string filePath = message.AppData;
            bool isImageMessage = filePath != null && filePath.Length > 0;
            if (isImageMessage)
            {
                Message.Visibility = Visibility.Collapsed;
                Copy.Visibility = Visibility.Collapsed;
                Image.Visibility = Visibility.Visible;
                Save.Visibility = Visibility.Visible;

                BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
                Image.Source = image;
            }
            else
            {
                Message.Visibility = Visibility.Visible;
                Image.Visibility = Visibility.Collapsed;
                Message.Blocks.Add(TextWithLinks);
            }

            Timestamp.Text = HumanFriendlyTimeStamp;
            Background.Fill = _darkAccentBrush;
            Path.Fill = _darkAccentBrush;
        }
Exemplo n.º 5
0
 private void SendMessage(string message)
 {
     if (chatRoom != null)
     {
         LinphoneChatMessage chatMessage = chatRoom.CreateLinphoneChatMessage(message);
         chatRoom.SendMessage(chatMessage, this);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Callback called when a user selects the delete context menu
 /// </summary>
 public void bubble_MessageDeleted(object sender, LinphoneChatMessage message)
 {
     MessagesList.Children.Remove(sender as UserControl);
     if (chatRoom != null)
     {
         chatRoom.DeleteMessageFromHistory(message);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Callback called by LinphoneCore when the state of a sent message changes.
        /// </summary>
        public void MessageStateChanged(LinphoneChatMessage message, LinphoneChatMessageState state)
        {
            Logger.Msg("[Chat] Message state changed: " + state.ToString());

            Dispatcher.BeginInvoke(() =>
            {
                if (ProgressPopup.Visibility == Visibility.Visible)
                {
                    ProgressPopup.Visibility = Visibility.Collapsed;
                    MessageBox.Visibility    = Visibility.Visible;
                    AddSendButtonsToAppBar();
                }

                if (state == LinphoneChatMessageState.InProgress)
                {
                    // Create the chat bubble for both text or image messages
                    OutgoingChatBubble bubble = new OutgoingChatBubble(message);
                    bubble.MessageDeleted    += bubble_MessageDeleted;
                    MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble);
                    scrollToBottom();
                }
                else if (state == LinphoneChatMessageState.FileTransferDone && !message.IsOutgoing)
                {
                    try
                    {
                        message.AppData   = message.FileTransferFilePath;
                        ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last();
                        if (bubble != null)
                        {
                            ((IncomingChatBubble)bubble).RefreshImage();
                        }
                        EnableDownloadButtons(true);
                    }
                    catch { }
                }
                else
                {
                    // Update the outgoing status of the message
                    try
                    {
                        ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last();
                        if (bubble != null)
                        {
                            ((OutgoingChatBubble)bubble).UpdateStatus(state);
                        }
                    }
                    catch { }
                }

                if (chatRoom != null)
                {
                    chatRoom.MarkAsRead();
                }
            });
        }
Exemplo n.º 8
0
        /// <summary>
        /// Callback called by LinphoneManager when a message is received.
        /// </summary>
        public void MessageReceived(LinphoneChatMessage message)
        {
            MessagesList.Dispatcher.BeginInvoke(() =>
            {
                IncomingChatBubble bubble = new IncomingChatBubble(message);
                bubble.MessageDeleted    += bubble_MessageDeleted;
                bubble.DownloadImage     += bubble_DownloadImage;
                MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble);

                if (chatRoom != null)
                {
                    chatRoom.MarkAsRead();
                }

                scrollToBottom();
            });
        }
        /// <summary>
        /// Public constructor.
        /// </summary>
        public IncomingChatBubble(LinphoneChatMessage message) :
            base(message)
        {
            InitializeComponent();
            Timestamp.Text = HumanFriendlyTimeStamp;

            string fileName       = message.FileTransferName;
            string filePath       = message.AppData;
            bool   isImageMessage = fileName != null && fileName.Length > 0;

            if (isImageMessage)
            {
                Message.Visibility = Visibility.Collapsed;
                Copy.Visibility    = Visibility.Collapsed;
                if (filePath != null && filePath.Length > 0)
                {
                    // Image already downloaded
                    Image.Visibility = Visibility.Visible;
                    Save.Visibility  = Visibility.Visible;

                    BitmapImage image = Utils.ReadImageFromIsolatedStorage(filePath);
                    Image.Source = image;
                }
                else
                {
                    // Image needs to be downloaded
                    Download.Visibility = Visibility.Visible;
                }
            }
            else
            {
                Message.Visibility = Visibility.Visible;
                Image.Visibility   = Visibility.Collapsed;
                Message.Blocks.Add(TextWithLinks);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void MessageReceived(LinphoneChatMessage message)
        {
            if (BaseModel.UIDispatcher == null)
            {
                return;
            }
            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                LinphoneAddress fromAddress = message.From;
                string sipAddress           = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain);
                Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.Text + "\r\n");

                //Vibrate
                ChatSettingsManager settings = new ChatSettingsManager();
                settings.Load();
                if ((bool)settings.VibrateOnIncomingMessage)
                {
                    VibrationDevice vibrator = VibrationDevice.GetDefault();
                    vibrator.Vibrate(TimeSpan.FromSeconds(1));
                }

                if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
                {
                    MessageListener.MessageReceived(message);
                }
                else
                {
                    DateTime date = new DateTime(message.Time * TimeSpan.TicksPerSecond, DateTimeKind.Utc).AddYears(1969).ToLocalTime();
                    DateTime now  = DateTime.Now;
                    string dateStr;
                    if (now.Year == date.Year && now.Month == date.Month && now.Day == date.Day)
                    {
                        dateStr = String.Format("{0:HH:mm}", date);
                    }
                    else if (now.Year == date.Year)
                    {
                        dateStr = String.Format("{0:ddd d MMM, HH:mm}", date);
                    }
                    else
                    {
                        dateStr = String.Format("{0:ddd d MMM yyyy, HH:mm}", date);
                    }

                    //TODO: Temp hack to remove
                    string url = message.ExternalBodyUrl;
                    url        = url.Replace("\"", "");

                    //Displays the message as a popup
                    if (MessageReceivedNotification != null)
                    {
                        MessageReceivedNotification.Dismiss();
                    }

                    MessageReceivedNotification = new CustomMessageBox()
                    {
                        Title              = dateStr,
                        Caption            = url.Length > 0 ? AppResources.ImageMessageReceived : AppResources.MessageReceived,
                        Message            = url.Length > 0 ? "" : message.Text,
                        LeftButtonContent  = AppResources.Close,
                        RightButtonContent = AppResources.Show
                    };

                    MessageReceivedNotification.Dismissed += (s, e) =>
                    {
                        switch (e.Result)
                        {
                        case CustomMessageBoxResult.RightButton:
                            BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/Chat.xaml?sip=" + Utils.ReplacePlusInUri(message.PeerAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute));
                            break;
                        }
                    };

                    MessageReceivedNotification.Show();
                }
            });
        }
Exemplo n.º 11
0
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void FileTransferProgressIndication(LinphoneChatMessage message, int offset, int total)
 {
     Logger.Msg(String.Format("FileTransferProgressIndication: {0}/{1}", offset, total));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Callback called when a user wants to download an image in a message
 /// </summary>
 public void bubble_DownloadImage(object sender, LinphoneChatMessage message)
 {
     EnableDownloadButtons(false);
     this.Focus(); // Focus the page in order to remove focus from the text box and hide the soft keyboard
     message.StartFileDownload(this, Utils.GetImageRandomFileName());
 }
Exemplo n.º 13
0
 public void MessageReceived(LinphoneChatMessage message)
 {
     WriteLog("MessageReceived");
 }
Exemplo n.º 14
0
 public void MessageReceived(LinphoneChatMessage message)
 {
     Console.WriteLine("MessageReceived");
 }
 public void MessageReceived(LinphoneChatMessage message)
 {
     WriteLog("MessageReceived");
 }
 public void FileTransferProgressIndication(LinphoneChatMessage message, int offset, int total)
 {
     WriteLog("FileTransferProgressIndication");
 }
Exemplo n.º 17
0
 public void MessageReceived(LinphoneChatMessage message)
 {
     Console.WriteLine("MessageReceived");
 }
Exemplo n.º 18
0
        /// <summary>
        /// Callback called by LinphoneCore when the state of a sent message changes.
        /// </summary>
        public void MessageStateChanged(LinphoneChatMessage message, LinphoneChatMessageState state)
        {
            Logger.Msg("[Chat] Message state changed: " + state.ToString());

            Dispatcher.BeginInvoke(() =>
            {
                if (ProgressPopup.Visibility == Visibility.Visible)
                {
                    ProgressPopup.Visibility = Visibility.Collapsed;
                    MessageBox.Visibility = Visibility.Visible;
                    AddSendButtonsToAppBar();
                }

                if (state == LinphoneChatMessageState.InProgress)
                {
                    // Create the chat bubble for both text or image messages
                    OutgoingChatBubble bubble = new OutgoingChatBubble(message);
                    bubble.MessageDeleted += bubble_MessageDeleted;
                    MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble);
                    scrollToBottom();
                }
                else if (state == LinphoneChatMessageState.FileTransferDone && !message.IsOutgoing)
                {
                    try
                    {
                        message.AppData = message.FileTransferFilePath;
                        ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last();
                        if (bubble != null)
                        {
                            ((IncomingChatBubble)bubble).RefreshImage();
                        }
                        EnableDownloadButtons(true);
                    }
                    catch { }
                }
                else
                {
                    // Update the outgoing status of the message
                    try
                    {
                        ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last();
                        if (bubble != null)
                        {
                            ((OutgoingChatBubble)bubble).UpdateStatus(state);
                        }
                    }
                    catch { }
                }

                if (chatRoom != null)
                {
                    chatRoom.MarkAsRead();
                }
            });
        }
Exemplo n.º 19
0
        /// <summary>
        /// Callback for LinphoneCoreListener
        /// </summary>
        public void MessageReceived(LinphoneChatMessage message)
        {
            if (BaseModel.UIDispatcher == null) return;
            BaseModel.UIDispatcher.BeginInvoke(() =>
            {
                LinphoneAddress fromAddress = message.From;
                string sipAddress = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain);
                Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.Text + "\r\n");

                //Vibrate
                ChatSettingsManager settings = new ChatSettingsManager();
                settings.Load();
                if ((bool)settings.VibrateOnIncomingMessage)
                {
                    VibrationDevice vibrator = VibrationDevice.GetDefault();
                    vibrator.Vibrate(TimeSpan.FromSeconds(1));
                }

                if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
                {
                    MessageListener.MessageReceived(message);
                }
                else
                {
                    DateTime date = new DateTime(message.Time * TimeSpan.TicksPerSecond, DateTimeKind.Utc).AddYears(1969).ToLocalTime();
                    DateTime now = DateTime.Now;
                    string dateStr;
                    if (now.Year == date.Year && now.Month == date.Month && now.Day == date.Day)
                        dateStr = String.Format("{0:HH:mm}", date);
                    else if (now.Year == date.Year)
                        dateStr = String.Format("{0:ddd d MMM, HH:mm}", date);
                    else
                        dateStr = String.Format("{0:ddd d MMM yyyy, HH:mm}", date);

                    //TODO: Temp hack to remove
                    string url = message.ExternalBodyUrl;
                    url = url.Replace("\"", "");

                    //Displays the message as a popup
                    if (MessageReceivedNotification != null)
                    {
                        MessageReceivedNotification.Dismiss();
                    }

                    MessageReceivedNotification = new CustomMessageBox()
                    {
                        Title = dateStr,
                        Caption = url.Length > 0 ? AppResources.ImageMessageReceived : AppResources.MessageReceived,
                        Message = url.Length > 0 ? "" : message.Text,
                        LeftButtonContent = AppResources.Close,
                        RightButtonContent = AppResources.Show
                    };

                    MessageReceivedNotification.Dismissed += (s, e) =>
                    {
                        switch (e.Result)
                        {
                            case CustomMessageBoxResult.RightButton:
                                BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/Chat.xaml?sip=" + Utils.ReplacePlusInUri(message.PeerAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute));
                                break;
                        }
                    };

                    MessageReceivedNotification.Show();
                }
            });
        }
Exemplo n.º 20
0
 public void FileTransferProgressIndication(LinphoneChatMessage message, int offset, int total)
 {
     Console.WriteLine("FileTransferProgressIndication");
 }
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void FileTransferProgressIndication(LinphoneChatMessage message, int offset, int total)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void FileTransferProgressIndication(LinphoneChatMessage message, int offset, int total)
 {
     Logger.Msg(String.Format("FileTransferProgressIndication: {0}/{1}", offset, total));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Callback called when a user wants to download an image in a message
 /// </summary>
 public void bubble_DownloadImage(object sender, LinphoneChatMessage message)
 {
     EnableDownloadButtons(false);
     this.Focus(); // Focus the page in order to remove focus from the text box and hide the soft keyboard
     message.StartFileDownload(this, Utils.GetImageRandomFileName());
 }
Exemplo n.º 24
0
 /// <summary>
 /// Callback called when a user selects the delete context menu
 /// </summary>
 public void bubble_MessageDeleted(object sender, LinphoneChatMessage message)
 {
     MessagesList.Children.Remove(sender as UserControl);
     if (chatRoom != null) 
     {
         chatRoom.DeleteMessageFromHistory(message);
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Callback called by LinphoneManager when a message is received.
        /// </summary>
        public void MessageReceived(LinphoneChatMessage message)
        {
            MessagesList.Dispatcher.BeginInvoke(() =>
            {
                IncomingChatBubble bubble = new IncomingChatBubble(message);
                bubble.MessageDeleted += bubble_MessageDeleted;
                bubble.DownloadImage += bubble_DownloadImage;
                MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble);

                if (chatRoom != null)
                {
                    chatRoom.MarkAsRead();
                }

                scrollToBottom();
            });
        }
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void MessageReceived(LinphoneChatMessage message)
 {
 }
Exemplo n.º 27
0
 /// <summary>
 /// Public constructor
 /// </summary>
 public ChatBubble(LinphoneChatMessage message)
 {
     InitializeComponent();
     ChatMessage = message;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Public constructor
 /// </summary>
 public ChatBubble(LinphoneChatMessage message)
 {
     InitializeComponent();
     ChatMessage = message;
 }
 /// <summary>
 /// Callback for LinphoneCoreListener
 /// </summary>
 public void MessageReceived(LinphoneChatMessage message)
 {
 }