From 2c159b4d058ba978ebbaf9ce6b05ace1df846668 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 12 Sep 2013 11:36:21 +0300 Subject: [PATCH] Saves last seen message coming from server as chat room history and skip older history messages from now on. --- .../protocol/jabber/ChatRoomJabberImpl.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java index dc9ebb209..9c9cc317d 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java @@ -1700,6 +1700,18 @@ private void setConferenceDescriptionPacketExtension( private class SmackMessageListener implements PacketListener { + /** + * The timestamp of the last history message sent to the UI. + * Do not send earlier or messages with the same timestamp. + */ + private Date lastSeenDelayedMessage = null; + + /** + * The property to store the timestamp. + */ + private static final String LAST_SEEN_DELAYED_MESSAGE_PROP + = "lastSeenDelayedMessage"; + /** * Process a packet. * @param packet to process. @@ -1720,6 +1732,41 @@ public void processPacket(Packet packet) if(delay != null) { timeStamp = delay.getStamp(); + + // This is a delayed chat room message, a history message for + // the room coming from server. Lets check have we already + // shown this message and if this is the case skip it + // otherwise save it as last seen delayed message + if(lastSeenDelayedMessage == null) + { + // initialise this from configuration + String timestamp = + ConfigurationUtils.getChatRoomProperty( + provider, + getIdentifier(), + LAST_SEEN_DELAYED_MESSAGE_PROP); + + try + { + lastSeenDelayedMessage = + new Date(Long.parseLong(timestamp)); + } + catch(Throwable t) + {} + } + + if(lastSeenDelayedMessage != null + && !timeStamp.after(lastSeenDelayedMessage)) + return; + + // save it in configuration + ConfigurationUtils.updateChatRoomProperty( + provider, + getIdentifier(), + LAST_SEEN_DELAYED_MESSAGE_PROP, + String.valueOf(timeStamp.getTime())); + + lastSeenDelayedMessage = timeStamp; } else {