aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/msghistory
diff options
context:
space:
mode:
authorIngo Bauersachs <ingo@jitsi.org>2013-04-07 12:32:25 +0000
committerIngo Bauersachs <ingo@jitsi.org>2013-04-07 12:32:25 +0000
commit83e15ea8e2ac9a2b1b7754eb6eda75437f50d65c (patch)
treeff1278f35c13a8cae4af96a6dc23b3f72cf8028d /src/net/java/sip/communicator/impl/msghistory
parent14c78d292ca8c1a228e0c3359532e0f369f8dbf6 (diff)
downloadjitsi-83e15ea8e2ac9a2b1b7754eb6eda75437f50d65c.zip
jitsi-83e15ea8e2ac9a2b1b7754eb6eda75437f50d65c.tar.gz
jitsi-83e15ea8e2ac9a2b1b7754eb6eda75437f50d65c.tar.bz2
Log dates in all history files as ISO 8601 with timezone
Diffstat (limited to 'src/net/java/sip/communicator/impl/msghistory')
-rw-r--r--src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java82
1 files changed, 51 insertions, 31 deletions
diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
index 9ea2c40..87a8e2c 100644
--- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java
@@ -6,8 +6,12 @@
*/
package net.java.sip.communicator.impl.msghistory;
+import static
+ net.java.sip.communicator.service.history.HistoryService.DATE_FORMAT;
+
import java.beans.*;
import java.io.*;
+import java.text.*;
import java.util.*;
import net.java.sip.communicator.service.contactlist.*;
@@ -387,13 +391,13 @@ public class MessageHistoryServiceImpl
if(object instanceof MessageDeliveredEvent)
{
isRecordOK =
- (((MessageDeliveredEvent)object).getTimestamp()
+ (((MessageDeliveredEvent)object).getTimestamp().getTime()
> date.getTime());
}
else if(object instanceof MessageReceivedEvent)
{
isRecordOK =
- (((MessageReceivedEvent)object).getTimestamp()
+ (((MessageReceivedEvent)object).getTimestamp().getTime()
> date.getTime());
}
@@ -630,18 +634,19 @@ public class MessageHistoryServiceImpl
Contact contact)
{
MessageImpl msg = createMessageFromHistoryRecord(hr);
- long timestamp;
+ Date timestamp;
// if there is value for date of receiving the message
// this is the event timestamp (this is the date that had came
// from protocol)
// the HistoryRecord timestamp is the timestamp when the record
// was written
- long messageReceivedDate = msg.getMessageReceivedDate();
- long hrTimestamp = hr.getTimestamp();
- if (messageReceivedDate != 0)
+ Date messageReceivedDate = msg.getMessageReceivedDate();
+ Date hrTimestamp = hr.getTimestamp();
+ if (messageReceivedDate.getTime() != 0)
{
- if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000
+ // 24*60*60*1000
+ if(messageReceivedDate.getTime() - hrTimestamp.getTime() > 86400000)
timestamp = hrTimestamp;
else
timestamp = msg.getMessageReceivedDate();
@@ -676,18 +681,19 @@ public class MessageHistoryServiceImpl
HistoryRecord hr, ChatRoom room)
{
MessageImpl msg = createMessageFromHistoryRecord(hr);
- long timestamp;
+ Date timestamp;
// if there is value for date of receiving the message
// this is the event timestamp (this is the date that had came
// from protocol)
// the HistoryRecord timestamp is the timestamp when the record
// was written
- long messageReceivedDate = msg.getMessageReceivedDate();
- long hrTimestamp = hr.getTimestamp();
- if(messageReceivedDate != 0)
+ Date messageReceivedDate = msg.getMessageReceivedDate();
+ Date hrTimestamp = hr.getTimestamp();
+ if(messageReceivedDate.getTime() != 0)
{
- if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000
+ // 24*60*60*1000
+ if(messageReceivedDate.getTime() - hrTimestamp.getTime() > 86400000)
timestamp = hrTimestamp;
else
timestamp = msg.getMessageReceivedDate();
@@ -735,7 +741,8 @@ public class MessageHistoryServiceImpl
String messageUID = null;
String subject = null;
boolean isOutgoing = false;
- long messageReceivedDate = 0;
+ Date messageReceivedDate = new Date(0);
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
for (int i = 0; i < hr.getPropertyNames().length; i++)
{
String propName = hr.getPropertyNames()[i];
@@ -759,8 +766,15 @@ public class MessageHistoryServiceImpl
}
else if (propName.equals(STRUCTURE_NAMES[6]))
{
- messageReceivedDate =
- Long.parseLong(hr.getPropertyValues()[i]);
+ try
+ {
+ messageReceivedDate = sdf.parse(hr.getPropertyValues()[i]);
+ }
+ catch (ParseException e)
+ {
+ messageReceivedDate =
+ new Date(Long.parseLong(hr.getPropertyValues()[i]));
+ }
}
}
return new MessageImpl(textContent, contentType, contentEncoding,
@@ -892,7 +906,7 @@ public class MessageHistoryServiceImpl
* that came from the protocol provider
*/
private void writeMessage(String direction, Contact source,
- Contact destination, Message message, long messageTimestamp)
+ Contact destination, Message message, Date messageTimestamp)
{
try {
History history = this.getHistory(source, destination);
@@ -913,14 +927,16 @@ public class MessageHistoryServiceImpl
* that came from the protocol provider
*/
private void writeMessage(History history, String direction,
- Message message, long messageTimestamp)
+ Message message, Date messageTimestamp)
{
try {
HistoryWriter historyWriter = history.getWriter();
+ SimpleDateFormat sdf
+ = new SimpleDateFormat(HistoryService.DATE_FORMAT);
historyWriter.addRecord(new String[] { direction,
message.getContent(), message.getContentType(),
message.getEncoding(), message.getMessageUID(),
- message.getSubject(), String.valueOf(messageTimestamp) },
+ message.getSubject(), sdf.format(messageTimestamp) },
new Date()); // this date is when the history record is written
} catch (IOException e)
{
@@ -939,7 +955,7 @@ public class MessageHistoryServiceImpl
*/
private void writeMessage(History history, String direction,
ChatRoomMember from,
- Message message, long messageTimestamp)
+ Message message, Date messageTimestamp)
{
try {
// mising from, strange messages, most probably a history
@@ -948,11 +964,13 @@ public class MessageHistoryServiceImpl
return;
HistoryWriter historyWriter = history.getWriter();
+ SimpleDateFormat sdf
+ = new SimpleDateFormat(HistoryService.DATE_FORMAT);
historyWriter.addRecord(new String[] { direction,
message.getContent(), message.getContentType(),
message.getEncoding(), message.getMessageUID(),
from.getContactAddress(),
- String.valueOf(messageTimestamp) },
+ sdf.format(messageTimestamp) },
new Date()); // this date is when the history record is written
} catch (IOException e)
{
@@ -971,16 +989,18 @@ public class MessageHistoryServiceImpl
*/
private void writeMessage(History history, String direction,
Contact from,
- Message message, long messageTimestamp)
+ Message message, Date messageTimestamp)
{
try
{
HistoryWriter historyWriter = history.getWriter();
+ SimpleDateFormat sdf
+ = new SimpleDateFormat(HistoryService.DATE_FORMAT);
historyWriter.addRecord(new String[] { direction,
message.getContent(), message.getContentType(),
message.getEncoding(), message.getMessageUID(),
from.getAddress(),
- String.valueOf(messageTimestamp) },
+ sdf.format(messageTimestamp) },
new Date()); // this date is when the history record is written
} catch (IOException e)
{
@@ -1948,11 +1968,11 @@ public class MessageHistoryServiceImpl
{
private final boolean isOutgoing;
- private final long messageReceivedDate;
+ private final Date messageReceivedDate;
MessageImpl(String content, String contentType, String encoding,
String subject, String messageUID, boolean isOutgoing,
- long messageReceivedDate)
+ Date messageReceivedDate)
{
super(content, contentType, encoding, subject, messageUID);
@@ -1960,7 +1980,7 @@ public class MessageHistoryServiceImpl
this.messageReceivedDate = messageReceivedDate;
}
- public long getMessageReceivedDate()
+ public Date getMessageReceivedDate()
{
return messageReceivedDate;
}
@@ -1975,8 +1995,8 @@ public class MessageHistoryServiceImpl
{
public int compare(T o1, T o2)
{
- long date1;
- long date2;
+ Date date1;
+ Date date2;
if(o1 instanceof MessageDeliveredEvent)
date1 = ((MessageDeliveredEvent)o1).getTimestamp();
@@ -1992,7 +2012,7 @@ public class MessageHistoryServiceImpl
else
return 0;
- return (date1 < date2) ? -1 : ((date1 == date2) ? 0 : 1);
+ return date1.compareTo(date2);
}
}
@@ -2006,8 +2026,8 @@ public class MessageHistoryServiceImpl
{
public int compare(T o1, T o2)
{
- long date1;
- long date2;
+ Date date1;
+ Date date2;
if(o1 instanceof ChatRoomMessageDeliveredEvent)
date1 = ((ChatRoomMessageDeliveredEvent)o1).getTimestamp();
@@ -2023,7 +2043,7 @@ public class MessageHistoryServiceImpl
else
return 0;
- return (date1 < date2) ? -1 : ((date1 == date2) ? 0 : 1);
+ return date1.compareTo(date2);
}
}