Fixes history button in chat window to work and with chat rooms.

cusax-fix
Damian Minkov 12 years ago
parent 180310ee9a
commit 6a21b7ef24

@ -256,9 +256,11 @@ service.gui.HIDE_MAIN_WINDOW=<DIV>Clicking the X window button will not exit the
but only <BR> hide it. If you wish to exit the application choose File/Quit.</DIV> but only <BR> hide it. If you wish to exit the application choose File/Quit.</DIV>
service.gui.HISTORY=&History service.gui.HISTORY=&History
service.gui.HISTORY_CONTACT=History - {0} service.gui.HISTORY_CONTACT=History - {0}
service.gui.HISTORY_TOGGLE_PER_CONTACT=Turn off history logging for this contact service.gui.HISTORY_TOGGLE_PER_CONTACT=Turn off history for this contact
service.gui.HISTORY_TOGGLE_ALL=Turn off history logging for all chats and contacts 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_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_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_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? service.gui.HISTORY_REMOVE_ALL_WARNING=Are you sure you want to permanently remove all locally stored messages?

@ -8,12 +8,14 @@
import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*; 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.*;
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.main.chat.history.*;
import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.msghistory.*; 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.*;
import net.java.sip.communicator.util.skin.*; import net.java.sip.communicator.util.skin.*;
import org.jitsi.service.resources.*; import org.jitsi.service.resources.*;
@ -60,6 +62,11 @@ public class HistorySelectorBox
*/ */
private JCheckBoxMenuItem toggleAllHistory; 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. * The chat container, where this tool bar is added.
*/ */
@ -134,27 +141,40 @@ else if (menuItemName.equals("toggleHistoryPerContact"))
{ {
MetaContact currentContact = (MetaContact)desc; MetaContact currentContact = (MetaContact)desc;
boolean isHistoryEnabled = boolean isHistoryEnabled =
ConfigurationUtils.isHistoryLoggingEnabled(currentContact); ConfigurationUtils.isHistoryLoggingEnabled(
currentContact.getMetaUID());
ConfigurationUtils.setHistoryLoggingEnabled( 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")) else if (menuItemName.equals("eraseHistoryPerContact"))
{ {
Object desc = chatPanel.getChatSession().getDescriptor(); 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; return;
MetaContact contact = (MetaContact)desc;
MessageDialog dialog = MessageDialog dialog =
new MessageDialog(null, new MessageDialog(null,
GuiActivator.getResources().getI18NString( GuiActivator.getResources().getI18NString(
"service.gui.WARNING"), "service.gui.WARNING"),
GuiActivator.getResources().getI18NString( GuiActivator.getResources().getI18NString(
"service.gui.HISTORY_REMOVE_PER_CONTACT_WARNING", "service.gui.HISTORY_REMOVE_PER_CONTACT_WARNING",
new String[]{contact.getDisplayName()}), new String[]{destination}),
GuiActivator.getResources().getI18NString("service.gui.OK"), GuiActivator.getResources().getI18NString("service.gui.OK"),
false); false);
@ -162,15 +182,26 @@ else if (menuItemName.equals("eraseHistoryPerContact"))
{ {
try try
{ {
ServiceUtils.getService(GuiActivator.bundleContext, if(desc instanceof MetaContact)
MessageHistoryService.class).eraseLocallyStoredHistory( {
contact); 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) catch(IOException ex)
{ {
logger.error("Error removing history", ex); logger.error("Error removing history", ex);
chatPanel.addErrorMessage(contact.getDisplayName(), chatPanel.addErrorMessage(destination,
GuiActivator.getResources().getI18NString( GuiActivator.getResources().getI18NString(
"service.gui.HISTORY_REMOVE_ERROR"), "service.gui.HISTORY_REMOVE_ERROR"),
ex.getLocalizedMessage()); ex.getLocalizedMessage());
@ -224,8 +255,7 @@ private void init()
popupMenu.addSeparator(); popupMenu.addSeparator();
toggleHistoryPerContact = new JCheckBoxMenuItem( toggleHistoryPerContact = new JCheckBoxMenuItem();
R.getI18NString("service.gui.HISTORY_TOGGLE_PER_CONTACT"));
toggleHistoryPerContact.setName("toggleHistoryPerContact"); toggleHistoryPerContact.setName("toggleHistoryPerContact");
toggleHistoryPerContact.addActionListener(this); toggleHistoryPerContact.addActionListener(this);
popupMenu.add(toggleHistoryPerContact); popupMenu.add(toggleHistoryPerContact);
@ -238,8 +268,7 @@ private void init()
popupMenu.addSeparator(); popupMenu.addSeparator();
JMenuItem eraseHistoryPerContact = new JMenuItem( eraseHistoryPerContact = new JMenuItem();
R.getI18NString("service.gui.HISTORY_ERASE_PER_CONTACT"));
eraseHistoryPerContact.setName("eraseHistoryPerContact"); eraseHistoryPerContact.setName("eraseHistoryPerContact");
eraseHistoryPerContact.addActionListener(this); eraseHistoryPerContact.addActionListener(this);
popupMenu.add(eraseHistoryPerContact); popupMenu.add(eraseHistoryPerContact);
@ -268,7 +297,7 @@ public void propertyChange(PropertyChangeEvent evt)
if(evt.getPropertyName().equals( if(evt.getPropertyName().equals(
MessageHistoryService.PNAME_IS_MESSAGE_HISTORY_ENABLED)) MessageHistoryService.PNAME_IS_MESSAGE_HISTORY_ENABLED))
{ {
changeHistoryIcon(); updateMenus();
} }
else if(evt.getPropertyName().startsWith(MessageHistoryService else if(evt.getPropertyName().startsWith(MessageHistoryService
.PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX)) .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX))
@ -280,7 +309,13 @@ else if(evt.getPropertyName().startsWith(MessageHistoryService
MetaContact contact = (MetaContact)desc; MetaContact contact = (MetaContact)desc;
if(evt.getPropertyName().endsWith(contact.getMetaUID())) 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() public void loadSkin()
{ {
changeHistoryIcon(); updateMenus();
} }
/** /**
* Changes currently used icon on or off, depending on the current settings. * 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); toggleAllHistory.setSelected(false);
toggleHistoryPerContact.setSelected(false); toggleHistoryPerContact.setSelected(false);
@ -306,16 +344,37 @@ private void changeHistoryIcon()
if(chatContainer.getCurrentChat() != null) if(chatContainer.getCurrentChat() != null)
{ {
ResourceManagementService R = GuiActivator.getResources();
Object desc = chatContainer.getCurrentChat() Object desc = chatContainer.getCurrentChat()
.getChatSession().getDescriptor(); .getChatSession().getDescriptor();
if(desc instanceof MetaContact) if(desc instanceof MetaContact)
{ {
MetaContact contact = (MetaContact)desc; 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.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 @Override
public void chatChanged(ChatPanel panel) public void chatChanged(ChatPanel panel)
{ {
changeHistoryIcon(); updateMenus();
panel.addChatLinkClickedListener(this); panel.addChatLinkClickedListener(this);
} }

@ -859,6 +859,13 @@ public void messageDeliveryFailed(MessageDeliveryFailedEvent evt)
public void messageReceived(ChatRoomMessageReceivedEvent evt) public void messageReceived(ChatRoomMessageReceivedEvent evt)
{ {
if(!ConfigurationUtils.isHistoryLoggingEnabled(
evt.getSourceChatRoom().getIdentifier()))
{
// logging is switched off for this particular chat room
return;
}
try try
{ {
// ignore non conversation messages // ignore non conversation messages
@ -918,8 +925,14 @@ public void messageDelivered(ChatRoomMessageDeliveredEvent evt)
{ {
try try
{ {
History history = this. if(!ConfigurationUtils.isHistoryLoggingEnabled(
getHistoryForMultiChat( evt.getSourceChatRoom().getIdentifier()))
{
// logging is switched off for this particular chat room
return;
}
History history = this.getHistoryForMultiChat(
evt.getSourceChatRoom()); evt.getSourceChatRoom());
// if this is chat room message history on every room enter // 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 MetaContact metaContact = MessageHistoryActivator
.getContactListService().findMetaContactByContact(destination); .getContactListService().findMetaContactByContact(destination);
if(metaContact != null if(metaContact != null
&& !ConfigurationUtils.isHistoryLoggingEnabled(metaContact)) && !ConfigurationUtils.isHistoryLoggingEnabled(
metaContact.getMetaUID()))
{ {
// logging is switched off for this particular contact // logging is switched off for this particular contact
return; return;
@ -2292,6 +2306,13 @@ private void stopMessageHistoryService()
public void messageDelivered(AdHocChatRoomMessageDeliveredEvent evt) public void messageDelivered(AdHocChatRoomMessageDeliveredEvent evt)
{ {
if(!ConfigurationUtils.isHistoryLoggingEnabled(
evt.getSourceAdHocChatRoom().getIdentifier()))
{
// logging is switched off for this particular chat room
return;
}
try try
{ {
History history = this. History history = this.
@ -2314,6 +2335,13 @@ public void messageDeliveryFailed(
public void messageReceived(AdHocChatRoomMessageReceivedEvent evt) public void messageReceived(AdHocChatRoomMessageReceivedEvent evt)
{ {
if(!ConfigurationUtils.isHistoryLoggingEnabled(
evt.getSourceChatRoom().getIdentifier()))
{
// logging is switched off for this particular chat room
return;
}
try try
{ {
History history = this.getHistoryForAdHocMultiChat( History history = this.getHistoryForAdHocMultiChat(
@ -2381,4 +2409,17 @@ public void eraseLocallyStoredHistory(MetaContact contact)
historyService.purgeLocallyStoredHistory(history.getID()); 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());
}
} }

@ -385,4 +385,13 @@ public void eraseLocallyStoredHistory()
*/ */
public void eraseLocallyStoredHistory(MetaContact contact) public void eraseLocallyStoredHistory(MetaContact contact)
throws IOException; 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;
} }

@ -1106,19 +1106,19 @@ public static void setHistoryLoggingEnabled(boolean isEnabled)
/** /**
* Returns <code>true</code> if the "IS_MESSAGE_HISTORY_ENABLED" * Returns <code>true</code> if the "IS_MESSAGE_HISTORY_ENABLED"
* property is true for the <tt>contact</tt>, otherwise - returns * property is true for the <tt>id</tt>, otherwise - returns
* <code>false</code>. * <code>false</code>.
* Indicates to the user interface whether the history logging is enabled * 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 <code>true</code> if the "IS_MESSAGE_HISTORY_ENABLED" * @return <code>true</code> if the "IS_MESSAGE_HISTORY_ENABLED"
* property is true for the <tt>contact</tt>, otherwise - returns * property is true for the <tt>id</tt>, otherwise - returns
* <code>false</code>. * <code>false</code>.
*/ */
public static boolean isHistoryLoggingEnabled(MetaContact contact) public static boolean isHistoryLoggingEnabled(String id)
{ {
return configService.getBoolean(MessageHistoryService return configService.getBoolean(MessageHistoryService
.PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX .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. * enabled for the contact.
*/ */
public static void setHistoryLoggingEnabled( public static void setHistoryLoggingEnabled(
boolean isEnabled, MetaContact contact) boolean isEnabled, String id)
{ {
if(isEnabled) if(isEnabled)
configService.setProperty( configService.setProperty(
MessageHistoryService MessageHistoryService
.PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX
+ "." + contact.getMetaUID(), null); + "." + id, null);
else else
configService.setProperty( configService.setProperty(
MessageHistoryService MessageHistoryService
.PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX .PNAME_IS_MESSAGE_HISTORY_PER_CONTACT_ENABLED_PREFIX
+ "." + contact.getMetaUID(), isEnabled); + "." + id, isEnabled);
} }

Loading…
Cancel
Save