Updates recent messages, fixes sometimes disappearing messages.

fix-message-formatting
Damian Minkov 11 years ago
parent ab08cd7a00
commit 721f22def0

@ -89,11 +89,11 @@ private void initItems()
.getPreferredContactDetail(OperationSetBasicTelephony.class);
// Call menu.
if (cDetail != null
&& sourceContact.getContactSource().getType()
!= ContactSourceService.RECENT_MESSAGES_TYPE)
if (cDetail != null)
{
add(initCallMenu());
Component c = initCallMenu();
if(c != null)
add(c);
}
// Only create the menu if the add contact functionality is enabled.
@ -181,6 +181,10 @@ else if (providersCount > 1)
contains(OperationSetBasicTelephony.class));
callContactMenu.add(callContactItem);
}
if(callContactMenu.getMenuComponentCount() == 0)
return null;
return callContactMenu;
}

@ -1139,6 +1139,8 @@ private void loadRecentMessages()
messageSourceServiceReg = bundleContext.registerService(
ContactSourceService.class.getName(),
messageSourceService, null);
MessageHistoryActivator.getContactListService()
.addMetaContactListListener(this.messageSourceService);
}
/**
@ -1148,6 +1150,9 @@ private void stopRecentMessages()
{
if(messageSourceServiceReg != null)
{
MessageHistoryActivator.getContactListService()
.removeMetaContactListListener(this.messageSourceService);
messageSourceServiceReg.unregister();
messageSourceServiceReg = null;

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.msghistory;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.muc.*;
@ -175,7 +176,7 @@ void update(EventObject source)
this.contact = e.getDestinationContact();
this.address = contact.getAddress();
this.displayName = contact.getDisplayName();
this.updateDisplayName();
this.ppService = contact.getProtocolProvider();
this.image = contact.getImage();
this.status = contact.getPresenceStatus();
@ -189,7 +190,7 @@ else if(source instanceof MessageReceivedEvent)
this.contact = e.getSourceContact();
this.address = contact.getAddress();
this.displayName = contact.getDisplayName();
this.updateDisplayName();
this.ppService = contact.getProtocolProvider();
this.image = contact.getImage();
this.status = contact.getPresenceStatus();
@ -279,6 +280,9 @@ else if(source instanceof ChatRoomMessageDeliveredEvent
*/
void initDetails(boolean isChatRoom, Contact contact)
{
if(!isChatRoom && contact != null)
this.updateDisplayName();
ContactDetail contactDetail =
new ContactDetail(
this.address,
@ -334,6 +338,7 @@ void initDetails(boolean isChatRoom, Contact contact)
contactDetail.setSupportedOpSets(supportedOpSets);
}
contactDetails.clear();
contactDetails.add(contactDetail);
}
@ -506,6 +511,24 @@ public void setDisplayName(String displayName)
this.displayName = displayName;
}
/**
* Updates display name if contact is not null.
*/
private void updateDisplayName()
{
if(this.contact == null)
return;
MetaContact metaContact
= MessageHistoryActivator.getContactListService()
.findMetaContactByContact(contact);
if(metaContact == null)
return;
this.displayName = metaContact.getDisplayName();
}
/**
* Compares two MessageSourceContacts.
* @param o the object to compare with

@ -0,0 +1,241 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.msghistory;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
import java.util.regex.*;
/**
* The query which creates source contacts and uses the values stored in
* <tt>MessageSourceService</tt>.
*
* @author Damian Minkov
*/
public class MessageSourceContactQuery
extends AsyncContactQuery<MessageSourceService>
{
/**
* Constructs.
*
* @param messageSourceService
*/
MessageSourceContactQuery(MessageSourceService messageSourceService)
{
super(messageSourceService,
Pattern.compile("",
Pattern.CASE_INSENSITIVE | Pattern.LITERAL),
false);
}
/**
* Creates <tt>MessageSourceContact</tt> for all currently cached
* recent messages in the <tt>MessageSourceService</tt>.
*/
@Override
public void run()
{
getContactSource().updateRecentMessages();
}
/**
* Updates capabilities from <tt>EventObject</tt> for the found
* <tt>MessageSourceContact</tt> equals to the <tt>Object</tt> supplied.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
* @param srcObj used to search for <tt>MessageSourceContact</tt>
* @param eventObj the values used for the update
*/
public void updateCapabilities(Object srcObj, EventObject eventObj)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
((MessageSourceContact)msc).initDetails(eventObj);
break;
}
}
}
/**
* Updates capabilities from <tt>Contact</tt> for the found
* <tt>MessageSourceContact</tt> equals to the <tt>Object</tt> supplied.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
* @param srcObj used to search for <tt>MessageSourceContact</tt>
* @param contact the values used for the update
*/
public void updateCapabilities(Object srcObj, Contact contact)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
((MessageSourceContact)msc).initDetails(false, contact);
break;
}
}
}
/**
* Notifies the <tt>ContactQueryListener</tt>s registered with this
* <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
* changed.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
*
* @param srcObj the <tt>Object</tt> representing a recent message
* which has been changed and corresponding <tt>SourceContact</tt>
* which the registered <tt>ContactQueryListener</tt>s are to be
* notified about
*/
public void updateContact(Object srcObj, EventObject eventObject)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
((MessageSourceContact)msc).update(eventObject);
super.fireContactChanged(msc);
break;
}
}
}
/**
* Notifies the <tt>ContactQueryListener</tt>s registered with this
* <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
* changed.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
*
* @param srcObj the <tt>Object</tt> representing a recent message
* which has been changed and corresponding <tt>SourceContact</tt>
* which the registered <tt>ContactQueryListener</tt>s are to be
* notified about
*/
public void fireContactChanged(Object srcObj)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
super.fireContactChanged(msc);
break;
}
}
}
/**
* Notifies the <tt>ContactQueryListener</tt>s registered with this
* <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
* changed.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
*
* @param srcObj the <tt>Object</tt> representing a recent message
* which has been changed and corresponding <tt>SourceContact</tt>
* which the registered <tt>ContactQueryListener</tt>s are to be
* notified about
*/
public void updateContactStatus(Object srcObj,
PresenceStatus status)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
((MessageSourceContact)msc).setStatus(status);
super.fireContactChanged(msc);
break;
}
}
}
/**
* Notifies the <tt>ContactQueryListener</tt>s registered with this
* <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
* changed.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
*
* @param srcObj the <tt>Object</tt> representing a recent message
* which has been changed and corresponding <tt>SourceContact</tt>
* which the registered <tt>ContactQueryListener</tt>s are to be
* notified about
*/
public void updateContactDisplayName(Object srcObj,
String newName)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc)
&& msc instanceof MessageSourceContact)
{
((MessageSourceContact)msc).setDisplayName(newName);
super.fireContactChanged(msc);
break;
}
}
}
/**
* Notifies the <tt>ContactQueryListener</tt>s registered with this
* <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
* removed.
* Note that Object may not be <tt>MessageSourceContact</tt>, but its
* equals method can return true for message source contact instances.
*
* @param srcObj representing the message and its corresponding
* <tt>SourceContact</tt> which has been removed and which the registered
* <tt>ContactQueryListener</tt>s are to be notified about
*/
public void fireContactRemoved(Object srcObj)
{
for(SourceContact msc : getQueryResults())
{
if(srcObj.equals(msc))
{
super.fireContactRemoved(msc);
break;
}
}
}
/**
* Adds a specific <tt>SourceContact</tt> to the list of
* <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
* response to {@link #getQueryResults()}.
*
* @param sourceContact the <tt>SourceContact</tt> to be added to the
* <tt>queryResults</tt> of this <tt>ContactQuery</tt>
* @return <tt>true</tt> if the <tt>queryResults</tt> of this
* <tt>ContactQuery</tt> has changed in response to the call
*/
public boolean addQueryResult(SourceContact sourceContact)
{
return super.addQueryResult(sourceContact, false);
}
}

@ -12,6 +12,7 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.history.event,
net.java.sip.communicator.service.msghistory,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.contactlist.event,
net.java.sip.communicator.service.contactsource,
net.java.sip.communicator.service.history.records,
net.java.sip.communicator.service.muc,

Loading…
Cancel
Save