From 6a21b7ef2431c365e52389238d446cd1c83f5853 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 12 Sep 2013 10:56:55 +0300 Subject: [PATCH] Fixes history button in chat window to work and with chat rooms. --- resources/languages/resources.properties | 6 +- .../chat/toolBars/HistorySelectorBox.java | 99 +++++++++++++++---- .../msghistory/MessageHistoryServiceImpl.java | 47 ++++++++- .../msghistory/MessageHistoryService.java | 9 ++ .../communicator/util/ConfigurationUtils.java | 16 +-- 5 files changed, 144 insertions(+), 33 deletions(-) diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index afe6b33a9..ca2fd007d 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -256,9 +256,11 @@ service.gui.HIDE_MAIN_WINDOW=
Clicking the X window button will not exit the but only
hide it. If you wish to exit the application choose File/Quit.
service.gui.HISTORY=&History service.gui.HISTORY_CONTACT=History - {0} -service.gui.HISTORY_TOGGLE_PER_CONTACT=Turn off history logging for this contact -service.gui.HISTORY_TOGGLE_ALL=Turn off history logging for all chats and contacts +service.gui.HISTORY_TOGGLE_PER_CONTACT=Turn off history for this contact +service.gui.HISTORY_TOGGLE_PER_CHATROOM=Turn off history for this chat room +service.gui.HISTORY_TOGGLE_ALL=Turn off history for all chats and contacts service.gui.HISTORY_ERASE_PER_CONTACT=Erase all history for this contact +service.gui.HISTORY_ERASE_PER_CHATROOM=Erase all history for this chat room service.gui.HISTORY_ERASE_ALL=Erase all chat history in {0} service.gui.HISTORY_REMOVE_PER_CONTACT_WARNING=Are you sure you want to permanently remove all locally stored messages for {0}? service.gui.HISTORY_REMOVE_ALL_WARNING=Are you sure you want to permanently remove all locally stored messages? diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java index 21a5786ab..56390e0e1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/HistorySelectorBox.java @@ -8,12 +8,14 @@ import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.main.chat.*; +import net.java.sip.communicator.impl.gui.main.chat.conference.*; import net.java.sip.communicator.impl.gui.main.chat.history.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.msghistory.*; +import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.skin.*; import org.jitsi.service.resources.*; @@ -60,6 +62,11 @@ public class HistorySelectorBox */ private JCheckBoxMenuItem toggleAllHistory; + /** + * The menu item to erase history for contact or chat room. + */ + private JMenuItem eraseHistoryPerContact; + /** * The chat container, where this tool bar is added. */ @@ -134,27 +141,40 @@ else if (menuItemName.equals("toggleHistoryPerContact")) { MetaContact currentContact = (MetaContact)desc; boolean isHistoryEnabled = - ConfigurationUtils.isHistoryLoggingEnabled(currentContact); + ConfigurationUtils.isHistoryLoggingEnabled( + currentContact.getMetaUID()); ConfigurationUtils.setHistoryLoggingEnabled( - !isHistoryEnabled, currentContact); + !isHistoryEnabled, currentContact.getMetaUID()); + } + else if(desc instanceof ChatRoomWrapper) + { + ChatRoom currentChatRoom = ((ChatRoomWrapper)desc).getChatRoom(); + boolean isHistoryEnabled = + ConfigurationUtils.isHistoryLoggingEnabled( + currentChatRoom.getIdentifier()); + ConfigurationUtils.setHistoryLoggingEnabled( + !isHistoryEnabled, currentChatRoom.getIdentifier()); } } else if (menuItemName.equals("eraseHistoryPerContact")) { Object desc = chatPanel.getChatSession().getDescriptor(); - if(!(desc instanceof MetaContact)) + String destination; + if(desc instanceof MetaContact) + destination = ((MetaContact)desc).getDisplayName(); + else if(desc instanceof ChatRoomWrapper) + destination = ((ChatRoomWrapper)desc).getChatRoomName(); + else return; - MetaContact contact = (MetaContact)desc; - MessageDialog dialog = new MessageDialog(null, GuiActivator.getResources().getI18NString( "service.gui.WARNING"), GuiActivator.getResources().getI18NString( "service.gui.HISTORY_REMOVE_PER_CONTACT_WARNING", - new String[]{contact.getDisplayName()}), + new String[]{destination}), GuiActivator.getResources().getI18NString("service.gui.OK"), false); @@ -162,15 +182,26 @@ else if (menuItemName.equals("eraseHistoryPerContact")) { try { - ServiceUtils.getService(GuiActivator.bundleContext, - MessageHistoryService.class).eraseLocallyStoredHistory( - contact); + if(desc instanceof MetaContact) + { + ServiceUtils.getService(GuiActivator.bundleContext, + MessageHistoryService.class) + .eraseLocallyStoredHistory( + (MetaContact)desc); + } + else if(desc instanceof ChatRoomWrapper) + { + ServiceUtils.getService(GuiActivator.bundleContext, + MessageHistoryService.class) + .eraseLocallyStoredHistory( + ((ChatRoomWrapper)desc).getChatRoom()); + } } catch(IOException ex) { logger.error("Error removing history", ex); - chatPanel.addErrorMessage(contact.getDisplayName(), + chatPanel.addErrorMessage(destination, GuiActivator.getResources().getI18NString( "service.gui.HISTORY_REMOVE_ERROR"), ex.getLocalizedMessage()); @@ -224,8 +255,7 @@ private void init() popupMenu.addSeparator(); - toggleHistoryPerContact = new JCheckBoxMenuItem( - R.getI18NString("service.gui.HISTORY_TOGGLE_PER_CONTACT")); + toggleHistoryPerContact = new JCheckBoxMenuItem(); toggleHistoryPerContact.setName("toggleHistoryPerContact"); toggleHistoryPerContact.addActionListener(this); popupMenu.add(toggleHistoryPerContact); @@ -238,8 +268,7 @@ private void init() popupMenu.addSeparator(); - JMenuItem eraseHistoryPerContact = new JMenuItem( - R.getI18NString("service.gui.HISTORY_ERASE_PER_CONTACT")); + eraseHistoryPerContact = new JMenuItem(); eraseHistoryPerContact.setName("eraseHistoryPerContact"); eraseHistoryPerContact.addActionListener(this); popupMenu.add(eraseHistoryPerContact); @@ -268,7 +297,7 @@ public void propertyChange(PropertyChangeEvent evt) if(evt.getPropertyName().equals( MessageHistoryService.PNAME_IS_MESSAGE_HISTORY_ENABLED)) { - changeHistoryIcon(); + updateMenus(); } else if(evt.getPropertyName().startsWith(MessageHistoryService .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX)) @@ -280,7 +309,13 @@ else if(evt.getPropertyName().startsWith(MessageHistoryService MetaContact contact = (MetaContact)desc; if(evt.getPropertyName().endsWith(contact.getMetaUID())) - changeHistoryIcon(); + updateMenus(); + } + else if(desc instanceof ChatRoomWrapper) + { + if(evt.getPropertyName().endsWith( + ((ChatRoomWrapper)desc).getChatRoom().getIdentifier())) + updateMenus(); } } } @@ -290,13 +325,16 @@ else if(evt.getPropertyName().startsWith(MessageHistoryService */ public void loadSkin() { - changeHistoryIcon(); + updateMenus(); } /** * Changes currently used icon on or off, depending on the current settings. + * Updates selected menu items, depends on current configuration. + * Updates the text depending on the current chat session, is it chat room + * or a metacontact. */ - private void changeHistoryIcon() + private void updateMenus() { toggleAllHistory.setSelected(false); toggleHistoryPerContact.setSelected(false); @@ -306,16 +344,37 @@ private void changeHistoryIcon() if(chatContainer.getCurrentChat() != null) { + ResourceManagementService R = GuiActivator.getResources(); + Object desc = chatContainer.getCurrentChat() .getChatSession().getDescriptor(); if(desc instanceof MetaContact) { MetaContact contact = (MetaContact)desc; - if(!ConfigurationUtils.isHistoryLoggingEnabled(contact)) + if(!ConfigurationUtils.isHistoryLoggingEnabled( + contact.getMetaUID())) + { + toggleHistoryPerContact.setSelected(true); + } + + toggleHistoryPerContact.setText( + R.getI18NString("service.gui.HISTORY_TOGGLE_PER_CONTACT")); + eraseHistoryPerContact.setText( + R.getI18NString("service.gui.HISTORY_ERASE_PER_CONTACT")); + } + else if(desc instanceof ChatRoomWrapper) + { + if(!ConfigurationUtils.isHistoryLoggingEnabled( + ((ChatRoomWrapper)desc).getChatRoom().getIdentifier())) { toggleHistoryPerContact.setSelected(true); } + + toggleHistoryPerContact.setText( + R.getI18NString("service.gui.HISTORY_TOGGLE_PER_CHATROOM")); + eraseHistoryPerContact.setText( + R.getI18NString("service.gui.HISTORY_ERASE_PER_CHATROOM")); } } @@ -348,7 +407,7 @@ public void dispose() @Override public void chatChanged(ChatPanel panel) { - changeHistoryIcon(); + updateMenus(); panel.addChatLinkClickedListener(this); } diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java index aa104714f..dd74fa4bb 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java @@ -859,6 +859,13 @@ public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) public void messageReceived(ChatRoomMessageReceivedEvent evt) { + if(!ConfigurationUtils.isHistoryLoggingEnabled( + evt.getSourceChatRoom().getIdentifier())) + { + // logging is switched off for this particular chat room + return; + } + try { // ignore non conversation messages @@ -918,8 +925,14 @@ public void messageDelivered(ChatRoomMessageDeliveredEvent evt) { try { - History history = this. - getHistoryForMultiChat( + if(!ConfigurationUtils.isHistoryLoggingEnabled( + evt.getSourceChatRoom().getIdentifier())) + { + // logging is switched off for this particular chat room + return; + } + + History history = this.getHistoryForMultiChat( evt.getSourceChatRoom()); // if this is chat room message history on every room enter @@ -983,7 +996,8 @@ private void writeMessage(String direction, Contact source, MetaContact metaContact = MessageHistoryActivator .getContactListService().findMetaContactByContact(destination); if(metaContact != null - && !ConfigurationUtils.isHistoryLoggingEnabled(metaContact)) + && !ConfigurationUtils.isHistoryLoggingEnabled( + metaContact.getMetaUID())) { // logging is switched off for this particular contact return; @@ -2292,6 +2306,13 @@ private void stopMessageHistoryService() public void messageDelivered(AdHocChatRoomMessageDeliveredEvent evt) { + if(!ConfigurationUtils.isHistoryLoggingEnabled( + evt.getSourceAdHocChatRoom().getIdentifier())) + { + // logging is switched off for this particular chat room + return; + } + try { History history = this. @@ -2314,6 +2335,13 @@ public void messageDeliveryFailed( public void messageReceived(AdHocChatRoomMessageReceivedEvent evt) { + if(!ConfigurationUtils.isHistoryLoggingEnabled( + evt.getSourceChatRoom().getIdentifier())) + { + // logging is switched off for this particular chat room + return; + } + try { History history = this.getHistoryForAdHocMultiChat( @@ -2381,4 +2409,17 @@ public void eraseLocallyStoredHistory(MetaContact contact) historyService.purgeLocallyStoredHistory(history.getID()); } } + + /** + * Permanently removes locally stored message history for the chatroom. + * + * @throws java.io.IOException + * Thrown if the history could not be removed due to a IO error. + */ + public void eraseLocallyStoredHistory(ChatRoom room) + throws IOException + { + History history = this.getHistoryForMultiChat(room); + historyService.purgeLocallyStoredHistory(history.getID()); + } } diff --git a/src/net/java/sip/communicator/service/msghistory/MessageHistoryService.java b/src/net/java/sip/communicator/service/msghistory/MessageHistoryService.java index f52e38bd4..5ff2a716d 100644 --- a/src/net/java/sip/communicator/service/msghistory/MessageHistoryService.java +++ b/src/net/java/sip/communicator/service/msghistory/MessageHistoryService.java @@ -385,4 +385,13 @@ public void eraseLocallyStoredHistory() */ public void eraseLocallyStoredHistory(MetaContact contact) throws IOException; + + /** + * Permanently removes locally stored message history for the chatroom. + * + * @throws java.io.IOException + * Thrown if the history could not be removed due to a IO error. + */ + public void eraseLocallyStoredHistory(ChatRoom room) + throws IOException; } diff --git a/src/net/java/sip/communicator/util/ConfigurationUtils.java b/src/net/java/sip/communicator/util/ConfigurationUtils.java index 9205c781a..d6d735a5e 100644 --- a/src/net/java/sip/communicator/util/ConfigurationUtils.java +++ b/src/net/java/sip/communicator/util/ConfigurationUtils.java @@ -1106,19 +1106,19 @@ public static void setHistoryLoggingEnabled(boolean isEnabled) /** * Returns true if the "IS_MESSAGE_HISTORY_ENABLED" - * property is true for the contact, otherwise - returns + * property is true for the id, otherwise - returns * false. * Indicates to the user interface whether the history logging is enabled - * for the supplied MetaContact. + * for the supplied id (id for metacontact or for chat room). * @return true if the "IS_MESSAGE_HISTORY_ENABLED" - * property is true for the contact, otherwise - returns + * property is true for the id, otherwise - returns * false. */ - public static boolean isHistoryLoggingEnabled(MetaContact contact) + public static boolean isHistoryLoggingEnabled(String id) { return configService.getBoolean(MessageHistoryService .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX - + "." + contact.getMetaUID(), true); + + "." + id, true); } /** @@ -1129,18 +1129,18 @@ public static boolean isHistoryLoggingEnabled(MetaContact contact) * enabled for the contact. */ public static void setHistoryLoggingEnabled( - boolean isEnabled, MetaContact contact) + boolean isEnabled, String id) { if(isEnabled) configService.setProperty( MessageHistoryService .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX - + "." + contact.getMetaUID(), null); + + "." + id, null); else configService.setProperty( MessageHistoryService .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX - + "." + contact.getMetaUID(), isEnabled); + + "." + id, isEnabled); }