From 29c0cf0340d6335fc48b45808bb87dde33b344a8 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Fri, 6 Jun 2014 13:14:22 +0300 Subject: [PATCH] Updates recent chats when erasing chat history. --- .../msghistory/MessageHistoryServiceImpl.java | 9 ++ .../impl/msghistory/MessageSourceService.java | 95 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java index bd9d18134..c6ed3cc6b 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java @@ -2956,6 +2956,9 @@ public void eraseLocallyStoredHistory() HistoryID historyId = HistoryID.createFromRawID( new String[] { "messages" }); historyService.purgeLocallyStoredHistory(historyId); + + if(this.messageSourceService != null) + this.messageSourceService.eraseLocallyStoredHistory(); } /** @@ -2975,6 +2978,9 @@ public void eraseLocallyStoredHistory(MetaContact contact) History history = this.getHistory(null, item); historyService.purgeLocallyStoredHistory(history.getID()); } + + if(this.messageSourceService != null) + this.messageSourceService.eraseLocallyStoredHistory(contact); } /** @@ -2988,6 +2994,9 @@ public void eraseLocallyStoredHistory(ChatRoom room) { History history = this.getHistoryForMultiChat(room); historyService.purgeLocallyStoredHistory(history.getID()); + + if(this.messageSourceService != null) + this.messageSourceService.eraseLocallyStoredHistory(room); } /** diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageSourceService.java b/src/net/java/sip/communicator/impl/msghistory/MessageSourceService.java index cef4618e4..8e0cb70e9 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageSourceService.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageSourceService.java @@ -12,6 +12,7 @@ import java.util.*; import java.util.regex.*; +import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactsource.*; import net.java.sip.communicator.service.history.*; import net.java.sip.communicator.service.history.records.*; @@ -1211,6 +1212,100 @@ public void supportedOperationSetsChanged(ContactCapabilitiesEvent event) } } + /** + * Permanently removes all locally stored message history, + * remove recent contacts. + */ + public void eraseLocallyStoredHistory() + throws IOException + { + synchronized(recentMessages) + { + List toRemove + = new ArrayList(recentMessages); + + recentMessages.clear(); + + if(recentQuery != null) + { + for(MessageSourceContact msc : toRemove) + { + recentQuery.fireContactRemoved(msc); + } + } + } + } + + /** + * Permanently removes locally stored message history for the metacontact, + * remove any recent contacts if any. + */ + public void eraseLocallyStoredHistory(MetaContact contact) + throws IOException + { + synchronized(recentMessages) + { + List toRemove + = new ArrayList(); + Iterator iter = contact.getContacts(); + while(iter.hasNext()) + { + Contact item = iter.next(); + String id = item.getAddress(); + ProtocolProviderService provider = item.getProtocolProvider(); + + for(MessageSourceContact msc : recentMessages) + { + if(msc.getProtocolProviderService().equals(provider) + && msc.getContactAddress().equals(id)) + { + toRemove.add(msc); + } + } + } + + recentMessages.removeAll(toRemove); + + if(recentQuery != null) + { + for(MessageSourceContact msc : toRemove) + { + recentQuery.fireContactRemoved(msc); + } + } + } + + } + + /** + * Permanently removes locally stored message history for the chatroom, + * remove any recent contacts if any. + */ + public void eraseLocallyStoredHistory(ChatRoom room) + { + synchronized(recentMessages) + { + MessageSourceContact toRemove = null; + for(MessageSourceContact msg : recentMessages) + { + if(msg.getRoom() != null + && msg.getRoom().equals(room)) + { + toRemove = msg; + break; + } + } + + if(toRemove == null) + return; + + recentMessages.remove(toRemove); + + if(recentQuery != null) + recentQuery.fireContactRemoved(toRemove); + } + } + /** * The contact query implementation. */