Commit 73539542 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Fixing file sharing

parent fd867c3a
......@@ -51,13 +51,11 @@ namespace Linphone.Controls {
if (isImageMessage) {
Message.Visibility = Visibility.Collapsed;
//Copy.Visibility = Visibility.Collapsed;
if (filePath != null && filePath.Length > 0) {
if (message.Appdata != null && message.Appdata.Length > 0) {
// Image already downloaded
Image.Visibility = Visibility.Visible;
// Save.Visibility = Visibility.Visible;
SetImage(filePath);
//Save.Visibility = Visibility.Visible;
SetImage(message.Appdata);
} else {
// Image needs to be downloaded
Download.Visibility = Visibility.Visible;
......
......@@ -39,14 +39,20 @@ namespace Linphone.Controls {
ChatMessage = message;
this.Holding += Bubble_Holding;
string filePath = message.FileTransferFilepath;
bool isImageMessage = filePath != null && filePath.Length > 0;
string fileName = null;
if (message.FileTransferInformation != null && message.FileTransferInformation.Name != null) {
fileName = message.FileTransferInformation.Name;
int end = message.FileTransferInformation.Name.IndexOf('.');
if (end > 0)
fileName = fileName.Substring(0, end);
}
bool isImageMessage = fileName != null && fileName.Length > 0;
if (isImageMessage) {
Message.Visibility = Visibility.Collapsed;
//Copy.Visibility = Visibility.Collapsed;
Image.Visibility = Visibility.Visible;
//Save.Visibility = Visibility.Visible;
SetImage(filePath);
SetImage(fileName);
} else {
Message.Visibility = Visibility.Visible;
Message.Blocks.Add(Utils.FormatText(message.Text));
......@@ -100,6 +106,17 @@ namespace Linphone.Controls {
public void MessageStateChanged(ChatMessage message, ChatMessageState state) {
}
/// <summary>
/// Displays the image in the bubble
/// </summary>
public void RefreshImage() {
string filePath = ChatMessage.FileTransferFilepath;
if (filePath != null && filePath.Length > 0) {
Image.Visibility = Visibility.Visible;
SetImage(ChatMessage.Appdata);
}
}
public delegate void MessageDeletedEventHandler(object sender, ChatMessage message);
public event MessageDeletedEventHandler MessageDeleted;
......
......@@ -100,7 +100,7 @@ namespace Linphone.Views {
CreateChatRoom(sipAddress);
UpdateComposingMessage();
chatRoom.MarkAsRead();
DisplayPastMessages(chatRoom.GetHistory(chatRoom.HistorySize));
DisplayPastMessagesAsync(chatRoom.GetHistory(chatRoom.HistorySize));
}
if (sipAddress == null) {
ContactName.Visibility = Visibility.Collapsed;
......@@ -142,18 +142,26 @@ namespace Linphone.Views {
#endregion
private void DisplayPastMessages(IEnumerable<ChatMessage> messages) {
private async void DisplayPastMessagesAsync(IEnumerable<ChatMessage> messages) {
foreach (ChatMessage message in messages) {
if (!message.IsOutgoing) {
IncomingChatBubble bubble = new IncomingChatBubble(message);
bubble.MessageDeleted += bubble_MessageDeleted;
bubble.DownloadImage += bubble_DownloadImage;
bubble.ImageTapped += Bubble_ImageTapped;
bubble.RefreshImage();
MessagesList.Children.Add(bubble);
} else {
if (!message.IsText && message.FileTransferInformation != null) {
var tempFolder = ApplicationData.Current.LocalFolder;
string name = message.FileTransferInformation.Name;
StorageFile tempFile = await tempFolder.GetFileAsync(name.Substring(0, name.IndexOf('.')));
message.FileTransferFilepath = tempFile.Path;
}
OutgoingChatBubble bubble = new OutgoingChatBubble(message);
bubble.MessageDeleted += bubble_MessageDeleted;
bubble.UpdateStatus(message.State);
bubble.RefreshImage();
MessagesList.Children.Add(bubble);
}
}
......@@ -235,6 +243,16 @@ namespace Linphone.Views {
} catch {
Debug.WriteLine("Cannot create load download image");
}
} else if (state == ChatMessageState.FileTransferDone && message.IsOutgoing) {
try {
OutgoingChatBubble bubble = (OutgoingChatBubble)MessagesList.Children.OfType<OutgoingChatBubble>().Where(b => message.Equals(((OutgoingChatBubble)b).ChatMessage)).Last();
if (bubble != null) {
((OutgoingChatBubble)bubble).ChatMessage.FileTransferFilepath = message.FileTransferFilepath;
((OutgoingChatBubble)bubble).RefreshImage();
}
} catch {
Debug.WriteLine("Cannot load uploaded image");
}
} else {
try {
foreach (OutgoingChatBubble bubble in MessagesList.Children.OfType<OutgoingChatBubble>()) {
......@@ -333,6 +351,7 @@ namespace Linphone.Views {
ChatMessage msg = chatRoom.CreateFileTransferMessage(content);
msg.Appdata = fileName;
msg.FileTransferFilepath = filePath;
msg.Listener.OnMsgStateChanged = MessageStateChanged;
chatRoom.SendChatMessage(msg);
} catch (Exception e) {
Debug.WriteLine("Cannot upload image: " + e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment