Commit 4520f517 authored by Sylvain Berfini's avatar Sylvain Berfini

Added duplicate message detection

parent acd4da7c
......@@ -788,6 +788,20 @@ namespace Linphone.Model
/// </summary>
public void MessageReceived(LinphoneChatMessage message)
{
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));
long timestamp = (date.Ticks / TimeSpan.TicksPerSecond);
//Check if duplicate
var duplicate = from m in DatabaseManager.Instance.Messages where (m.Timestamp == timestamp && m.Message.Equals(message.GetText()) && m.ImageURL.Equals(message.GetExternalBodyUrl())) select m;
if (duplicate.Count() > 0)
{
Debug.WriteLine("[LinphoneManager] Duplicate message detected : " + message.GetText());
return;
}
string sipAddress = message.GetFrom().AsStringUriOnly().Replace("sip:", "");
Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.GetText());
......@@ -801,15 +815,10 @@ namespace Linphone.Model
}
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));
//TODO: Temp hack to remove
string url = message.GetExternalBodyUrl();
url = url.Replace("\"", "");
ChatMessage msg = new ChatMessage { Message = message.GetText(), ImageURL = url, MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = (date.Ticks / TimeSpan.TicksPerSecond) };
ChatMessage msg = new ChatMessage { Message = message.GetText(), ImageURL = url, MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = timestamp };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
......
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