From 67857bddcf6de39b74726595006e4c7e384ee313 Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sun, 7 Apr 2013 12:26:42 +0000 Subject: [PATCH] Avoid duplicating incoming message when show history in chats is enabled --- .../communicator/impl/gui/UIServiceImpl.java | 20 ++++++++- .../impl/gui/main/chat/ChatWindowManager.java | 45 ++++++++++++++++++- .../NotificationManager.java | 20 ++++++--- .../communicator/service/gui/UIService.java | 10 +++++ 4 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index cd318f99c..97726b95a 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -652,6 +652,21 @@ public PopupDialog getPopupDialog() * @see UIService#getChat(Contact) */ public ChatPanel getChat(Contact contact) + { + return this.getChat(contact, null); + } + + /** + * Implements {@link UIService#getChat(Contact)}. If a chat for the given + * contact exists already, returns it; otherwise, creates a new one. + * + * @param contact the contact that we'd like to retrieve a chat window for. + * @param escapedMessageID the message ID of the message that should be + * excluded from the history when the last one is loaded in the chat + * @return the Chat corresponding to the specified contact. + * @see UIService#getChat(Contact) + */ + public ChatPanel getChat(Contact contact, String escapedMessageUID) { MetaContact metaContact = GuiActivator.getContactListService() @@ -660,7 +675,10 @@ public ChatPanel getChat(Contact contact) if(metaContact == null) return null; - return chatWindowManager.getContactChat(metaContact, true); + return chatWindowManager.getContactChat( + metaContact, + true, + escapedMessageUID); } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java index 5d6c17569..ec8e4adfa 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java @@ -358,6 +358,40 @@ public ChatPanel getContactChat(MetaContact metaContact, boolean create) } } + /** + * Gets the ChatPanel corresponding to the specified + * MetaContact and optionally creates it if it does not exist. + * + * @param metaContact the MetaContact to get the corresponding + * ChatPanel of + * @param create true to create a ChatPanel corresponding + * to the specified MetaContact if such ChatPanel does not + * exist yet + * @param escapedMessageID the message ID of the message that should be + * excluded from the history when the last one is loaded in the chat + * @return the ChatPanel corresponding to the specified + * MetaContact; null if there is no such + * ChatPanel and create is false + */ + public ChatPanel getContactChat(MetaContact metaContact, boolean create, + String escapedMessageID) + { + // if we are not creating a ui we don't need any execution + // in event dispatch thread, lets execute now + if(!create) + return getContactChat(metaContact, null, create, escapedMessageID); + else + { + // we may create using event dispatch thread + MetaContactChatCreateRunnable runnable + = new MetaContactChatCreateRunnable( + metaContact, + null, + escapedMessageID); + return runnable.getChatPanel(); + } + } + /** * Returns the chat panel corresponding to the given meta contact * @@ -386,7 +420,10 @@ public ChatPanel getContactChat(MetaContact metaContact, { // we may create using event dispatch thread MetaContactChatCreateRunnable runnable - = new MetaContactChatCreateRunnable(metaContact, null, null); + = new MetaContactChatCreateRunnable( + metaContact, + null, + escapedMessageID); return runnable.getChatPanel(); } @@ -1449,7 +1486,11 @@ private MetaContactChatCreateRunnable(MetaContact metaContact, */ protected ChatPanel createChatPanel() { - return getContactChat(metaContact, null, true, null); + return getContactChat( + metaContact, + null, + true, + this.escapedMessageID); } } diff --git a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java index 3a69df50e..fc4942ca6 100644 --- a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java +++ b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java @@ -146,7 +146,8 @@ public class NotificationManager public static void fireChatNotification(Object chatContact, String eventType, String messageTitle, - String message) + String message, + String messageUID) { NotificationService notificationService = NotificationWiringActivator.getNotificationService(); @@ -164,7 +165,7 @@ public static void fireChatNotification(Object chatContact, Contact contact = (Contact) chatContact; if(uiService != null) - chatPanel = uiService.getChat(contact); + chatPanel = uiService.getChat(contact, messageUID); contactIcon = contact.getImage(); if(contactIcon == null) @@ -737,7 +738,8 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event) sourceContact, INCOMING_FILE, title, - request.getFileName()); + request.getFileName(), + null); } catch(Throwable t) { @@ -1189,7 +1191,8 @@ public void messageReceived(AdHocChatRoomMessageReceivedEvent evt) sourceChatRoom, INCOMING_MESSAGE, title, - messageContent); + messageContent, + evt.getMessage().getMessageUID()); } } catch(Throwable t) @@ -1255,7 +1258,8 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt) sourceChatRoom, INCOMING_MESSAGE, title, - messageContent); + messageContent, + evt.getMessage().getMessageUID()); } } catch(Throwable t) @@ -1282,7 +1286,8 @@ public void messageReceived(MessageReceivedEvent evt) evt.getSourceContact(), INCOMING_MESSAGE, title, - evt.getSourceMessage().getContent()); + evt.getSourceMessage().getContent(), + evt.getSourceMessage().getMessageUID()); } catch(Throwable t) { @@ -1892,7 +1897,8 @@ public void typingNotificationReceived(TypingNotificationEvent ev) PROACTIVE_NOTIFICATION, contact.getDisplayName(), NotificationWiringActivator.getResources().getI18NString( - "service.gui.PROACTIVE_NOTIFICATION")); + "service.gui.PROACTIVE_NOTIFICATION"), + null); } catch(Throwable t) { diff --git a/src/net/java/sip/communicator/service/gui/UIService.java b/src/net/java/sip/communicator/service/gui/UIService.java index a2cbbe01e..35e9aa977 100644 --- a/src/net/java/sip/communicator/service/gui/UIService.java +++ b/src/net/java/sip/communicator/service/gui/UIService.java @@ -214,6 +214,16 @@ public ExportedWindow getExportedWindow(WindowID windowID, Object[] params) */ public Chat getChat(Contact contact); + /** + * Returns the Chat corresponding to the given Contact. + * + * @param contact the Contact for which the searched chat is about. + * @param escapedMessageID the message ID of the message that should be + * excluded from the history when the last one is loaded in the chat + * @return the Chat corresponding to the given Contact. + */ + public Chat getChat(Contact contact, String escapedMessageID); + /** * Returns the Chat corresponding to the given ChatRoom. *