Adds more code that generates HTML descriptions of mail nofitications.

cusax-fix
Emil Ivov 17 years ago
parent a75e981299
commit d64dabd663

@ -691,63 +691,6 @@ private void subscribeForGmailNotifications()
jabberProvider.getConnection().sendPacket(mailnotification);
}
/**
* Creates an html description of all participant names in the thread.
* We try to do this in a GMail-like (although quite simplified) way:<br/>
* We print the whole name for a sole participant. <br/>
* We print only the first names for more than one participant. <br/>
* We print up to three names max. <br/>
* We show in bold people that we have unread messages for <br/>.
*
* @param thread the thread that we are to describe.
*
* @return an html description of <tt>thread</tt>
*/
private String createParticipantNames(MailThreadInfo thread)
{
StringBuffer participantNames = new StringBuffer();
//if we have more than one sender we only show first names
boolean firstNamesOnly = thread.getSenderCount() > 1;
int unreadSenderCount = thread.getUnreadSenderCount();
int maximumSndrsAllowed = 3;
int maximumUnreadAllowed = Math.min(
maximumSndrsAllowed, unreadSenderCount);
int maximumReadAllowed = maximumSndrsAllowed - maximumUnreadAllowed;
//we now iterate over all senders and include as many unread and read
//participants as possible.
Iterator<MailThreadInfo.Sender> senders = thread.senders();
while(senders.hasNext())
{
MailThreadInfo.Sender sender = senders.next();
}
return participantNames.toString();
}
/**
* Creates an html description of the specified thread.
*
* @param thread the thread that we are to describe.
*
* @return an html description of <tt>thread</tt>
*/
private String createMailThreadDescription(MailThreadInfo thread)
{
StringBuffer threadBuff = new StringBuffer();
//first get the names of the participants
threadBuff.append(createParticipantNames(thread));
return threadBuff.toString();
}
/**
* Creates an html description of the specified mailbox.
*
@ -772,7 +715,7 @@ private String createMailboxDescription(MailboxIQ mailboxIQ)
while(threads.hasNext())
{
message.append(createMailThreadDescription(threads.next()));
message.append(threads.next().createHtmlDescription());
}
return newMailHeader;

@ -140,6 +140,27 @@ public class Sender
* this sender.
*/
public boolean unread = false;
/**
* Tries to parse and return the first name of this sender.
*
* @return the first name of this sender.
*/
public String getFirstName()
{
if(name == null || name.trim().length() == 0)
return "";
String[] names = name.split("\\s");
String result = names[0];
//return 14 chars max
if(result.length() > 15)
result = result.substring(0, 14);
return result;
}
}
/**
@ -533,6 +554,132 @@ private void parseSenders(XmlPullParser parser)
eventType = parser.next();
}
}
/**
* Creates an html description of all participant names in the thread.
* We try to do this in a GMail-like (although quite simplified) way:<br/>
* We print the whole name for a sole participant. <br/>
* We print only the first names for more than one participant. <br/>
* We print up to three names max. <br/>
* We show in bold people that we have unread messages for <br/>.
*
* @return an html description of <tt>thread</tt>
*/
private String createParticipantNames()
{
StringBuffer participantNames = new StringBuffer();
//if we have more than one sender we only show first names
boolean firstNamesOnly = getSenderCount() > 1;
int unreadSenderCount = getUnreadSenderCount();
int maximumSndrsAllowed = 3;
int remainingSndrsAllowed = maximumSndrsAllowed;
int maximumUnreadAllowed = Math.min(
remainingSndrsAllowed, unreadSenderCount);
int maximumReadAllowed = remainingSndrsAllowed - maximumUnreadAllowed;
//we now iterate over all senders and include as many unread and read
//participants as possible.
Iterator<MailThreadInfo.Sender> senders = senders();
while(senders.hasNext())
{
if(remainingSndrsAllowed == 0 )
break;
MailThreadInfo.Sender sender = senders.next();
String name = firstNamesOnly? sender.getFirstName() : sender.name;
if (!sender.unread && maximumReadAllowed == 0)
continue;
if(remainingSndrsAllowed < maximumSndrsAllowed)
{
//this is not the first name we add so add a coma
participantNames.append(", ");
}
remainingSndrsAllowed--;
if(sender.unread)
{
participantNames.append("<b>").append(name).append("</b>");
maximumUnreadAllowed --;
}
else
{
participantNames.append(name);
maximumReadAllowed--;
}
}
//if we don't show all the senders, then show total number of messages
participantNames.append(" (").append(getMessageCount()).append(")");
return participantNames.toString();
}
/**
* Creates an html description of the specified thread.
*
* @param thread the thread that we are to describe.
*
* @return an html description of <tt>thread</tt>
*/
public String createHtmlDescription()
{
StringBuffer threadBuff = new StringBuffer();
//first get the names of the participants
threadBuff.append(createParticipantNames());
//start a new cell
threadBuff.append("<td>");
//now get the labels
threadBuff.append(createLabelList());
//add the subject
threadBuff.append("<b>").append(getSubject()).append("</b>");
//add mail snippet
threadBuff.append("<font color=#7777CC> - ");
threadBuff.append(getSnippet()).append("</font>");
//and we're done
return threadBuff.toString();
}
/**
* Creates a formatted list of labels.
*
* @return a <tt>String</tt> containing a formatted list of labels.
*/
private String createLabelList()
{
String[] labelsArray = labels.split("|");
StringBuffer labelsList = new StringBuffer();
//get rid of the system labels that start with "^"
for (int i = 0; i < labelsArray.length; i++)
{
String label = labelsArray[i];
if(label.startsWith("^"))
continue;
labelsList.append("<font color=#006633>");
labelsList.append(label);
labelsList.append("</font>");
if(i < labelsArray.length -1)
labelsList.append(", ");
}
return labelsList.toString();
}
}

Loading…
Cancel
Save