Commit 2a327879 authored by Sylvain Berfini's avatar Sylvain Berfini

Fix incoming messages saving and display

parent c5b2d9c3
......@@ -770,12 +770,24 @@ namespace Linphone.Model
/// </summary>
public void MessageReceived(LinphoneChatMessage message)
{
Logger.Msg("[LinphoneManager] Message received from " + message.GetFrom().AsStringUriOnly() + ": " + message.GetText());
string sipAddress = message.GetFrom().AsStringUriOnly().Replace("sip:", "");
Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.GetText());
if (MessageListener != null)
if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
{
MessageListener.MessageReceived(message);
}
else
{
DateTime date = new DateTime();
date = date.AddYears(1969); //Timestamp is calculated from 01/01/1970, and DateTime is initialized to 01/01/0001.
date = date.AddSeconds(message.GetTime());
date = date.Add(TimeZoneInfo.Local.GetUtcOffset(date));
ChatMessage msg = new ChatMessage { Message = message.GetText(), MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = (date.Ticks / TimeSpan.TicksPerSecond) };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
}
}
#endregion
......
......@@ -25,6 +25,11 @@ namespace Linphone.Views
/// Callback called when a message is received.
/// </summary>
void MessageReceived(LinphoneChatMessage message);
/// <summary>
/// Returns the sip address of the current displayed conversation if possible
/// </summary>
string GetSipAddressAssociatedWithDisplayConversation();
}
/// <summary>
......@@ -74,6 +79,10 @@ namespace Linphone.Views
if (NavigationContext.QueryString.ContainsKey("sip") && e.NavigationMode != NavigationMode.Back)
{
sipAddress = NavigationContext.QueryString["sip"];
if (sipAddress.StartsWith("sip:"))
{
sipAddress = sipAddress.Replace("sip:", "");
}
ContactName.Text = sipAddress;
cm.FindContact(sipAddress);
......@@ -162,6 +171,7 @@ namespace Linphone.Views
ChatMessage msg = new ChatMessage { Message = message, MarkedAsRead = true, IsIncoming = false, RemoteContact = sipAddress, LocalContact = "", Timestamp = (now.Ticks / TimeSpan.TicksPerSecond), Status = (int)LinphoneChatMessageState.InProgress };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
}
/// <summary>
......@@ -234,7 +244,6 @@ namespace Linphone.Views
{
MessagesList.Dispatcher.BeginInvoke(() =>
{
//FIXME: message.GetTime() returns a bad value.
DateTime date = new DateTime();
date = date.AddYears(1969); //Timestamp is calculated from 01/01/1970, and DateTime is initialized to 01/01/0001.
date = date.AddSeconds(message.GetTime());
......@@ -244,11 +253,17 @@ namespace Linphone.Views
ChatMessage msg = new ChatMessage { Message = message.GetText(), MarkedAsRead = true, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = (date.Ticks / TimeSpan.TicksPerSecond) };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
scrollToBottom();
});
}
public string GetSipAddressAssociatedWithDisplayConversation()
{
return sipAddress;
}
private void scrollToBottom()
{
MessagesScroll.UpdateLayout();
......
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